Debian Codegraph @

js/src/tests/test262/built-ins/Proxy/construct/trap-is-null.js

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