tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

trap-is-undefined-target-is-proxy.js (1235B)


      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(a, b) {
     23    this.sum = a + b;
     24  }
     25 }
     26 
     27 var FooBound = Foo.bind(null, 1);
     28 var FooTarget = new Proxy(FooBound, {});
     29 var FooProxy = new Proxy(FooTarget, {
     30  construct: undefined,
     31 });
     32 
     33 var foo = new FooBound(2);
     34 assert(foo instanceof Foo);
     35 assert.sameValue(foo.sum, 3);
     36 
     37 class Bar extends Foo {
     38  get isBar() {
     39    return true;
     40  }
     41 }
     42 
     43 var bar = Reflect.construct(FooProxy, [3], Bar);
     44 assert(bar instanceof Bar);
     45 assert.sameValue(bar.sum, 4);
     46 assert(bar.isBar);
     47 
     48 reportCompare(0, 0);