OLD | NEW |
(Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 // Flags: --harmony-typedarrays |
| 6 |
| 7 var typedArrayConstructors = [ |
| 8 Uint8Array, |
| 9 Int8Array, |
| 10 Uint16Array, |
| 11 Int16Array, |
| 12 Uint32Array, |
| 13 Int32Array, |
| 14 Uint8ClampedArray, |
| 15 Float32Array, |
| 16 Float64Array]; |
| 17 |
| 18 function TestTypedArrayForEach(constructor) { |
| 19 var a = new constructor(2); |
| 20 a[0] = 0; |
| 21 a[1] = 1; |
| 22 |
| 23 var count = 0; |
| 24 a.forEach(function (n) { count++; }); |
| 25 assertEquals(2, count); |
| 26 |
| 27 // Use specified object as this object when calling the function. |
| 28 var o = { value: 42 }; |
| 29 var result = []; |
| 30 a.forEach(function (n, index, array) { result.push(this.value); }, o); |
| 31 assertArrayEquals([42, 42], result); |
| 32 |
| 33 // Modify the original array. |
| 34 count = 0; |
| 35 a.forEach(function (n, index, array) { array[index] = n + 1; count++ }); |
| 36 assertEquals(2, count); |
| 37 assertArrayEquals([1, 2], a); |
| 38 } |
| 39 |
| 40 for (i = 0; i < typedArrayConstructors.length; i++) { |
| 41 TestTypedArrayForEach(typedArrayConstructors[i]); |
| 42 } |
OLD | NEW |