1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-10 09:47:35 +00:00

LibJS: Convert Proxy tests

This commit is contained in:
Matthew Olsson 2020-07-03 22:43:08 -07:00 committed by Andreas Kling
parent b86faeaeef
commit 449a1cf3a2
14 changed files with 820 additions and 815 deletions

View file

@ -1,49 +1,36 @@
load("test-common.js");
try {
assert(Object.isExtensible(new Proxy({}, { isExtensible: null })) === true);
assert(Object.isExtensible(new Proxy({}, { isExtensible: undefined })) === true);
assert(Object.isExtensible(new Proxy({}, {})) === true);
let o = {};
let p = new Proxy(o, {
isExtensible(target) {
assert(target === o);
return true;
}
describe("[[IsExtensible]] trap normal behavior", () => {
test("forwarding when not defined in handler", () => {
expect(Object.isExtensible(new Proxy({}, { isExtensible: null }))).toBe(true);
expect(Object.isExtensible(new Proxy({}, { isExtensible: undefined }))).toBe(true);
expect(Object.isExtensible(new Proxy({}, {}))).toBe(true);
});
Object.isExtensible(p);
test("correct arguments supplied to trap", () => {
let o = {};
let p = new Proxy(o, {
isExtensible(target) {
expect(target).toBe(o);
return true;
}
});
// Invariants
o = {};
p = new Proxy(o, {
isExtensible(proxyTarget) {
assert(proxyTarget === o);
return true;
},
expect(Object.isExtensible(p)).toBe(true);
});
});
assert(Object.isExtensible(p) === true);
Object.preventExtensions(o);
describe("[[Call]] invariants", () => {
test("return value must match the target's extensibility", () => {
let o = {};
Object.preventExtensions(o);
assertThrowsError(() => {
Object.isExtensible(p);
}, {
error: TypeError,
message: "Proxy handler's isExtensible trap violates invariant: return value must match the target's extensibility",
let p = new Proxy(o, {
isExtensible() {
return true;
},
});
expect(() => {
Object.isExtensible(p);
}).toThrowWithMessage(TypeError, "Proxy handler's isExtensible trap violates invariant: return value must match the target's extensibility");
});
p = new Proxy(o, {
isExtensible(proxyTarget) {
assert(proxyTarget === o);
return false;
},
});
assert(Object.isExtensible(p) === false);
console.log("PASS");
} catch (e) {
console.log("FAIL: " + e);
}
});