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