Debian Codegraph @

js/src/tests/test262/built-ins/Proxy/construct/call-parameters-new-target.js

raw
1 // Copyright (C) 2017 Aleksey 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 trap is called with handler object as its context, and parameters are:
8 target, an array list with the called arguments and the NewTarget
9 info: |
10 [[Construct]] (argumentsList, newTarget)
11
12 9. Let newObj be Call(trap, handler, «target, argArray, newTarget»).
13 features: [Proxy, Reflect, Reflect.construct]
14 ---*/
15
16 function Target() {}
17
18 function NewTarget() {}
19
20 var handler = {
21 construct: function(target, args, newTarget) {
22 assert.sameValue(this, handler, "trap context is the handler object");
23 assert.sameValue(target, Target, "first parameter is the target object");
24 assert.sameValue(args.length, 2, "arguments list contains all construct arguments");
25
26 var a = args[0];
27 var b = args[1];
28 assert.sameValue(a, 1, "arguments list has first construct argument");
29 assert.sameValue(b, 2, "arguments list has second construct argument");
30 assert.sameValue(newTarget, NewTarget, "newTarget is passed as the third parameter");
31
32 return {
33 sum: a + b
34 };
35 },
36 };
37
38 var P = new Proxy(Target, handler);
39 var res = Reflect.construct(P, [1, 2], NewTarget);
40 assert.sameValue(res.sum, 3);
41
42 reportCompare(0, 0);