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 211 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
222 RangeError); | 222 RangeError); |
223 var unalignedArrayBuffer = new ArrayBuffer(10*elementSize + 1); | 223 var unalignedArrayBuffer = new ArrayBuffer(10*elementSize + 1); |
224 var goodArray = new constr(unalignedArrayBuffer, 0, 10); | 224 var goodArray = new constr(unalignedArrayBuffer, 0, 10); |
225 assertSame(10, goodArray.length); | 225 assertSame(10, goodArray.length); |
226 assertSame(10*elementSize, goodArray.byteLength); | 226 assertSame(10*elementSize, goodArray.byteLength); |
227 assertThrows(function() { new constr(unalignedArrayBuffer)}, RangeError); | 227 assertThrows(function() { new constr(unalignedArrayBuffer)}, RangeError); |
228 assertThrows(function() { new constr(unalignedArrayBuffer, 5*elementSize)}, | 228 assertThrows(function() { new constr(unalignedArrayBuffer, 5*elementSize)}, |
229 RangeError); | 229 RangeError); |
230 } | 230 } |
231 | 231 |
| 232 var aFromUndef = new constr(); |
| 233 assertSame(elementSize, aFromUndef.BYTES_PER_ELEMENT); |
| 234 assertSame(0, aFromUndef.length); |
| 235 assertSame(0*elementSize, aFromUndef.byteLength); |
| 236 assertSame(0, aFromUndef.byteOffset); |
| 237 assertSame(0*elementSize, aFromUndef.buffer.byteLength); |
| 238 |
| 239 var aFromNull = new constr(null); |
| 240 assertSame(elementSize, aFromNull.BYTES_PER_ELEMENT); |
| 241 assertSame(0, aFromNull.length); |
| 242 assertSame(0*elementSize, aFromNull.byteLength); |
| 243 assertSame(0, aFromNull.byteOffset); |
| 244 assertSame(0*elementSize, aFromNull.buffer.byteLength); |
| 245 |
| 246 var aFromBool = new constr(true); |
| 247 assertSame(elementSize, aFromBool.BYTES_PER_ELEMENT); |
| 248 assertSame(1, aFromBool.length); |
| 249 assertSame(1*elementSize, aFromBool.byteLength); |
| 250 assertSame(0, aFromBool.byteOffset); |
| 251 assertSame(1*elementSize, aFromBool.buffer.byteLength); |
| 252 |
232 var aFromString = new constr("30"); | 253 var aFromString = new constr("30"); |
233 assertSame(elementSize, aFromString.BYTES_PER_ELEMENT); | 254 assertSame(elementSize, aFromString.BYTES_PER_ELEMENT); |
234 assertSame(30, aFromString.length); | 255 assertSame(30, aFromString.length); |
235 assertSame(30*elementSize, aFromString.byteLength); | 256 assertSame(30*elementSize, aFromString.byteLength); |
236 assertSame(0, aFromString.byteOffset); | 257 assertSame(0, aFromString.byteOffset); |
237 assertSame(30*elementSize, aFromString.buffer.byteLength); | 258 assertSame(30*elementSize, aFromString.buffer.byteLength); |
238 | 259 |
| 260 assertThrows(function() { new constr(Symbol()); }, TypeError); |
| 261 |
239 var jsArray = []; | 262 var jsArray = []; |
240 for (i = 0; i < 30; i++) { | 263 for (i = 0; i < 30; i++) { |
241 jsArray.push(typicalElement); | 264 jsArray.push(typicalElement); |
242 } | 265 } |
243 var aFromArray = new constr(jsArray); | 266 var aFromArray = new constr(jsArray); |
244 assertSame(elementSize, aFromArray.BYTES_PER_ELEMENT); | 267 assertSame(elementSize, aFromArray.BYTES_PER_ELEMENT); |
245 assertSame(30, aFromArray.length); | 268 assertSame(30, aFromArray.length); |
246 assertSame(30*elementSize, aFromArray.byteLength); | 269 assertSame(30*elementSize, aFromArray.byteLength); |
247 assertSame(0, aFromArray.byteOffset); | 270 assertSame(0, aFromArray.byteOffset); |
248 assertSame(30*elementSize, aFromArray.buffer.byteLength); | 271 assertSame(30*elementSize, aFromArray.buffer.byteLength); |
(...skipping 518 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
767 | 790 |
768 function TestNonConfigurableProperties(constructor) { | 791 function TestNonConfigurableProperties(constructor) { |
769 var arr = new constructor([100]) | 792 var arr = new constructor([100]) |
770 assertFalse(Object.getOwnPropertyDescriptor(arr,"0").configurable) | 793 assertFalse(Object.getOwnPropertyDescriptor(arr,"0").configurable) |
771 assertFalse(delete arr[0]) | 794 assertFalse(delete arr[0]) |
772 } | 795 } |
773 | 796 |
774 for(i = 0; i < typedArrayConstructors.length; i++) { | 797 for(i = 0; i < typedArrayConstructors.length; i++) { |
775 TestNonConfigurableProperties(typedArrayConstructors[i]); | 798 TestNonConfigurableProperties(typedArrayConstructors[i]); |
776 } | 799 } |
OLD | NEW |