mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-07-29 12:19:54 +00:00
LibJS: Add Proxy objects
Includes all traps except the following: [[Call]], [[Construct]], [[OwnPropertyKeys]]. An important implication of this commit is that any call to any virtual Object method has the potential to throw an exception. These methods were not checked in this commit -- a future commit will have to protect these various method calls throughout the codebase.
This commit is contained in:
parent
58a72e9b81
commit
39ad42defd
Notes:
sideshowbarker
2024-07-19 05:47:32 +09:00
Author: https://github.com/mattco98
Commit: 39ad42defd
Pull-request: https://github.com/SerenityOS/serenity/pull/2489
Reviewed-by: https://github.com/awesomekling
29 changed files with 1697 additions and 54 deletions
55
Libraries/LibJS/Tests/Proxy.handler-preventExtensions.js
Normal file
55
Libraries/LibJS/Tests/Proxy.handler-preventExtensions.js
Normal file
|
@ -0,0 +1,55 @@
|
|||
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: "Proxy preventExtensions handler 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);
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue