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 201 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
212 if (elementSize !== 1) { | 212 if (elementSize !== 1) { |
213 assertThrows(function() { new proto(ab, 128*elementSize - 1, 10); }, | 213 assertThrows(function() { new proto(ab, 128*elementSize - 1, 10); }, |
214 RangeError); | 214 RangeError); |
215 var unalignedArrayBuffer = new ArrayBuffer(10*elementSize + 1); | 215 var unalignedArrayBuffer = new ArrayBuffer(10*elementSize + 1); |
216 var goodArray = new proto(unalignedArrayBuffer, 0, 10); | 216 var goodArray = new proto(unalignedArrayBuffer, 0, 10); |
217 assertSame(10, goodArray.length); | 217 assertSame(10, goodArray.length); |
218 assertSame(10*elementSize, goodArray.byteLength); | 218 assertSame(10*elementSize, goodArray.byteLength); |
219 assertThrows(function() { new proto(unalignedArrayBuffer)}, RangeError); | 219 assertThrows(function() { new proto(unalignedArrayBuffer)}, RangeError); |
220 assertThrows(function() { new proto(unalignedArrayBuffer, 5*elementSize)}, | 220 assertThrows(function() { new proto(unalignedArrayBuffer, 5*elementSize)}, |
221 RangeError); | 221 RangeError); |
222 assertThrows(function() { new proto() }, TypeError); | |
223 } | 222 } |
224 | 223 |
225 var aFromString = new proto("30"); | 224 var aFromString = new proto("30"); |
226 assertSame(elementSize, aFromString.BYTES_PER_ELEMENT); | 225 assertSame(elementSize, aFromString.BYTES_PER_ELEMENT); |
227 assertSame(30, aFromString.length); | 226 assertSame(30, aFromString.length); |
228 assertSame(30*elementSize, aFromString.byteLength); | 227 assertSame(30*elementSize, aFromString.byteLength); |
229 assertSame(0, aFromString.byteOffset); | 228 assertSame(0, aFromString.byteOffset); |
230 assertSame(30*elementSize, aFromString.buffer.byteLength); | 229 assertSame(30*elementSize, aFromString.buffer.byteLength); |
231 | 230 |
232 var jsArray = []; | 231 var jsArray = []; |
(...skipping 10 matching lines...) Expand all Loading... |
243 assertSame(typicalElement, aFromArray[i]); | 242 assertSame(typicalElement, aFromArray[i]); |
244 } | 243 } |
245 | 244 |
246 var abLen0 = new ArrayBuffer(0); | 245 var abLen0 = new ArrayBuffer(0); |
247 var aOverAbLen0 = new proto(abLen0); | 246 var aOverAbLen0 = new proto(abLen0); |
248 assertSame(abLen0, aOverAbLen0.buffer); | 247 assertSame(abLen0, aOverAbLen0.buffer); |
249 assertSame(elementSize, aOverAbLen0.BYTES_PER_ELEMENT); | 248 assertSame(elementSize, aOverAbLen0.BYTES_PER_ELEMENT); |
250 assertSame(0, aOverAbLen0.length); | 249 assertSame(0, aOverAbLen0.length); |
251 assertSame(0, aOverAbLen0.byteLength); | 250 assertSame(0, aOverAbLen0.byteLength); |
252 assertSame(0, aOverAbLen0.byteOffset); | 251 assertSame(0, aOverAbLen0.byteOffset); |
| 252 |
| 253 var aNoParam = new proto(); |
| 254 assertSame(elementSize, aNoParam.BYTES_PER_ELEMENT); |
| 255 assertSame(0, aNoParam.length); |
| 256 assertSame(0, aNoParam.byteLength); |
| 257 assertSame(0, aNoParam.byteOffset); |
253 } | 258 } |
254 | 259 |
255 TestTypedArray(Uint8Array, 1, 0xFF); | 260 TestTypedArray(Uint8Array, 1, 0xFF); |
256 TestTypedArray(Int8Array, 1, -0x7F); | 261 TestTypedArray(Int8Array, 1, -0x7F); |
257 TestTypedArray(Uint16Array, 2, 0xFFFF); | 262 TestTypedArray(Uint16Array, 2, 0xFFFF); |
258 TestTypedArray(Int16Array, 2, -0x7FFF); | 263 TestTypedArray(Int16Array, 2, -0x7FFF); |
259 TestTypedArray(Uint32Array, 4, 0xFFFFFFFF); | 264 TestTypedArray(Uint32Array, 4, 0xFFFFFFFF); |
260 TestTypedArray(Int32Array, 4, -0x7FFFFFFF); | 265 TestTypedArray(Int32Array, 4, -0x7FFFFFFF); |
261 TestTypedArray(Float32Array, 4, 0.5); | 266 TestTypedArray(Float32Array, 4, 0.5); |
262 TestTypedArray(Float64Array, 8, 0.5); | 267 TestTypedArray(Float64Array, 8, 0.5); |
(...skipping 295 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
558 TestArbitrary(new ArrayBuffer(256)); | 563 TestArbitrary(new ArrayBuffer(256)); |
559 for(i = 0; i < typedArrayConstructors.lenght; i++) { | 564 for(i = 0; i < typedArrayConstructors.lenght; i++) { |
560 TestArbitary(new typedArrayConstructors[i](10)); | 565 TestArbitary(new typedArrayConstructors[i](10)); |
561 } | 566 } |
562 TestArbitrary(new DataView(new ArrayBuffer(256))); | 567 TestArbitrary(new DataView(new ArrayBuffer(256))); |
563 | 568 |
564 | 569 |
565 // Test direct constructor call | 570 // Test direct constructor call |
566 assertThrows(function() { ArrayBuffer(); }, TypeError); | 571 assertThrows(function() { ArrayBuffer(); }, TypeError); |
567 assertThrows(function() { DataView(new ArrayBuffer()); }, TypeError); | 572 assertThrows(function() { DataView(new ArrayBuffer()); }, TypeError); |
OLD | NEW |