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); |
| 93 |
92 TestSlice(0, 100, 5, 1); | 94 TestSlice(0, 100, 5, 1); |
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 TestSlice(0, 100, -10, 80); |
97 TestSlice(10, 100, 80, -10); | 99 TestSlice(10, 100, 80, -10); |
98 | 100 |
99 TestSlice(10, 100, 90, "100"); | 101 TestSlice(10, 100, 90, "100"); |
100 TestSlice(10, 100, "90", "100"); | 102 TestSlice(10, 100, "90", "100"); |
101 | 103 |
102 TestSlice(0, 100, 90, "abc"); | 104 TestSlice(0, 100, 90, "abc"); |
103 TestSlice(10, 100, "abc", 10); | 105 TestSlice(10, 100, "abc", 10); |
104 | 106 |
105 TestSlice(10, 100, 0.96, 10.96); | 107 TestSlice(10, 100, 0.96, 10.96); |
106 TestSlice(10, 100, 0.96, 10.01); | 108 TestSlice(10, 100, 0.96, 10.01); |
107 TestSlice(10, 100, 0.01, 10.01); | 109 TestSlice(10, 100, 0.01, 10.01); |
108 TestSlice(10, 100, 0.01, 10.96); | 110 TestSlice(10, 100, 0.01, 10.96); |
109 | 111 |
110 | |
111 TestSlice(10, 100, 90); | 112 TestSlice(10, 100, 90); |
112 TestSlice(10, 100, -10); | 113 TestSlice(10, 100, -10); |
113 } | 114 } |
114 | 115 |
115 TestArrayBufferSlice(); | 116 TestArrayBufferSlice(); |
116 | 117 |
117 // Typed arrays | 118 // Typed arrays |
118 | 119 |
119 function TestTypedArray(proto, elementSize, typicalElement) { | 120 function TestTypedArray(proto, elementSize, typicalElement) { |
120 var ab = new ArrayBuffer(256*elementSize); | 121 var ab = new ArrayBuffer(256*elementSize); |
(...skipping 361 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
482 var d3b = new DataView(ab, 256, 0); | 483 var d3b = new DataView(ab, 256, 0); |
483 assertSame(ab, d3b.buffer); | 484 assertSame(ab, d3b.buffer); |
484 assertSame(256, d3b.byteOffset); | 485 assertSame(256, d3b.byteOffset); |
485 assertSame(0, d3b.byteLength); | 486 assertSame(0, d3b.byteLength); |
486 | 487 |
487 var d3c = new DataView(ab, 256); | 488 var d3c = new DataView(ab, 256); |
488 assertSame(ab, d3c.buffer); | 489 assertSame(ab, d3c.buffer); |
489 assertSame(256, d3c.byteOffset); | 490 assertSame(256, d3c.byteOffset); |
490 assertSame(0, d3c.byteLength); | 491 assertSame(0, d3c.byteLength); |
491 | 492 |
492 // weird args | 493 var d4 = new DataView(ab, 1, 3.1415926); |
493 var d4 = new DataView(ab, -1); | |
494 assertSame(ab, d4.buffer); | 494 assertSame(ab, d4.buffer); |
495 assertSame(0, d4.byteOffset); | 495 assertSame(1, d4.byteOffset); |
496 assertSame(256, d4.byteLength); | 496 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 | 497 |
508 | 498 |
509 // error cases | 499 // error cases |
| 500 assertThrows(function() { new DataView(ab, -1); }, RangeError); |
| 501 assertThrows(function() { new DataView(ab, 1, -1); }, RangeError); |
510 assertThrows(function() { new DataView(); }, TypeError); | 502 assertThrows(function() { new DataView(); }, TypeError); |
511 assertThrows(function() { new DataView([]); }, TypeError); | 503 assertThrows(function() { new DataView([]); }, TypeError); |
512 assertThrows(function() { new DataView(ab, 257); }, RangeError); | 504 assertThrows(function() { new DataView(ab, 257); }, RangeError); |
513 assertThrows(function() { new DataView(ab, 1, 1024); }, RangeError); | 505 assertThrows(function() { new DataView(ab, 1, 1024); }, RangeError); |
514 } | 506 } |
515 | 507 |
516 TestDataViewConstructor(); | 508 TestDataViewConstructor(); |
517 | 509 |
518 function TestDataViewPropertyTypeChecks() { | 510 function TestDataViewPropertyTypeChecks() { |
519 var a = new DataView(new ArrayBuffer(10)); | 511 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)); | 558 TestArbitrary(new ArrayBuffer(256)); |
567 for(i = 0; i < typedArrayConstructors.lenght; i++) { | 559 for(i = 0; i < typedArrayConstructors.lenght; i++) { |
568 TestArbitary(new typedArrayConstructors[i](10)); | 560 TestArbitary(new typedArrayConstructors[i](10)); |
569 } | 561 } |
570 TestArbitrary(new DataView(new ArrayBuffer(256))); | 562 TestArbitrary(new DataView(new ArrayBuffer(256))); |
571 | 563 |
572 | 564 |
573 // Test direct constructor call | 565 // Test direct constructor call |
574 assertTrue(ArrayBuffer() instanceof ArrayBuffer); | 566 assertTrue(ArrayBuffer() instanceof ArrayBuffer); |
575 assertTrue(DataView(new ArrayBuffer()) instanceof DataView); | 567 assertTrue(DataView(new ArrayBuffer()) instanceof DataView); |
OLD | NEW |