| 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 17 matching lines...) Expand all Loading... |
| 28 // ArrayBuffer | 28 // ArrayBuffer |
| 29 | 29 |
| 30 function TestByteLength(param, expectedByteLength) { | 30 function TestByteLength(param, expectedByteLength) { |
| 31 var ab = new ArrayBuffer(param); | 31 var ab = new ArrayBuffer(param); |
| 32 assertSame(expectedByteLength, ab.byteLength); | 32 assertSame(expectedByteLength, ab.byteLength); |
| 33 } | 33 } |
| 34 | 34 |
| 35 function TestArrayBufferCreation() { | 35 function TestArrayBufferCreation() { |
| 36 TestByteLength(1, 1); | 36 TestByteLength(1, 1); |
| 37 TestByteLength(256, 256); | 37 TestByteLength(256, 256); |
| 38 TestByteLength(-10, 0); | |
| 39 TestByteLength(2.567, 2); | 38 TestByteLength(2.567, 2); |
| 40 TestByteLength(-2.567, 0); | |
| 41 | 39 |
| 42 TestByteLength("abc", 0); | 40 TestByteLength("abc", 0); |
| 43 | 41 |
| 44 TestByteLength(0, 0); | 42 TestByteLength(0, 0); |
| 45 | 43 |
| 44 assertThrows(function() { new ArrayBuffer(-10); }, RangeError); |
| 45 assertThrows(function() { new ArrayBuffer(-2.567); }, RangeError); |
| 46 |
| 46 /* TODO[dslomov]: Reenable the test | 47 /* TODO[dslomov]: Reenable the test |
| 47 assertThrows(function() { | 48 assertThrows(function() { |
| 48 var ab1 = new ArrayBuffer(0xFFFFFFFFFFFF) | 49 var ab1 = new ArrayBuffer(0xFFFFFFFFFFFF) |
| 49 }, RangeError); | 50 }, RangeError); |
| 50 */ | 51 */ |
| 51 | 52 |
| 52 var ab = new ArrayBuffer(); | 53 var ab = new ArrayBuffer(); |
| 53 assertSame(0, ab.byteLength); | 54 assertSame(0, ab.byteLength); |
| 54 } | 55 } |
| 55 | 56 |
| (...skipping 26 matching lines...) Expand all Loading... |
| 82 var ab = new ArrayBuffer(1024); | 83 var ab = new ArrayBuffer(1024); |
| 83 var ab1 = ab.slice(512, 1024); | 84 var ab1 = ab.slice(512, 1024); |
| 84 assertSame(512, ab1.byteLength); | 85 assertSame(512, ab1.byteLength); |
| 85 | 86 |
| 86 TestSlice(512, 1024, 512, 1024); | 87 TestSlice(512, 1024, 512, 1024); |
| 87 TestSlice(512, 1024, 512); | 88 TestSlice(512, 1024, 512); |
| 88 | 89 |
| 89 TestSlice(0, 0, 1, 20); | 90 TestSlice(0, 0, 1, 20); |
| 90 TestSlice(100, 100, 0, 100); | 91 TestSlice(100, 100, 0, 100); |
| 91 TestSlice(100, 100, 0, 1000); | 92 TestSlice(100, 100, 0, 1000); |
| 92 TestSlice(0, 100, 5, 1); | 93 |
| 94 assertThrows(function() { new ArrayBuffer(100).slice(5,1); }, RangeError); |
| 93 | 95 |
| 94 TestSlice(1, 100, -11, -10); | 96 TestSlice(1, 100, -11, -10); |
| 95 TestSlice(9, 100, -10, 99); | 97 TestSlice(9, 100, -10, 99); |
| 96 TestSlice(0, 100, -10, 80); | 98 assertThrows( |
| 99 function () { new ArrayBuffer(100).slice(-10, 80); }, RangeError); |
| 97 TestSlice(10, 100, 80, -10); | 100 TestSlice(10, 100, 80, -10); |
| 98 | 101 |
| 99 TestSlice(10, 100, 90, "100"); | 102 TestSlice(10, 100, 90, "100"); |
| 100 TestSlice(10, 100, "90", "100"); | 103 TestSlice(10, 100, "90", "100"); |
| 101 | 104 |
| 102 TestSlice(0, 100, 90, "abc"); | 105 assertThrows( |
| 106 function() { new ArrayBuffer(100).slice(90,"abc"); }, RangeError); |
| 103 TestSlice(10, 100, "abc", 10); | 107 TestSlice(10, 100, "abc", 10); |
| 104 | 108 |
| 105 TestSlice(10, 100, 0.96, 10.96); | 109 TestSlice(10, 100, 0.96, 10.96); |
| 106 TestSlice(10, 100, 0.96, 10.01); | 110 TestSlice(10, 100, 0.96, 10.01); |
| 107 TestSlice(10, 100, 0.01, 10.01); | 111 TestSlice(10, 100, 0.01, 10.01); |
| 108 TestSlice(10, 100, 0.01, 10.96); | 112 TestSlice(10, 100, 0.01, 10.96); |
| 109 | 113 |
| 110 | 114 |
| 111 TestSlice(10, 100, 90); | 115 TestSlice(10, 100, 90); |
| 112 TestSlice(10, 100, -10); | 116 TestSlice(10, 100, -10); |
| (...skipping 369 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 482 var d3b = new DataView(ab, 256, 0); | 486 var d3b = new DataView(ab, 256, 0); |
| 483 assertSame(ab, d3b.buffer); | 487 assertSame(ab, d3b.buffer); |
| 484 assertSame(256, d3b.byteOffset); | 488 assertSame(256, d3b.byteOffset); |
| 485 assertSame(0, d3b.byteLength); | 489 assertSame(0, d3b.byteLength); |
| 486 | 490 |
| 487 var d3c = new DataView(ab, 256); | 491 var d3c = new DataView(ab, 256); |
| 488 assertSame(ab, d3c.buffer); | 492 assertSame(ab, d3c.buffer); |
| 489 assertSame(256, d3c.byteOffset); | 493 assertSame(256, d3c.byteOffset); |
| 490 assertSame(0, d3c.byteLength); | 494 assertSame(0, d3c.byteLength); |
| 491 | 495 |
| 492 // weird args | 496 var d4 = new DataView(ab, 1, 3.1415926); |
| 493 var d4 = new DataView(ab, -1); | |
| 494 assertSame(ab, d4.buffer); | 497 assertSame(ab, d4.buffer); |
| 495 assertSame(0, d4.byteOffset); | 498 assertSame(1, d4.byteOffset); |
| 496 assertSame(256, d4.byteLength); | 499 assertSame(3, d4.byteLength); |
| 497 | |
| 498 var d5 = new DataView(ab, 1, -1); | |
| 499 assertSame(ab, d5.buffer); | |
| 500 assertSame(1, d5.byteOffset); | |
| 501 assertSame(0, d5.byteLength); | |
| 502 | |
| 503 var d6 = new DataView(ab, 1, 3.1415926); | |
| 504 assertSame(ab, d6.buffer); | |
| 505 assertSame(1, d6.byteOffset); | |
| 506 assertSame(3, d6.byteLength); | |
| 507 | 500 |
| 508 | 501 |
| 509 // error cases | 502 // error cases |
| 503 assertThrows(function() { new DataView(ab, -1); }, RangeError); |
| 504 assertThrows(function() { new DataView(ab, 1, -1); }, RangeError); |
| 510 assertThrows(function() { new DataView(); }, TypeError); | 505 assertThrows(function() { new DataView(); }, TypeError); |
| 511 assertThrows(function() { new DataView([]); }, TypeError); | 506 assertThrows(function() { new DataView([]); }, TypeError); |
| 512 assertThrows(function() { new DataView(ab, 257); }, RangeError); | 507 assertThrows(function() { new DataView(ab, 257); }, RangeError); |
| 513 assertThrows(function() { new DataView(ab, 1, 1024); }, RangeError); | 508 assertThrows(function() { new DataView(ab, 1, 1024); }, RangeError); |
| 514 } | 509 } |
| 515 | 510 |
| 516 TestDataViewConstructor(); | 511 TestDataViewConstructor(); |
| 517 | 512 |
| 518 function TestDataViewPropertyTypeChecks() { | 513 function TestDataViewPropertyTypeChecks() { |
| 519 var a = new DataView(new ArrayBuffer(10)); | 514 var a = new DataView(new ArrayBuffer(10)); |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 566 TestArbitrary(new ArrayBuffer(256)); | 561 TestArbitrary(new ArrayBuffer(256)); |
| 567 for(i = 0; i < typedArrayConstructors.lenght; i++) { | 562 for(i = 0; i < typedArrayConstructors.lenght; i++) { |
| 568 TestArbitary(new typedArrayConstructors[i](10)); | 563 TestArbitary(new typedArrayConstructors[i](10)); |
| 569 } | 564 } |
| 570 TestArbitrary(new DataView(new ArrayBuffer(256))); | 565 TestArbitrary(new DataView(new ArrayBuffer(256))); |
| 571 | 566 |
| 572 | 567 |
| 573 // Test direct constructor call | 568 // Test direct constructor call |
| 574 assertTrue(ArrayBuffer() instanceof ArrayBuffer); | 569 assertTrue(ArrayBuffer() instanceof ArrayBuffer); |
| 575 assertTrue(DataView(new ArrayBuffer()) instanceof DataView); | 570 assertTrue(DataView(new ArrayBuffer()) instanceof DataView); |
| OLD | NEW |