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 CheckWrapping(false, Boolean); | 78 CheckWrapping(false, Boolean); |
79 CheckWrapping("xxx", String); | 79 CheckWrapping("xxx", String); |
80 CheckWrapping(42, Number); | 80 CheckWrapping(42, Number); |
81 CheckWrapping(3.14, Number); | 81 CheckWrapping(3.14, Number); |
82 CheckWrapping({}, Object); | 82 CheckWrapping({}, Object); |
83 | 83 |
84 // Neutering the buffer backing the typed array mid-way should | 84 // Neutering the buffer backing the typed array mid-way should |
85 // still make .forEach() finish, and the array should keep being | 85 // still make .forEach() finish, and the array should keep being |
86 // empty after neutering it. | 86 // empty after neutering it. |
87 count = 0; | 87 count = 0; |
88 a = new constructor(2); | 88 a = new constructor(3); |
89 result = a.every(function (n, index, array) { | 89 result = a.every(function (n, index, array) { |
| 90 assertFalse(array[index] === undefined); // don't get here if neutered |
90 if (count > 0) %ArrayBufferNeuter(array.buffer); | 91 if (count > 0) %ArrayBufferNeuter(array.buffer); |
91 array[index] = n + 1; | 92 array[index] = n + 1; |
92 count++; | 93 count++; |
93 return count > 1 ? array[index] === undefined : true; | 94 return count > 1 ? array[index] === undefined : true; |
94 }); | 95 }); |
95 assertEquals(2, count); | 96 assertEquals(2, count); |
96 assertEquals(true, result); | 97 assertEquals(true, result); |
97 CheckTypedArrayIsNeutered(a); | 98 CheckTypedArrayIsNeutered(a); |
98 assertEquals(undefined, a[0]); | 99 assertEquals(undefined, a[0]); |
99 | 100 |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
132 count = 0; | 133 count = 0; |
133 a = new typedArrayConstructors[i](4); | 134 a = new typedArrayConstructors[i](4); |
134 constructor.prototype.every.call(a, function (x) { count++; return true; }); | 135 constructor.prototype.every.call(a, function (x) { count++; return true; }); |
135 assertEquals(a.length, count); | 136 assertEquals(a.length, count); |
136 } | 137 } |
137 } | 138 } |
138 | 139 |
139 for (i = 0; i < typedArrayConstructors.length; i++) { | 140 for (i = 0; i < typedArrayConstructors.length; i++) { |
140 TestTypedArrayForEach(typedArrayConstructors[i]); | 141 TestTypedArrayForEach(typedArrayConstructors[i]); |
141 } | 142 } |
OLD | NEW |