| 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..a1a388688d1a0ee206aefac0f612b323f424113f
|
| --- /dev/null
|
| +++ b/test/mjsunit/harmony/typedarrays-foreach.js
|
| @@ -0,0 +1,42 @@
|
| +// 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);
|
| +}
|
| +
|
| +for (i = 0; i < typedArrayConstructors.length; i++) {
|
| + TestTypedArrayForEach(typedArrayConstructors[i]);
|
| +}
|
|
|