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 463 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
474 assertArrayPrefix(expected, a); | 474 assertArrayPrefix(expected, a); |
475 assertThrows(function() { a.set.call({}) }, TypeError); | 475 assertThrows(function() { a.set.call({}) }, TypeError); |
476 assertThrows(function() { a.set.call([]) }, TypeError); | 476 assertThrows(function() { a.set.call([]) }, TypeError); |
477 | 477 |
478 assertThrows(function() { a.set(0); }, TypeError); | 478 assertThrows(function() { a.set(0); }, TypeError); |
479 assertThrows(function() { a.set(0, 1); }, TypeError); | 479 assertThrows(function() { a.set(0, 1); }, TypeError); |
480 } | 480 } |
481 | 481 |
482 TestTypedArraySet(); | 482 TestTypedArraySet(); |
483 | 483 |
| 484 function TestTypedArraysWithIllegalIndices() { |
| 485 var a = new Int32Array(100); |
| 486 |
| 487 a[-10] = 10; |
| 488 assertEquals(undefined, a[-10]); |
| 489 a["-10"] = 10; |
| 490 assertEquals(undefined, a["-10"]); |
| 491 |
| 492 var s = " -10"; |
| 493 a[s] = 10; |
| 494 assertEquals(10, a[s]); |
| 495 var s1 = " -10 "; |
| 496 a[s] = 10; |
| 497 assertEquals(10, a[s]); |
| 498 |
| 499 a["-1e2"] = 10; |
| 500 assertEquals(10, a["-1e2"]); |
| 501 assertEquals(undefined, a[-1e2]); |
| 502 |
| 503 a[-Infinity] = 50; |
| 504 assertEquals(undefined, a[-Infinity]); |
| 505 a[1.5] = 10; |
| 506 assertEquals(undefined, a[1.5]); |
| 507 var nan = Math.sqrt(-1); |
| 508 a[nan] = 5; |
| 509 assertEquals(5, a[nan]); |
| 510 } |
| 511 |
| 512 TestTypedArraysWithIllegalIndices(); |
| 513 |
484 // DataView | 514 // DataView |
485 function TestDataViewConstructor() { | 515 function TestDataViewConstructor() { |
486 var ab = new ArrayBuffer(256); | 516 var ab = new ArrayBuffer(256); |
487 | 517 |
488 var d1 = new DataView(ab, 1, 255); | 518 var d1 = new DataView(ab, 1, 255); |
489 assertTrue(ArrayBuffer.isView(d1)); | 519 assertTrue(ArrayBuffer.isView(d1)); |
490 assertSame(ab, d1.buffer); | 520 assertSame(ab, d1.buffer); |
491 assertSame(1, d1.byteOffset); | 521 assertSame(1, d1.byteOffset); |
492 assertSame(255, d1.byteLength); | 522 assertSame(255, d1.byteLength); |
493 | 523 |
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
584 TestArbitrary(new ArrayBuffer(256)); | 614 TestArbitrary(new ArrayBuffer(256)); |
585 for(i = 0; i < typedArrayConstructors.length; i++) { | 615 for(i = 0; i < typedArrayConstructors.length; i++) { |
586 TestArbitrary(new typedArrayConstructors[i](10)); | 616 TestArbitrary(new typedArrayConstructors[i](10)); |
587 } | 617 } |
588 TestArbitrary(new DataView(new ArrayBuffer(256))); | 618 TestArbitrary(new DataView(new ArrayBuffer(256))); |
589 | 619 |
590 | 620 |
591 // Test direct constructor call | 621 // Test direct constructor call |
592 assertThrows(function() { ArrayBuffer(); }, TypeError); | 622 assertThrows(function() { ArrayBuffer(); }, TypeError); |
593 assertThrows(function() { DataView(new ArrayBuffer()); }, TypeError); | 623 assertThrows(function() { DataView(new ArrayBuffer()); }, TypeError); |
OLD | NEW |