OLD | NEW |
1 // Copyright 2015 the V8 project authors. All rights reserved. | 1 // Copyright 2015 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 // Tests for standard TypedArray array iteration functions. | 5 // Tests for standard TypedArray array iteration functions. |
6 | 6 |
| 7 // Flags: --allow-natives-syntax |
| 8 |
7 var typedArrayConstructors = [ | 9 var typedArrayConstructors = [ |
8 Uint8Array, | 10 Uint8Array, |
9 Int8Array, | 11 Int8Array, |
10 Uint16Array, | 12 Uint16Array, |
11 Int16Array, | 13 Int16Array, |
12 Uint32Array, | 14 Uint32Array, |
13 Int32Array, | 15 Int32Array, |
14 Uint8ClampedArray, | 16 Uint8ClampedArray, |
15 Float32Array, | 17 Float32Array, |
16 Float64Array | 18 Float64Array |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
70 assertThrows(function() { | 72 assertThrows(function() { |
71 constructor.prototype.filter.call([], function() {}); | 73 constructor.prototype.filter.call([], function() {}); |
72 }, TypeError); | 74 }, TypeError); |
73 | 75 |
74 // Shadowing the length property doesn't change anything | 76 // Shadowing the length property doesn't change anything |
75 a = new constructor([1, 2]); | 77 a = new constructor([1, 2]); |
76 Object.defineProperty(a, 'length', { value: 1 }); | 78 Object.defineProperty(a, 'length', { value: 1 }); |
77 assertArrayLikeEquals([2], a.filter(function(elt) { | 79 assertArrayLikeEquals([2], a.filter(function(elt) { |
78 return elt == 2; | 80 return elt == 2; |
79 }), constructor); | 81 }), constructor); |
| 82 |
| 83 // Detached Operation |
| 84 var array = new constructor([1, 2, 3, 4, 5, 6, 7, 8, 9, 10]); |
| 85 %ArrayBufferNeuter(array.buffer); |
| 86 assertThrows(() => array.filter(() => false), TypeError); |
80 })(); | 87 })(); |
81 | 88 |
82 (function TypedArrayMapTest() { | 89 (function TypedArrayMapTest() { |
83 var a = new constructor([0, 1, 2, 3, 4]); | 90 var a = new constructor([0, 1, 2, 3, 4]); |
84 | 91 |
85 // Simple use. | 92 // Simple use. |
86 var result = [1, 2, 3, 4, 5]; | 93 var result = [1, 2, 3, 4, 5]; |
87 assertArrayLikeEquals(result, a.map(function(n) { return n + 1; }), | 94 assertArrayLikeEquals(result, a.map(function(n) { return n + 1; }), |
88 constructor); | 95 constructor); |
89 assertEquals(a, a); | 96 assertEquals(a, a); |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
123 | 130 |
124 // Test that the result is converted to the right type | 131 // Test that the result is converted to the right type |
125 assertArrayLikeEquals([3, 3], new constructor([1, 2]).map(function() { | 132 assertArrayLikeEquals([3, 3], new constructor([1, 2]).map(function() { |
126 return "3"; | 133 return "3"; |
127 }), constructor); | 134 }), constructor); |
128 if (constructor !== Float32Array && constructor !== Float64Array) { | 135 if (constructor !== Float32Array && constructor !== Float64Array) { |
129 assertArrayLikeEquals([0, 0], new constructor([1, 2]).map(function() { | 136 assertArrayLikeEquals([0, 0], new constructor([1, 2]).map(function() { |
130 return NaN; | 137 return NaN; |
131 }), constructor); | 138 }), constructor); |
132 } | 139 } |
| 140 |
| 141 // Detached Operation |
| 142 var array = new constructor([1, 2, 3, 4, 5, 6, 7, 8, 9, 10]); |
| 143 %ArrayBufferNeuter(array.buffer); |
| 144 assertThrows(() => array.map((v) => v), TypeError); |
133 })(); | 145 })(); |
134 | 146 |
135 // | 147 // |
136 // %TypedArray%.prototype.some | 148 // %TypedArray%.prototype.some |
137 // | 149 // |
138 (function TypedArraySomeTest() { | 150 (function TypedArraySomeTest() { |
139 var a = new constructor([0, 1, 2, 3, 4]); | 151 var a = new constructor([0, 1, 2, 3, 4]); |
140 | 152 |
141 // Simple use. | 153 // Simple use. |
142 assertTrue(a.some(function(n) { return n == 3})); | 154 assertTrue(a.some(function(n) { return n == 3})); |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
182 constructor.prototype.some.call([], function() {}); | 194 constructor.prototype.some.call([], function() {}); |
183 }, TypeError); | 195 }, TypeError); |
184 | 196 |
185 // Shadowing the length property doesn't change anything | 197 // Shadowing the length property doesn't change anything |
186 a = new constructor([1, 2]); | 198 a = new constructor([1, 2]); |
187 Object.defineProperty(a, 'length', { value: 1 }); | 199 Object.defineProperty(a, 'length', { value: 1 }); |
188 assertEquals(true, a.some(function(elt) { return elt == 2; })); | 200 assertEquals(true, a.some(function(elt) { return elt == 2; })); |
189 assertEquals(false, Array.prototype.some.call(a, function(elt) { | 201 assertEquals(false, Array.prototype.some.call(a, function(elt) { |
190 return elt == 2; | 202 return elt == 2; |
191 })); | 203 })); |
| 204 |
| 205 // Detached Operation |
| 206 var array = new constructor([1, 2, 3, 4, 5, 6, 7, 8, 9, 10]); |
| 207 %ArrayBufferNeuter(array.buffer); |
| 208 assertThrows(() => array.some((v) => false), TypeError); |
192 })(); | 209 })(); |
193 | 210 |
194 } | 211 } |
OLD | NEW |