Debian Codegraph @

tests/auto/qml/ecmascripttests/test262/test/built-ins/Array/of/sets-length.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 esid: sec-array.of
5 es6id: 22.1.2.3
6 description: >
7 Calls the length setter if available
8 info: |
9 Array.of ( ...items )
10
11 ...
12 9. Let setStatus be Set(A, "length", len, true).
13 ...
14 ---*/
15
16 var hits = 0;
17 var value;
18 var _this_;
19
20 function Pack() {
21 Object.defineProperty(this, "length", {
22 set: function(len) {
23 hits++;
24 value = len;
25 _this_ = this;
26 }
27 });
28 }
29
30 var result = Array.of.call(Pack, 'wolves', 'cards', 'cigarettes', 'lies');
31
32 assert.sameValue(hits, 1, 'instance length setter called once');
33 assert.sameValue(
34 value, 4,
35 'setter is called with the number of Array.of arguments'
36 );
37 assert.sameValue(_this_, result, 'setter is called with the new object');