trap-is-null-target-is-proxy.js (1189B)
1 // Copyright (C) 2020 Alexey Shvayka. All rights reserved. 2 // This code is governed by the BSD license found in the LICENSE file. 3 4 /*--- 5 esid: sec-proxy-object-internal-methods-and-internal-slots-construct-argumentslist-newtarget 6 description: > 7 If "construct" trap is null or undefined, [[Construct]] call is 8 properly forwarded to [[ProxyTarget]] (which is also a Proxy object). 9 info: | 10 [[Construct]] ( argumentsList, newTarget ) 11 12 [...] 13 4. Let target be O.[[ProxyTarget]]. 14 5. Assert: IsConstructor(target) is true. 15 6. Let trap be ? GetMethod(handler, "construct"). 16 7. If trap is undefined, then 17 a. Return ? Construct(target, argumentsList, newTarget). 18 features: [class, Proxy, Reflect, Reflect.construct] 19 ---*/ 20 21 class Foo { 22 constructor(arg) { 23 this.arg = arg; 24 } 25 } 26 27 var FooTarget = new Proxy(Foo, {}); 28 var FooProxy = new Proxy(FooTarget, { 29 construct: null, 30 }); 31 32 var foo = new FooProxy(1); 33 assert(foo instanceof Foo); 34 assert.sameValue(foo.arg, 1); 35 36 class Bar extends Foo { 37 get isBar() { 38 return true; 39 } 40 } 41 42 var bar = Reflect.construct(FooProxy, [2], Bar); 43 assert(bar instanceof Bar); 44 assert.sameValue(bar.arg, 2); 45 assert(bar.isBar); 46 47 reportCompare(0, 0);