mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-29 11:00:29 +00:00
78155a6668
Now, exceptions can be thrown with interpreter.throw_exception<T>(ErrorType:TYPE, "format", "args", "here").
55 lines
1.3 KiB
JavaScript
55 lines
1.3 KiB
JavaScript
load("test-common.js");
|
|
|
|
try {
|
|
let p = new Proxy({}, { preventExtensions: null });
|
|
assert(Object.preventExtensions(p) === p);
|
|
p = new Proxy({}, { preventExtensions: undefined });
|
|
assert(Object.preventExtensions(p) === p);
|
|
p = new Proxy({}, {});
|
|
assert(Object.preventExtensions(p) == p);
|
|
|
|
let o = {};
|
|
p = new Proxy(o, {
|
|
preventExtensions(target) {
|
|
assert(target === o);
|
|
return true;
|
|
}
|
|
});
|
|
|
|
Object.preventExtensions(o);
|
|
Object.preventExtensions(p);
|
|
|
|
// Invariants
|
|
|
|
p = new Proxy({}, {
|
|
preventExtensions() {
|
|
return false;
|
|
},
|
|
});
|
|
assertThrowsError(() => {
|
|
Object.preventExtensions(p);
|
|
}, {
|
|
error: TypeError,
|
|
message: "Object's [[PreventExtensions]] method returned false",
|
|
});
|
|
|
|
o = {};
|
|
p = new Proxy(o, {
|
|
preventExtensions() {
|
|
return true;
|
|
},
|
|
});
|
|
assertThrowsError(() => {
|
|
Object.preventExtensions(p);
|
|
}, {
|
|
error: TypeError,
|
|
message: "Proxy handler's preventExtensions trap violates invariant: cannot return true if the target object is extensible"
|
|
});
|
|
|
|
Object.preventExtensions(o);
|
|
assert(Object.preventExtensions(p) === p);
|
|
|
|
console.log("PASS");
|
|
} catch (e) {
|
|
console.log("FAIL: " + e);
|
|
}
|