| 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-array.of |
| 5 |
es6id: 22.1.2.3 |
| 6 |
description: Passes the number of arguments to the constructor it calls. |
| 7 |
info: | |
| 8 |
Array.of ( ...items ) |
| 9 |
|
| 10 |
1. Let len be the actual number of arguments passed to this function. |
| 11 |
2. Let items be the List of arguments passed to this function. |
| 12 |
3. Let C be the this value. |
| 13 |
4. If IsConstructor(C) is true, then |
| 14 |
a. Let A be Construct(C, «len»). |
| 15 |
... |
| 16 |
---*/ |
| 17 |
|
| 18 |
var len; |
| 19 |
var hits = 0; |
| 20 |
|
| 21 |
function C(length) { |
| 22 |
len = length; |
| 23 |
hits++; |
| 24 |
} |
| 25 |
|
| 26 |
Array.of.call(C); |
| 27 |
assert.sameValue(len, 0, '`Array.of.call(C);` called `new C(0)`'); |
| 28 |
assert.sameValue(hits, 1, 'Called constructor once per call'); |
| 29 |
|
| 30 |
Array.of.call(C, 'a', 'b') |
| 31 |
assert.sameValue(len, 2, '`Array.of.call(C, "a", "b"));` called `new C(2)`'); |
| 32 |
assert.sameValue(hits, 2, 'Called constructor once per call'); |
| 33 |
|
| 34 |
Array.of.call(C, false, null, undefined); |
| 35 |
assert.sameValue( |
| 36 |
len, 3, |
| 37 |
'`Array.of.call(C, false, null, undefined);` called `new C(3)`' |
| 38 |
); |
| 39 |
assert.sameValue(hits, 3, 'Called constructor once per call'); |