mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-08-27 12:46:06 +00:00
LibJS: Support receiver in ProxyObject::get/put()
If a receiver is given, e.g. via Reflect.get/set(), forward it to the target object's get()/put() or use it as last argument of the trap function. The default value is the Proxy object itself.
This commit is contained in:
parent
76308c2e1f
commit
f6f0d3cbae
Notes:
sideshowbarker
2024-07-19 01:16:54 +09:00
Author: https://github.com/linusg
Commit: f6f0d3cbae
Pull-request: https://github.com/SerenityOS/serenity/pull/4157
3 changed files with 35 additions and 6 deletions
|
@ -40,6 +40,16 @@ describe("[[Get]] trap normal behavior", () => {
|
|||
expect(p.test).toBeUndefined();
|
||||
expect(p[Symbol.hasInstance]).toBeUndefined();
|
||||
});
|
||||
|
||||
test("custom receiver value", () => {
|
||||
let p = new Proxy({}, {
|
||||
get(target, property, receiver) {
|
||||
return receiver;
|
||||
},
|
||||
});
|
||||
|
||||
expect(Reflect.get(p, "foo", 42)).toBe(42);
|
||||
});
|
||||
});
|
||||
|
||||
describe("[[Get]] invariants", () => {
|
||||
|
|
|
@ -43,6 +43,21 @@ describe("[[Set]] trap normal behavior", () => {
|
|||
p[Symbol.hasInstance] = "foo"
|
||||
expect(p[Symbol.hasInstance]).toBe("foo");
|
||||
});
|
||||
|
||||
test("custom receiver value", () => {
|
||||
const o = {};
|
||||
const r = {};
|
||||
let p = new Proxy(o, {
|
||||
set(target, property, value, receiver) {
|
||||
receiver[property] = value;
|
||||
return true;
|
||||
},
|
||||
});
|
||||
|
||||
expect(Reflect.set(p, "foo", 42, r)).toBe(true);
|
||||
expect(o.foo).toBeUndefined();
|
||||
expect(r.foo).toBe(42);
|
||||
});
|
||||
});
|
||||
|
||||
describe("[[Set]] invariants", () => {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue