Chromium Code Reviews| 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 353 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 364 CheckProperty("byteOffset"); | 364 CheckProperty("byteOffset"); |
| 365 CheckProperty("byteLength"); | 365 CheckProperty("byteLength"); |
| 366 CheckProperty("length"); | 366 CheckProperty("length"); |
| 367 } | 367 } |
| 368 | 368 |
| 369 for(i = 0; i < typedArrayConstructors.lenght; i++) { | 369 for(i = 0; i < typedArrayConstructors.lenght; i++) { |
| 370 TestPropertyTypeChecks(typedArrayConstructors[i]); | 370 TestPropertyTypeChecks(typedArrayConstructors[i]); |
| 371 } | 371 } |
| 372 | 372 |
| 373 | 373 |
| 374 function TestTypedArraySet() { | |
| 375 // Test array.set in different combinations. | |
| 376 | |
| 377 function assertArrayPrefix(expected, array) { | |
| 378 for (var i = 0; i < expected.length; ++i) { | |
| 379 assertEquals(expected[i], array[i]); | |
| 380 } | |
| 381 } | |
| 382 | |
| 383 var a11 = new Int16Array([1, 2, 3, 4, 0, -1]) | |
| 384 var a12 = new Uint16Array(15) | |
| 385 a12.set(a11, 3) | |
| 386 assertArrayPrefix([0, 0, 0, 1, 2, 3, 4, 0, 0xffff, 0, 0], a12) | |
| 387 assertThrows(function(){ a11.set(a12) }) | |
| 388 | |
| 389 var a21 = [1, undefined, 10, NaN, 0, -1, {valueOf: function() {return 3}}] | |
| 390 var a22 = new Int32Array(12) | |
| 391 a22.set(a21, 2) | |
| 392 assertArrayPrefix([0, 0, 1, 0, 10, 0, 0, -1, 3, 0], a22) | |
| 393 | |
| 394 var a31 = new Float32Array([2, 4, 6, 8, 11, NaN, 1/0, -3]) | |
| 395 var a32 = a31.subarray(2, 6) | |
| 396 a31.set(a32, 4) | |
| 397 assertArrayPrefix([2, 4, 6, 8, 6, 8, 11, NaN], a31) | |
| 398 assertArrayPrefix([6, 8, 6, 8], a32) | |
| 399 | |
| 400 var a4 = new Uint8ClampedArray([3,2,5,6]) | |
| 401 a4.set(a4) | |
| 402 assertArrayPrefix([3, 2, 5, 6], a4) | |
| 403 | |
| 404 // Cases with overlapping backing store but different element sizes. | |
| 405 var b = new ArrayBuffer(4) | |
| 406 var a5 = new Int16Array(b) | |
| 407 var a50 = new Int8Array(b) | |
| 408 var a51 = new Int8Array(b, 0, 2) | |
| 409 var a52 = new Int8Array(b, 1, 2) | |
| 410 var a53 = new Int8Array(b, 2, 2) | |
| 411 | |
| 412 a5.set([0x5050, 0x0a0a]) | |
| 413 assertArrayPrefix([0x50, 0x50, 0x0a, 0x0a], a50) | |
| 414 assertArrayPrefix([0x50, 0x50], a51) | |
| 415 assertArrayPrefix([0x50, 0x0a], a52) | |
| 416 assertArrayPrefix([0x0a, 0x0a], a53) | |
| 417 | |
| 418 a50.set([0x50, 0x50, 0x0a, 0x0a]) | |
| 419 a51.set(a5) | |
| 420 assertArrayPrefix([0x50, 0x0a, 0x0a, 0x0a], a50) | |
| 421 | |
| 422 a50.set([0x50, 0x50, 0x0a, 0x0a]) | |
| 423 a52.set(a5) | |
| 424 assertArrayPrefix([0x50, 0x50, 0x0a, 0x0a], a50) | |
| 425 | |
| 426 a50.set([0x50, 0x50, 0x0a, 0x0a]) | |
| 427 a53.set(a5) | |
| 428 assertArrayPrefix([0x50, 0x50, 0x50, 0x0a], a50) | |
| 429 | |
| 430 a50.set([0x50, 0x51, 0x0a, 0x0b]) | |
| 431 a5.set(a51) | |
| 432 assertArrayPrefix([0x0050, 0x0051], a5) | |
| 433 | |
| 434 a50.set([0x50, 0x51, 0x0a, 0x0b]) | |
| 435 a5.set(a52) | |
| 436 assertArrayPrefix([0x0051, 0x000a], a5) | |
| 437 | |
| 438 a50.set([0x50, 0x51, 0x0a, 0x0b]) | |
| 439 a5.set(a53) | |
| 440 assertArrayPrefix([0x000a, 0x000b], a5) | |
| 441 | |
| 442 // Mixed types of same size. | |
| 443 var a61 = new Float32Array([1.2, 12.3]) | |
| 444 var a62 = new Int32Array(2) | |
| 445 a62.set(a61) | |
| 446 assertArrayPrefix([1, 12], a62) | |
| 447 a61.set(a62) | |
| 448 assertArrayPrefix([1, 12], a61) | |
| 449 | |
| 450 // Invalid source | |
| 451 var a = new Uint16Array(50); | |
| 452 assertThrows(function() { a.set(0) }, TypeError); | |
| 453 assertThrows(function() { a.set({}) }, TypeError); | |
| 454 assertThrows(function() { a.set.call({}) }, TypeError); | |
| 455 assertThrows(function() { a.set.call(0) }, TypeError); | |
|
rossberg
2013/05/07 14:31:45
More interestingly, maybe add a case for []
| |
| 456 } | |
| 457 | |
| 458 TestTypedArraySet(); | |
| 459 | |
| 374 // General tests for properties | 460 // General tests for properties |
| 375 | 461 |
| 376 // Test property attribute [[Enumerable]] | 462 // Test property attribute [[Enumerable]] |
| 377 function TestEnumerable(func, obj) { | 463 function TestEnumerable(func, obj) { |
| 378 function props(x) { | 464 function props(x) { |
| 379 var array = []; | 465 var array = []; |
| 380 for (var p in x) array.push(p); | 466 for (var p in x) array.push(p); |
| 381 return array.sort(); | 467 return array.sort(); |
| 382 } | 468 } |
| 383 assertArrayEquals([], props(func)); | 469 assertArrayEquals([], props(func)); |
| (...skipping 19 matching lines...) Expand all Loading... | |
| 403 } | 489 } |
| 404 TestArbitrary(new ArrayBuffer(256)); | 490 TestArbitrary(new ArrayBuffer(256)); |
| 405 for(i = 0; i < typedArrayConstructors.lenght; i++) { | 491 for(i = 0; i < typedArrayConstructors.lenght; i++) { |
| 406 TestArbitary(new typedArrayConstructors[i](10)); | 492 TestArbitary(new typedArrayConstructors[i](10)); |
| 407 } | 493 } |
| 408 | 494 |
| 409 | 495 |
| 410 | 496 |
| 411 // Test direct constructor call | 497 // Test direct constructor call |
| 412 assertTrue(ArrayBuffer() instanceof ArrayBuffer); | 498 assertTrue(ArrayBuffer() instanceof ArrayBuffer); |
| OLD | NEW |