Skip to content

Commit 41ba526

Browse files
committed
Constructing object on chained proxy
In the functiontrap we don't create an object if the target itself is proxy. However as we provide NewTarget flag, the nested functiontrap will try to take the args[0] which later leads to Assert as it was null. Fixed that by constructing an object if the args[0] is null even if the NewTarget flag is passed.
1 parent 9f3f947 commit 41ba526

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

lib/Runtime/Library/JavascriptProxy.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2136,7 +2136,9 @@ namespace Js
21362136
{
21372137
JavascriptError::ThrowTypeError(scriptContext, JSERR_This_NeedFunction, _u("construct"));
21382138
}
2139-
if (!isCtorSuperCall)
2139+
2140+
// args.Values[0] will be null in the case where NewTarget is initially provided by proxy.
2141+
if (!isCtorSuperCall || !args.Values[0])
21402142
{
21412143
newThisObject = JavascriptOperators::NewScObjectNoCtor(targetObj, scriptContext);
21422144
args.Values[0] = newThisObject;

test/es6/proxybugs.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -429,6 +429,22 @@ var tests = [
429429
assert.isUndefined(withtrap.noTrap);
430430
}
431431
},
432+
{
433+
name: "Constructing object from a proxy object (which has proxy as target) should not fire an Assert (OS# 17516464)",
434+
body() {
435+
function Foo(a) {
436+
this.x = a;
437+
}
438+
var proxy = new Proxy(Foo, {});
439+
var proxy1 = new Proxy(proxy, {});
440+
var proxy2 = new Proxy(proxy1, {});
441+
var obj1 = new proxy2(10);
442+
assert.areEqual(10, obj1.x);
443+
444+
var obj2 = Reflect.construct(proxy2, [20]);
445+
assert.areEqual(20, obj2.x);
446+
}
447+
}
432448
];
433449

434450
testRunner.runTests(tests, { verbose: WScript.Arguments[0] != "summary" });

0 commit comments

Comments
 (0)