]> git.saurik.com Git - apple/javascriptcore.git/blame - tests/stress/array-from-set-length.js
JavaScriptCore-7601.1.46.3.tar.gz
[apple/javascriptcore.git] / tests / stress / array-from-set-length.js
CommitLineData
ed1e77d3
A
1function shouldBe(actual, expected) {
2 if (actual !== expected)
3 throw new Error('bad value: ' + actual);
4}
5
6for (var i = 0; i < 10; ++i) {
7 Object.defineProperty(Array.prototype, i, {
8 get() {
9 throw new Error('get is called.');
10 },
11 set(value) {
12 throw new Error('set is called.');
13 }
14 });
15}
16
17class ArrayLike {
18 constructor(length) {
19 this.lengthCalled = false;
20 this._length = length;
21 }
22 set length(value) {
23 this.lengthCalled = true;
24 this._length = value;
25 }
26 get length() {
27 return this._length;
28 }
29}
30
31var arrayLike = new ArrayLike(10);
32for (var i = 0; i < 10; ++i) {
33 arrayLike[i] = i;
34}
35shouldBe(arrayLike.lengthCalled, false);
36
37var generated = Array.from.call(ArrayLike, arrayLike);
38
39shouldBe(generated.length, 10);
40shouldBe(generated instanceof ArrayLike, true);
41for (var i = 0; i < 10; ++i) {
42 shouldBe(generated[i], i);
43}
44shouldBe(arrayLike.lengthCalled, false);
45shouldBe(generated.lengthCalled, true);