OLD | NEW |
1 // Copyright 2013 the V8 project authors. All rights reserved. | 1 // Copyright 2013 the V8 project authors. All rights reserved. |
2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
4 // met: | 4 // met: |
5 // | 5 // |
6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
(...skipping 197 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
208 } | 208 } |
209 | 209 |
210 TestTypedArray(Uint8Array, 1, 0xFF); | 210 TestTypedArray(Uint8Array, 1, 0xFF); |
211 TestTypedArray(Int8Array, 1, -0x7F); | 211 TestTypedArray(Int8Array, 1, -0x7F); |
212 TestTypedArray(Uint16Array, 2, 0xFFFF); | 212 TestTypedArray(Uint16Array, 2, 0xFFFF); |
213 TestTypedArray(Int16Array, 2, -0x7FFF); | 213 TestTypedArray(Int16Array, 2, -0x7FFF); |
214 TestTypedArray(Uint32Array, 4, 0xFFFFFFFF); | 214 TestTypedArray(Uint32Array, 4, 0xFFFFFFFF); |
215 TestTypedArray(Int32Array, 4, -0x7FFFFFFF); | 215 TestTypedArray(Int32Array, 4, -0x7FFFFFFF); |
216 TestTypedArray(Float32Array, 4, 0.5); | 216 TestTypedArray(Float32Array, 4, 0.5); |
217 TestTypedArray(Float64Array, 8, 0.5); | 217 TestTypedArray(Float64Array, 8, 0.5); |
| 218 TestTypedArray(Uint8ClampedArray, 1, 0xFF); |
| 219 |
| 220 function TestTypedArrayOutOfRange(constructor, value, result) { |
| 221 var a = new constructor(1); |
| 222 a[0] = value; |
| 223 assertSame(result, a[0]); |
| 224 } |
| 225 |
| 226 TestTypedArrayOutOfRange(Uint8Array, 0x1FA, 0xFA); |
| 227 TestTypedArrayOutOfRange(Uint8Array, -1, 0xFF); |
| 228 TestTypedArrayOutOfRange(Int8Array, 0x1FA, 0x7A - 0x80); |
| 229 |
| 230 TestTypedArrayOutOfRange(Uint16Array, 0x1FFFA, 0xFFFA); |
| 231 TestTypedArrayOutOfRange(Uint16Array, -1, 0xFFFF); |
| 232 TestTypedArrayOutOfRange(Int16Array, 0x1FFFA, 0x7FFA - 0x8000); |
| 233 |
| 234 TestTypedArrayOutOfRange(Uint32Array, 0x1FFFFFFFA, 0xFFFFFFFA); |
| 235 TestTypedArrayOutOfRange(Uint32Array, -1, 0xFFFFFFFF); |
| 236 TestTypedArrayOutOfRange(Int16Array, 0x1FFFFFFFA, 0x7FFFFFFA - 0x80000000); |
| 237 |
| 238 TestTypedArrayOutOfRange(Uint8ClampedArray, 0x1FA, 0xFF); |
| 239 TestTypedArrayOutOfRange(Uint8ClampedArray, -1, 0); |
218 | 240 |
219 | 241 |
220 // General tests for properties | 242 // General tests for properties |
221 | 243 |
222 // Test property attribute [[Enumerable]] | 244 // Test property attribute [[Enumerable]] |
223 function TestEnumerable(func, obj) { | 245 function TestEnumerable(func, obj) { |
224 function props(x) { | 246 function props(x) { |
225 var array = []; | 247 var array = []; |
226 for (var p in x) array.push(p); | 248 for (var p in x) array.push(p); |
227 return array.sort(); | 249 return array.sort(); |
228 } | 250 } |
229 assertArrayEquals([], props(func)); | 251 assertArrayEquals([], props(func)); |
230 assertArrayEquals([], props(func.prototype)); | 252 assertArrayEquals([], props(func.prototype)); |
231 if (obj) | 253 if (obj) |
232 assertArrayEquals([], props(obj)); | 254 assertArrayEquals([], props(obj)); |
233 } | 255 } |
234 TestEnumerable(ArrayBuffer, new ArrayBuffer()); | 256 TestEnumerable(ArrayBuffer, new ArrayBuffer()); |
235 TestEnumerable(Uint8Array); | 257 TestEnumerable(Uint8Array); |
236 | 258 TestEnumerable(Int8Array); |
| 259 TestEnumerable(Uint16Array); |
| 260 TestEnumerable(Int16Array); |
| 261 TestEnumerable(Uint32Array); |
| 262 TestEnumerable(Int32Array); |
| 263 TestEnumerable(Float32Array); |
| 264 TestEnumerable(Uint8ClampedArray); |
237 | 265 |
238 // Test arbitrary properties on ArrayBuffer | 266 // Test arbitrary properties on ArrayBuffer |
239 function TestArbitrary(m) { | 267 function TestArbitrary(m) { |
240 function TestProperty(map, property, value) { | 268 function TestProperty(map, property, value) { |
241 map[property] = value; | 269 map[property] = value; |
242 assertEquals(value, map[property]); | 270 assertEquals(value, map[property]); |
243 } | 271 } |
244 for (var i = 0; i < 20; i++) { | 272 for (var i = 0; i < 20; i++) { |
245 TestProperty(m, i, 'val' + i); | 273 TestProperty(m, i, 'val' + i); |
246 TestProperty(m, 'foo' + i, 'bar' + i); | 274 TestProperty(m, 'foo' + i, 'bar' + i); |
247 } | 275 } |
248 } | 276 } |
249 TestArbitrary(new ArrayBuffer(256)); | 277 TestArbitrary(new ArrayBuffer(256)); |
250 | 278 |
251 // Test direct constructor call | 279 // Test direct constructor call |
252 assertTrue(ArrayBuffer() instanceof ArrayBuffer); | 280 assertTrue(ArrayBuffer() instanceof ArrayBuffer); |
OLD | NEW |