Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(340)

Side by Side Diff: test/mjsunit/external-array-no-sse2.js

Issue 17904007: Do not allow invocation of ArrayBuffer and array buffer views' constructors as functions. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 7 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « test/mjsunit/external-array.js ('k') | test/mjsunit/harmony/typedarrays.js » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2012 the V8 project authors. All rights reserved. 1 // Copyright 2012 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 502 matching lines...) Expand 10 before | Expand all | Expand 10 after
513 aa = a.subarray(0,-8); 513 aa = a.subarray(0,-8);
514 assertInstance(aa, Uint16Array); 514 assertInstance(aa, Uint16Array);
515 assertEquals(0, aa.length); 515 assertEquals(0, aa.length);
516 assertEquals(0, aa.byteLength); 516 assertEquals(0, aa.byteLength);
517 assertEquals(2, aa.BYTES_PER_ELEMENT); 517 assertEquals(2, aa.BYTES_PER_ELEMENT);
518 assertSame(a.buffer, aa.buffer); 518 assertSame(a.buffer, aa.buffer);
519 519
520 assertThrows(function(){ a.subarray.call({}, 0) }); 520 assertThrows(function(){ a.subarray.call({}, 0) });
521 assertThrows(function(){ a.subarray.call([], 0) }); 521 assertThrows(function(){ a.subarray.call([], 0) });
522 522
523 // Call constructors directly as functions, and through .call and .apply 523 // Try to call constructors directly as functions, and through .call
524 // and .apply. Should fail.
524 525
525 b = ArrayBuffer(100) 526 assertThrows(function() { ArrayBuffer(100); }, TypeError);
526 a = Int8Array(b, 5, 77) 527 assertThrows(function() { Int8Array(b, 5, 77); }, TypeError);
527 assertInstance(b, ArrayBuffer) 528 assertThrows(function() { ArrayBuffer.call(null, 10); }, TypeError);
528 assertInstance(a, Int8Array) 529 assertThrows(function() { Uint16Array.call(null, b, 2, 4); }, TypeError);
529 assertSame(b, a.buffer) 530 assertThrows(function() { ArrayBuffer.apply(null, [1000]); }, TypeError);
530 assertEquals(5, a.byteOffset) 531 assertThrows(function() { Float32Array.apply(null, [b, 128, 1]); }, TypeError);
531 assertEquals(77, a.byteLength)
532 b = ArrayBuffer.call(null, 10)
533 a = Uint16Array.call(null, b, 2, 4)
534 assertInstance(b, ArrayBuffer)
535 assertInstance(a, Uint16Array)
536 assertSame(b, a.buffer)
537 assertEquals(2, a.byteOffset)
538 assertEquals(8, a.byteLength)
539 b = ArrayBuffer.apply(null, [1000])
540 a = Float32Array.apply(null, [b, 128, 1])
541 assertInstance(b, ArrayBuffer)
542 assertInstance(a, Float32Array)
543 assertSame(b, a.buffer)
544 assertEquals(128, a.byteOffset)
545 assertEquals(4, a.byteLength)
546
547 532
548 // Test array.set in different combinations. 533 // Test array.set in different combinations.
549 534
550 function assertArrayPrefix(expected, array) { 535 function assertArrayPrefix(expected, array) {
551 for (var i = 0; i < expected.length; ++i) { 536 for (var i = 0; i < expected.length; ++i) {
552 assertEquals(expected[i], array[i]); 537 assertEquals(expected[i], array[i]);
553 } 538 }
554 } 539 }
555 540
556 var a11 = new Int16Array([1, 2, 3, 4, 0, -1]) 541 var a11 = new Int16Array([1, 2, 3, 4, 0, -1])
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
625 assertThrows(function() { a.set({}) }) 610 assertThrows(function() { a.set({}) })
626 611
627 612
628 // Test arraybuffer.slice 613 // Test arraybuffer.slice
629 614
630 var a0 = new Int8Array([1, 2, 3, 4, 5, 6]) 615 var a0 = new Int8Array([1, 2, 3, 4, 5, 6])
631 var b0 = a0.buffer 616 var b0 = a0.buffer
632 617
633 var b1 = b0.slice(0) 618 var b1 = b0.slice(0)
634 assertEquals(b0.byteLength, b1.byteLength) 619 assertEquals(b0.byteLength, b1.byteLength)
635 assertArrayPrefix([1, 2, 3, 4, 5, 6], Int8Array(b1)) 620 assertArrayPrefix([1, 2, 3, 4, 5, 6], new Int8Array(b1))
636 621
637 var b2 = b0.slice(3) 622 var b2 = b0.slice(3)
638 assertEquals(b0.byteLength - 3, b2.byteLength) 623 assertEquals(b0.byteLength - 3, b2.byteLength)
639 assertArrayPrefix([4, 5, 6], Int8Array(b2)) 624 assertArrayPrefix([4, 5, 6], new Int8Array(b2))
640 625
641 var b3 = b0.slice(2, 4) 626 var b3 = b0.slice(2, 4)
642 assertEquals(2, b3.byteLength) 627 assertEquals(2, b3.byteLength)
643 assertArrayPrefix([3, 4], Int8Array(b3)) 628 assertArrayPrefix([3, 4], new Int8Array(b3))
644 629
645 function goo(a, i) { 630 function goo(a, i) {
646 return a[i]; 631 return a[i];
647 } 632 }
648 633
649 function boo(a, i, v) { 634 function boo(a, i, v) {
650 return a[i] = v; 635 return a[i] = v;
651 } 636 }
652 637
653 function do_tagged_index_external_array_test(constructor) { 638 function do_tagged_index_external_array_test(constructor) {
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
685 670
686 built_in_array = new Array(1.5, 2, 3, 4, 5, 6); 671 built_in_array = new Array(1.5, 2, 3, 4, 5, 6);
687 assertEquals(1.5, goo(built_in_array, 0)); 672 assertEquals(1.5, goo(built_in_array, 0));
688 assertEquals(1.5, goo(built_in_array, 0)); 673 assertEquals(1.5, goo(built_in_array, 0));
689 %OptimizeFunctionOnNextCall(goo); 674 %OptimizeFunctionOnNextCall(goo);
690 %OptimizeFunctionOnNextCall(boo); 675 %OptimizeFunctionOnNextCall(boo);
691 boo(built_in_array, 0, 2.5); 676 boo(built_in_array, 0, 2.5);
692 assertEquals(2.5, goo(built_in_array, 0)); 677 assertEquals(2.5, goo(built_in_array, 0));
693 %ClearFunctionTypeFeedback(goo); 678 %ClearFunctionTypeFeedback(goo);
694 %ClearFunctionTypeFeedback(boo); 679 %ClearFunctionTypeFeedback(boo);
OLDNEW
« no previous file with comments | « test/mjsunit/external-array.js ('k') | test/mjsunit/harmony/typedarrays.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698