mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 17:07:34 +00:00
LibJS: Add ErrorTypes for Promise ownKeys trap invariant violations
This commit is contained in:
parent
ca09f20dcf
commit
cf109533de
3 changed files with 65 additions and 3 deletions
|
@ -0,0 +1,56 @@
|
|||
// TODO: Add "[[OwnPropertyKeys]] trap normal behavior" tests
|
||||
|
||||
describe("[[OwnPropertyKeys]] invariants", () => {
|
||||
// TODO: Add tests for other [[OwnPropertyKeys]] trap invariants
|
||||
|
||||
test("cannot report new property of non-extensible object", () => {
|
||||
const target = Object.preventExtensions({});
|
||||
const handler = {
|
||||
ownKeys() {
|
||||
return ["foo", "bar", "baz"];
|
||||
},
|
||||
};
|
||||
const proxy = new Proxy(target, handler);
|
||||
|
||||
expect(() => {
|
||||
Reflect.ownKeys(proxy);
|
||||
}).toThrowWithMessage(
|
||||
TypeError,
|
||||
"Proxy handler's ownKeys trap violates invariant: cannot report new property 'foo' of non-extensible object"
|
||||
);
|
||||
});
|
||||
|
||||
test("cannot skip property of non-extensible object", () => {
|
||||
const target = Object.preventExtensions({ foo: null });
|
||||
const handler = {
|
||||
ownKeys() {
|
||||
return ["bar", "baz"];
|
||||
},
|
||||
};
|
||||
const proxy = new Proxy(target, handler);
|
||||
|
||||
expect(() => {
|
||||
Reflect.ownKeys(proxy);
|
||||
}).toThrowWithMessage(
|
||||
TypeError,
|
||||
"Proxy handler's ownKeys trap violates invariant: cannot skip property 'foo' of non-extensible object"
|
||||
);
|
||||
});
|
||||
|
||||
test("cannot skip non-configurable property", () => {
|
||||
const target = Object.defineProperty({}, "foo", { configurable: false });
|
||||
const handler = {
|
||||
ownKeys() {
|
||||
return ["bar", "baz"];
|
||||
},
|
||||
};
|
||||
const proxy = new Proxy(target, handler);
|
||||
|
||||
expect(() => {
|
||||
Reflect.ownKeys(proxy);
|
||||
}).toThrowWithMessage(
|
||||
TypeError,
|
||||
"Proxy handler's ownKeys trap violates invariant: cannot skip non-configurable property 'foo'"
|
||||
);
|
||||
});
|
||||
});
|
Loading…
Add table
Add a link
Reference in a new issue