Debian Codegraph @

js/src/tests/test262/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 description: >
6 Calls the length setter if available
7 info: |
8 Array.of ( ...items )
9
10 ...
11 9. Let setStatus be Set(A, "length", len, true).
12 ...
13 ---*/
14
15 var hits = 0;
16 var value;
17 var _this_;
18
19 function Pack() {
20 Object.defineProperty(this, "length", {
21 set: function(len) {
22 hits++;
23 value = len;
24 _this_ = this;
25 }
26 });
27 }
28
29 var result = Array.of.call(Pack, 'wolves', 'cards', 'cigarettes', 'lies');
30
31 assert.sameValue(hits, 1, 'The value of hits is expected to be 1');
32 assert.sameValue(
33 value, 4,
34 'The value of value is expected to be 4'
35 );
36 assert.sameValue(_this_, result, 'The value of _this_ is expected to equal the value of result');
37
38 reportCompare(0, 0);