Chromium Code Reviews| Index: test/mjsunit/harmony/typedarrays-foreach.js |
| diff --git a/test/mjsunit/harmony/typedarrays-foreach.js b/test/mjsunit/harmony/typedarrays-foreach.js |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..ca88b39dd52a494364075df14f0f3e39c46956b6 |
| --- /dev/null |
| +++ b/test/mjsunit/harmony/typedarrays-foreach.js |
| @@ -0,0 +1,44 @@ |
| +// Copyright 2014 the V8 project authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +// Flags: --harmony-typedarrays |
| + |
| +var typedArrayConstructors = [ |
| + Uint8Array, |
| + Int8Array, |
| + Uint16Array, |
| + Int16Array, |
| + Uint32Array, |
| + Int32Array, |
| + Uint8ClampedArray, |
| + Float32Array, |
| + Float64Array]; |
| + |
| +function TestTypedArrayForEach(constructor) { |
| + var a = new constructor(2); |
| + a[0] = 0; |
| + a[1] = 1; |
| + |
| + var count = 0; |
| + a.forEach(function (n) { count++; }); |
| + assertEquals(2, count); |
| + |
| + // Use specified object as this object when calling the function. |
| + var o = { value: 42 }; |
| + var result = []; |
| + a.forEach(function (n, index, array) { result.push(this.value); }, o); |
| + assertArrayEquals([42, 42], result); |
| + |
| + // Modify the original array. |
| + count = 0; |
| + a.forEach(function (n, index, array) { array[index] = n + 1; count++ }); |
| + assertEquals(2, count); |
| + assertArrayEquals([1, 2], a); |
| + |
| + // Respect holes |
|
aperez
2014/09/18 18:18:39
I have to remove this leftover comment, typed arra
|
| +} |
| + |
| +for (i = 0; i < typedArrayConstructors.length; i++) { |
| + TestTypedArrayForEach(typedArrayConstructors[i]); |
| +} |