| OLD | NEW |
| 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 501 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 512 aa = a.subarray(0,-8); | 512 aa = a.subarray(0,-8); |
| 513 assertInstance(aa, Uint16Array); | 513 assertInstance(aa, Uint16Array); |
| 514 assertEquals(0, aa.length); | 514 assertEquals(0, aa.length); |
| 515 assertEquals(0, aa.byteLength); | 515 assertEquals(0, aa.byteLength); |
| 516 assertEquals(2, aa.BYTES_PER_ELEMENT); | 516 assertEquals(2, aa.BYTES_PER_ELEMENT); |
| 517 assertSame(a.buffer, aa.buffer); | 517 assertSame(a.buffer, aa.buffer); |
| 518 | 518 |
| 519 assertThrows(function(){ a.subarray.call({}, 0) }); | 519 assertThrows(function(){ a.subarray.call({}, 0) }); |
| 520 assertThrows(function(){ a.subarray.call([], 0) }); | 520 assertThrows(function(){ a.subarray.call([], 0) }); |
| 521 | 521 |
| 522 // Call constructors directly as functions, and through .call and .apply | 522 // Try to call constructors directly as functions, and through .call |
| 523 // and .apply. Should fail. |
| 523 | 524 |
| 524 b = ArrayBuffer(100) | 525 assertThrows(function() { ArrayBuffer(100); }, TypeError); |
| 525 a = Int8Array(b, 5, 77) | 526 assertThrows(function() { Int8Array(b, 5, 77); }, TypeError); |
| 526 assertInstance(b, ArrayBuffer) | 527 assertThrows(function() { ArrayBuffer.call(null, 10); }, TypeError); |
| 527 assertInstance(a, Int8Array) | 528 assertThrows(function() { Uint16Array.call(null, b, 2, 4); }, TypeError); |
| 528 assertSame(b, a.buffer) | 529 assertThrows(function() { ArrayBuffer.apply(null, [1000]); }, TypeError); |
| 529 assertEquals(5, a.byteOffset) | 530 assertThrows(function() { Float32Array.apply(null, [b, 128, 1]); }, TypeError); |
| 530 assertEquals(77, a.byteLength) | |
| 531 b = ArrayBuffer.call(null, 10) | |
| 532 a = Uint16Array.call(null, b, 2, 4) | |
| 533 assertInstance(b, ArrayBuffer) | |
| 534 assertInstance(a, Uint16Array) | |
| 535 assertSame(b, a.buffer) | |
| 536 assertEquals(2, a.byteOffset) | |
| 537 assertEquals(8, a.byteLength) | |
| 538 b = ArrayBuffer.apply(null, [1000]) | |
| 539 a = Float32Array.apply(null, [b, 128, 1]) | |
| 540 assertInstance(b, ArrayBuffer) | |
| 541 assertInstance(a, Float32Array) | |
| 542 assertSame(b, a.buffer) | |
| 543 assertEquals(128, a.byteOffset) | |
| 544 assertEquals(4, a.byteLength) | |
| 545 | |
| 546 | 531 |
| 547 // Test array.set in different combinations. | 532 // Test array.set in different combinations. |
| 548 | 533 |
| 549 function assertArrayPrefix(expected, array) { | 534 function assertArrayPrefix(expected, array) { |
| 550 for (var i = 0; i < expected.length; ++i) { | 535 for (var i = 0; i < expected.length; ++i) { |
| 551 assertEquals(expected[i], array[i]); | 536 assertEquals(expected[i], array[i]); |
| 552 } | 537 } |
| 553 } | 538 } |
| 554 | 539 |
| 555 var a11 = new Int16Array([1, 2, 3, 4, 0, -1]) | 540 var a11 = new Int16Array([1, 2, 3, 4, 0, -1]) |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 624 assertThrows(function() { a.set({}) }) | 609 assertThrows(function() { a.set({}) }) |
| 625 | 610 |
| 626 | 611 |
| 627 // Test arraybuffer.slice | 612 // Test arraybuffer.slice |
| 628 | 613 |
| 629 var a0 = new Int8Array([1, 2, 3, 4, 5, 6]) | 614 var a0 = new Int8Array([1, 2, 3, 4, 5, 6]) |
| 630 var b0 = a0.buffer | 615 var b0 = a0.buffer |
| 631 | 616 |
| 632 var b1 = b0.slice(0) | 617 var b1 = b0.slice(0) |
| 633 assertEquals(b0.byteLength, b1.byteLength) | 618 assertEquals(b0.byteLength, b1.byteLength) |
| 634 assertArrayPrefix([1, 2, 3, 4, 5, 6], Int8Array(b1)) | 619 assertArrayPrefix([1, 2, 3, 4, 5, 6], new Int8Array(b1)) |
| 635 | 620 |
| 636 var b2 = b0.slice(3) | 621 var b2 = b0.slice(3) |
| 637 assertEquals(b0.byteLength - 3, b2.byteLength) | 622 assertEquals(b0.byteLength - 3, b2.byteLength) |
| 638 assertArrayPrefix([4, 5, 6], Int8Array(b2)) | 623 assertArrayPrefix([4, 5, 6], new Int8Array(b2)) |
| 639 | 624 |
| 640 var b3 = b0.slice(2, 4) | 625 var b3 = b0.slice(2, 4) |
| 641 assertEquals(2, b3.byteLength) | 626 assertEquals(2, b3.byteLength) |
| 642 assertArrayPrefix([3, 4], Int8Array(b3)) | 627 assertArrayPrefix([3, 4], new Int8Array(b3)) |
| 643 | 628 |
| 644 function goo(a, i) { | 629 function goo(a, i) { |
| 645 return a[i]; | 630 return a[i]; |
| 646 } | 631 } |
| 647 | 632 |
| 648 function boo(a, i, v) { | 633 function boo(a, i, v) { |
| 649 return a[i] = v; | 634 return a[i] = v; |
| 650 } | 635 } |
| 651 | 636 |
| 652 function do_tagged_index_external_array_test(constructor) { | 637 function do_tagged_index_external_array_test(constructor) { |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 684 | 669 |
| 685 built_in_array = new Array(1.5, 2, 3, 4, 5, 6); | 670 built_in_array = new Array(1.5, 2, 3, 4, 5, 6); |
| 686 assertEquals(1.5, goo(built_in_array, 0)); | 671 assertEquals(1.5, goo(built_in_array, 0)); |
| 687 assertEquals(1.5, goo(built_in_array, 0)); | 672 assertEquals(1.5, goo(built_in_array, 0)); |
| 688 %OptimizeFunctionOnNextCall(goo); | 673 %OptimizeFunctionOnNextCall(goo); |
| 689 %OptimizeFunctionOnNextCall(boo); | 674 %OptimizeFunctionOnNextCall(boo); |
| 690 boo(built_in_array, 0, 2.5); | 675 boo(built_in_array, 0, 2.5); |
| 691 assertEquals(2.5, goo(built_in_array, 0)); | 676 assertEquals(2.5, goo(built_in_array, 0)); |
| 692 %ClearFunctionTypeFeedback(goo); | 677 %ClearFunctionTypeFeedback(goo); |
| 693 %ClearFunctionTypeFeedback(boo); | 678 %ClearFunctionTypeFeedback(boo); |
| OLD | NEW |