tor-browser

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

trap-is-undefined-no-property.js (1468B)


      1 // Copyright (C) 2015 the V8 project authors. All rights reserved.
      2 // This code is governed by the BSD license found in the LICENSE file.
      3 /*---
      4 esid: sec-proxy-object-internal-methods-and-internal-slots-construct-argumentslist-newtarget
      5 description: >
      6    If the construct trap is not set, propagate the construct to the target object.
      7 info: |
      8    [[Construct]] (argumentsList, newTarget)
      9 
     10    ...
     11    5. Let trap be ? GetMethod(handler, "construct").
     12    6. If trap is undefined, then
     13      a. Assert: target has a [[Construct]] internal method.
     14      b. Return ? Construct(target, argumentsList, newTarget).
     15    ...
     16 
     17    GetMethod ( V, P )
     18 
     19    ...
     20    3. If func is either undefined or null, return undefined.
     21    ...
     22 features: [Proxy, Reflect, Reflect.construct]
     23 ---*/
     24 
     25 var calls = 0;
     26 var _NewTarget;
     27 
     28 var Target = new Proxy(function() {
     29  throw new Test262Error('target should not be called');
     30 }, {
     31  construct: function(_Target, args, NewTarget) {
     32    calls += 1;
     33    _NewTarget = NewTarget;
     34    return {
     35      sum: args[0] + args[1]
     36    };
     37  }
     38 })
     39 
     40 var P = new Proxy(Target, {});
     41 var NewTarget = function() {};
     42 var obj = Reflect.construct(P, [3, 4], NewTarget);
     43 
     44 assert.sameValue(calls, 1, "construct is missing: [[Construct]] is invoked once");
     45 assert.sameValue(_NewTarget, NewTarget, "construct is missing: NewTarget is passed to [[Construct]]");
     46 assert.sameValue(obj.sum, 7, "construct is missing: result of [[Construct]] is returned");
     47 
     48 reportCompare(0, 0);