OLD | NEW |
1 // Copyright 2014 the V8 project authors. All rights reserved. | 1 // Copyright 2014 the V8 project authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 // Flags: --harmony-arrays --allow-natives-syntax | 5 // Flags: --harmony-arrays --allow-natives-syntax |
6 | 6 |
7 var typedArrayConstructors = [ | 7 var typedArrayConstructors = [ |
8 Uint8Array, | 8 Uint8Array, |
9 Int8Array, | 9 Int8Array, |
10 Uint16Array, | 10 Uint16Array, |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
78 array[index] = n + 1; | 78 array[index] = n + 1; |
79 count++; | 79 count++; |
80 }); | 80 }); |
81 } catch (e) { | 81 } catch (e) { |
82 } | 82 } |
83 assertEquals(1, count); | 83 assertEquals(1, count); |
84 assertEquals(43, a[0]); | 84 assertEquals(43, a[0]); |
85 assertEquals(42, a[1]); | 85 assertEquals(42, a[1]); |
86 | 86 |
87 // Neutering the buffer backing the typed array mid-way should | 87 // Neutering the buffer backing the typed array mid-way should |
88 // still make .forEach() finish, and the array should keep being | 88 // still make .forEach() finish, but exiting early due to the missing |
89 // empty after neutering it. | 89 // elements, and the array should keep being empty after detaching it. |
| 90 // TODO(dehrenberg): According to the ES6 spec, accessing or testing |
| 91 // for members on a detached TypedArray should throw, so really this |
| 92 // should throw in the third iteration. However, this behavior matches |
| 93 // the Khronos spec. |
| 94 a = new constructor(3); |
90 count = 0; | 95 count = 0; |
91 a.forEach(function (n, index, array) { | 96 a.forEach(function (n, index, array) { |
92 if (count > 0) %ArrayBufferNeuter(array.buffer); | 97 if (count > 0) %ArrayBufferNeuter(array.buffer); |
93 array[index] = n + 1; | 98 array[index] = n + 1; |
94 count++; | 99 count++; |
95 }); | 100 }); |
96 assertEquals(2, count); | 101 assertEquals(2, count); |
97 CheckTypedArrayIsNeutered(a); | 102 CheckTypedArrayIsNeutered(a); |
98 assertEquals(undefined, a[0]); | 103 assertEquals(undefined, a[0]); |
99 | 104 |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
131 count = 0; | 136 count = 0; |
132 a = new typedArrayConstructors[i](4); | 137 a = new typedArrayConstructors[i](4); |
133 constructor.prototype.forEach.call(a, function (x) { count++ }); | 138 constructor.prototype.forEach.call(a, function (x) { count++ }); |
134 assertEquals(a.length, count); | 139 assertEquals(a.length, count); |
135 } | 140 } |
136 } | 141 } |
137 | 142 |
138 for (i = 0; i < typedArrayConstructors.length; i++) { | 143 for (i = 0; i < typedArrayConstructors.length; i++) { |
139 TestTypedArrayForEach(typedArrayConstructors[i]); | 144 TestTypedArrayForEach(typedArrayConstructors[i]); |
140 } | 145 } |
OLD | NEW |