LibJS: Explicitly pass a "Function& new_target" to Function::construct

This allows the proxy handler to pass the proper new.target to construct
handlers.
This commit is contained in:
Matthew Olsson 2020-06-25 15:30:58 -07:00 committed by Andreas Kling
parent 19411e22d0
commit bda39ef7ab
Notes: sideshowbarker 2024-07-19 05:18:39 +09:00
38 changed files with 63 additions and 50 deletions

View file

@ -27,6 +27,21 @@ try {
assert(new p(15).x === 15);
assert(new p(15, true).x === 30);
let p;
function theNewTarget() {};
const handler = {
construct(target, arguments, newTarget) {
assert(target === f);
assert(newTarget === theNewTarget);
if (arguments[1])
return Reflect.construct(target, [arguments[0] * 2], newTarget);
return Reflect.construct(target, arguments, newTarget);
},
};
p = new Proxy(f, handler);
Reflect.construct(p, [15], theNewTarget);
// Invariants
[{}, [], new Proxy({}, {})].forEach(item => {
assertThrowsError(() => {