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 assertEquals(1, constructor.prototype.forEach.length); | |
20 | |
21 var a = new constructor(2); | |
wingo
2014/09/23 18:11:25
tests needed that typed array foreach methods don'
| |
22 a[0] = 0; | |
23 a[1] = 1; | |
24 | |
25 var count = 0; | |
26 a.forEach(function (n) { count++; }); | |
27 assertEquals(2, count); | |
28 | |
29 // Use specified object as this object when calling the function. | |
30 var o = { value: 42 }; | |
31 var result = []; | |
32 a.forEach(function (n, index, array) { result.push(this.value); }, o); | |
33 assertArrayEquals([42, 42], result); | |
34 | |
35 // Modify the original array. | |
36 count = 0; | |
37 a.forEach(function (n, index, array) { array[index] = n + 1; count++ }); | |
38 assertEquals(2, count); | |
39 assertArrayEquals([1, 2], a); | |
40 } | |
41 | |
42 for (i = 0; i < typedArrayConstructors.length; i++) { | |
43 TestTypedArrayForEach(typedArrayConstructors[i]); | |
44 } | |
OLD | NEW |