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 var x = 0; | |
512 var y = -0; | |
513 assertEquals(Infinity, 1/x); | |
514 assertEquals(-Infinity, 1/y); | |
515 a[x] = 5; | |
516 a[y] = 27; | |
517 assertEquals(27, a[x]); | |
518 assertEquals(27, a[y]); | |
519 } | |
520 | |
521 TestTypedArraysWithIllegalIndices(); | |
522 | |
523 function TestTypedArraysWithIllegalIndicesStrict() { | |
524 'use strict'; | |
525 var a = new Int32Array(100); | |
526 | |
527 a[-10] = 10; | |
528 assertEquals(undefined, a[-10]); | |
529 a["-10"] = 10; | |
530 assertEquals(undefined, a["-10"]); | |
531 | |
532 var s = " -10"; | |
533 a[s] = 10; | |
534 assertEquals(10, a[s]); | |
535 var s1 = " -10 "; | |
536 a[s] = 10; | |
537 assertEquals(10, a[s]); | |
538 | |
539 a["-1e2"] = 10; | |
540 assertEquals(10, a["-1e2"]); | |
541 assertEquals(undefined, a[-1e2]); | |
542 | |
543 a[-Infinity] = 50; | |
544 assertEquals(undefined, a[-Infinity]); | |
545 a[1.5] = 10; | |
546 assertEquals(undefined, a[1.5]); | |
547 var nan = Math.sqrt(-1); | |
548 a[nan] = 5; | |
549 assertEquals(5, a[nan]); | |
550 | |
551 var x = 0; | |
552 var y = -0; | |
553 assertEquals(Infinity, 1/x); | |
554 assertEquals(-Infinity, 1/y); | |
555 a[x] = 5; | |
556 a[y] = 27; | |
557 assertEquals(27, a[x]); | |
558 assertEquals(27, a[y]); | |
559 } | |
560 | |
561 TestTypedArraysWithIllegalIndicesStrict(); | |
562 | |
563 // DataView | 484 // DataView |
564 function TestDataViewConstructor() { | 485 function TestDataViewConstructor() { |
565 var ab = new ArrayBuffer(256); | 486 var ab = new ArrayBuffer(256); |
566 | 487 |
567 var d1 = new DataView(ab, 1, 255); | 488 var d1 = new DataView(ab, 1, 255); |
568 assertTrue(ArrayBuffer.isView(d1)); | 489 assertTrue(ArrayBuffer.isView(d1)); |
569 assertSame(ab, d1.buffer); | 490 assertSame(ab, d1.buffer); |
570 assertSame(1, d1.byteOffset); | 491 assertSame(1, d1.byteOffset); |
571 assertSame(255, d1.byteLength); | 492 assertSame(255, d1.byteLength); |
572 | 493 |
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
663 TestArbitrary(new ArrayBuffer(256)); | 584 TestArbitrary(new ArrayBuffer(256)); |
664 for(i = 0; i < typedArrayConstructors.length; i++) { | 585 for(i = 0; i < typedArrayConstructors.length; i++) { |
665 TestArbitrary(new typedArrayConstructors[i](10)); | 586 TestArbitrary(new typedArrayConstructors[i](10)); |
666 } | 587 } |
667 TestArbitrary(new DataView(new ArrayBuffer(256))); | 588 TestArbitrary(new DataView(new ArrayBuffer(256))); |
668 | 589 |
669 | 590 |
670 // Test direct constructor call | 591 // Test direct constructor call |
671 assertThrows(function() { ArrayBuffer(); }, TypeError); | 592 assertThrows(function() { ArrayBuffer(); }, TypeError); |
672 assertThrows(function() { DataView(new ArrayBuffer()); }, TypeError); | 593 assertThrows(function() { DataView(new ArrayBuffer()); }, TypeError); |
OLD | NEW |