tor-browser

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

trap-is-missing-target-is-proxy.js (1202B)


      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 includes: [compareArray.js]
     20 ---*/
     21 
     22 var ArrayTarget = new Proxy(Array, {});
     23 var ArrayProxy = new Proxy(ArrayTarget, {});
     24 
     25 var array = new ArrayProxy(1, 2, 3);
     26 assert(Array.isArray(array));
     27 assert.compareArray(array, [1, 2, 3]);
     28 
     29 class MyArray extends Array {
     30  get isMyArray() {
     31    return true;
     32  }
     33 }
     34 
     35 var myArray = Reflect.construct(ArrayProxy, [], MyArray);
     36 assert(Array.isArray(myArray));
     37 assert(myArray instanceof MyArray);
     38 assert(myArray.isMyArray);
     39 
     40 reportCompare(0, 0);