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 185 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
196 if (elementSize !== 1) { | 196 if (elementSize !== 1) { |
197 assertThrows(function() { new proto(ab, 128*elementSize - 1, 10); }, | 197 assertThrows(function() { new proto(ab, 128*elementSize - 1, 10); }, |
198 RangeError); | 198 RangeError); |
199 var unalignedArrayBuffer = new ArrayBuffer(10*elementSize + 1); | 199 var unalignedArrayBuffer = new ArrayBuffer(10*elementSize + 1); |
200 var goodArray = new proto(unalignedArrayBuffer, 0, 10); | 200 var goodArray = new proto(unalignedArrayBuffer, 0, 10); |
201 assertSame(10, goodArray.length); | 201 assertSame(10, goodArray.length); |
202 assertSame(10*elementSize, goodArray.byteLength); | 202 assertSame(10*elementSize, goodArray.byteLength); |
203 assertThrows(function() { new proto(unalignedArrayBuffer)}, RangeError); | 203 assertThrows(function() { new proto(unalignedArrayBuffer)}, RangeError); |
204 assertThrows(function() { new proto(unalignedArrayBuffer, 5*elementSize)}, | 204 assertThrows(function() { new proto(unalignedArrayBuffer, 5*elementSize)}, |
205 RangeError); | 205 RangeError); |
| 206 assertThrows(function() { new proto() }, TypeError); |
206 } | 207 } |
207 | 208 |
| 209 var aFromString = new proto("30"); |
| 210 assertSame(elementSize, aFromString.BYTES_PER_ELEMENT); |
| 211 assertSame(30, aFromString.length); |
| 212 assertSame(30*elementSize, aFromString.byteLength); |
| 213 assertSame(0, aFromString.byteOffset); |
| 214 assertSame(30*elementSize, aFromString.buffer.byteLength); |
| 215 |
| 216 var jsArray = []; |
| 217 for (i = 0; i < 30; i++) { |
| 218 jsArray.push(typicalElement); |
| 219 } |
| 220 var aFromArray = new proto(jsArray); |
| 221 assertSame(elementSize, aFromArray.BYTES_PER_ELEMENT); |
| 222 assertSame(30, aFromArray.length); |
| 223 assertSame(30*elementSize, aFromArray.byteLength); |
| 224 assertSame(0, aFromArray.byteOffset); |
| 225 assertSame(30*elementSize, aFromArray.buffer.byteLength); |
| 226 for (i = 0; i < 30; i++) { |
| 227 assertSame(typicalElement, aFromArray[i]); |
| 228 } |
208 } | 229 } |
209 | 230 |
210 TestTypedArray(Uint8Array, 1, 0xFF); | 231 TestTypedArray(Uint8Array, 1, 0xFF); |
211 TestTypedArray(Int8Array, 1, -0x7F); | 232 TestTypedArray(Int8Array, 1, -0x7F); |
212 TestTypedArray(Uint16Array, 2, 0xFFFF); | 233 TestTypedArray(Uint16Array, 2, 0xFFFF); |
213 TestTypedArray(Int16Array, 2, -0x7FFF); | 234 TestTypedArray(Int16Array, 2, -0x7FFF); |
214 TestTypedArray(Uint32Array, 4, 0xFFFFFFFF); | 235 TestTypedArray(Uint32Array, 4, 0xFFFFFFFF); |
215 TestTypedArray(Int32Array, 4, -0x7FFFFFFF); | 236 TestTypedArray(Int32Array, 4, -0x7FFFFFFF); |
216 TestTypedArray(Float32Array, 4, 0.5); | 237 TestTypedArray(Float32Array, 4, 0.5); |
217 TestTypedArray(Float64Array, 8, 0.5); | 238 TestTypedArray(Float64Array, 8, 0.5); |
(...skipping 25 matching lines...) Expand all Loading... |
243 } | 264 } |
244 for (var i = 0; i < 20; i++) { | 265 for (var i = 0; i < 20; i++) { |
245 TestProperty(m, i, 'val' + i); | 266 TestProperty(m, i, 'val' + i); |
246 TestProperty(m, 'foo' + i, 'bar' + i); | 267 TestProperty(m, 'foo' + i, 'bar' + i); |
247 } | 268 } |
248 } | 269 } |
249 TestArbitrary(new ArrayBuffer(256)); | 270 TestArbitrary(new ArrayBuffer(256)); |
250 | 271 |
251 // Test direct constructor call | 272 // Test direct constructor call |
252 assertTrue(ArrayBuffer() instanceof ArrayBuffer); | 273 assertTrue(ArrayBuffer() instanceof ArrayBuffer); |
OLD | NEW |