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