keith_miller@apple.com | 1618c2d | 2016-06-14 22:34:09 +0000 | [diff] [blame] | 1 | // This tests that the lazy watchpoints we set for Symbol.species in our Builtin arrayPrototype functions work. |
| 2 | |
| 3 | |
| 4 | function test(array) { |
| 5 | array = array.splice(2, 2); |
| 6 | array = array.slice(0, 5); |
| 7 | array = array.concat([1,2,3]); |
| 8 | return array; |
| 9 | } |
| 10 | noInline(test); |
| 11 | |
| 12 | function arrayEq(a, b) { |
| 13 | if (a.length !== b.length) |
| 14 | throw new Error(); |
| 15 | |
| 16 | for (let i = 0; i < a.length; i++) { |
| 17 | if (a[i] !== b[i]) |
| 18 | throw new Error(); |
| 19 | } |
| 20 | } |
| 21 | |
| 22 | for (let i = 0; i < 100; i++) |
| 23 | arrayEq(test([1,2,3,4,5,6,7,8,9]), [3,4,1,2,3]); |
| 24 | |
| 25 | class A extends Array { } |
| 26 | |
| 27 | for (let i = 0; i < 100; i++) { |
| 28 | let result = test(new A(1,2,3,4,5,6,7,8,9)); |
| 29 | arrayEq(result, [3,4,1,2,3]); |
| 30 | if (!(result instanceof A)) |
| 31 | throw new Error(); |
| 32 | } |
| 33 | |
| 34 | for (let i = 0; i < 100; i++) |
| 35 | arrayEq(test([1,2,3,4,5,6,7,8,9]), [3,4,1,2,3]); |
| 36 | |
| 37 | delete Array.prototype.sort; |
| 38 | |
| 39 | for (let i = 0; i < 100; i++) |
| 40 | arrayEq(test([1,2,3,4,5,6,7,8,9]), [3,4,1,2,3]); |
| 41 | |
| 42 | for (let i = 0; i < 100; i++) { |
| 43 | let result = test(new A(1,2,3,4,5,6,7,8,9)); |
| 44 | arrayEq(result, [3,4,1,2,3]); |
| 45 | if (!(result instanceof A)) |
| 46 | throw new Error(); |
| 47 | } |