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 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
114 TestSlice(10, 100, 0.01, 10.96); | 114 TestSlice(10, 100, 0.01, 10.96); |
115 | 115 |
116 TestSlice(10, 100, 90); | 116 TestSlice(10, 100, 90); |
117 TestSlice(10, 100, -10); | 117 TestSlice(10, 100, -10); |
118 } | 118 } |
119 | 119 |
120 TestArrayBufferSlice(); | 120 TestArrayBufferSlice(); |
121 | 121 |
122 // Typed arrays | 122 // Typed arrays |
123 | 123 |
| 124 function GetPropertyDescriptor(object, field, expectedDepth) { |
| 125 for (var depth = 0; depth < expectedDepth; depth++) { |
| 126 assertFalse(Object.hasOwnProperty(object, field)); |
| 127 object = object.__proto__; |
| 128 } |
| 129 return Object.getOwnPropertyDescriptor(object, field); |
| 130 } |
| 131 |
124 function TestTypedArray(constr, elementSize, typicalElement) { | 132 function TestTypedArray(constr, elementSize, typicalElement) { |
125 assertSame(elementSize, constr.BYTES_PER_ELEMENT); | 133 assertSame(elementSize, constr.BYTES_PER_ELEMENT); |
126 | 134 |
127 var ab = new ArrayBuffer(256*elementSize); | 135 var ab = new ArrayBuffer(256*elementSize); |
128 | 136 |
129 var a0 = new constr(30); | 137 var a0 = new constr(30); |
130 assertEquals("[object " + constr.name + "]", | 138 assertEquals("[object " + constr.name + "]", |
131 Object.prototype.toString.call(a0)); | 139 Object.prototype.toString.call(a0)); |
132 | 140 |
133 assertTrue(ArrayBuffer.isView(a0)); | 141 assertTrue(ArrayBuffer.isView(a0)); |
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
262 | 270 |
263 var aNoParam = new constr(); | 271 var aNoParam = new constr(); |
264 assertSame(elementSize, aNoParam.BYTES_PER_ELEMENT); | 272 assertSame(elementSize, aNoParam.BYTES_PER_ELEMENT); |
265 assertSame(0, aNoParam.length); | 273 assertSame(0, aNoParam.length); |
266 assertSame(0, aNoParam.byteLength); | 274 assertSame(0, aNoParam.byteLength); |
267 assertSame(0, aNoParam.byteOffset); | 275 assertSame(0, aNoParam.byteOffset); |
268 | 276 |
269 var a = new constr(ab, 64*elementSize, 128); | 277 var a = new constr(ab, 64*elementSize, 128); |
270 assertEquals("[object " + constr.name + "]", | 278 assertEquals("[object " + constr.name + "]", |
271 Object.prototype.toString.call(a)); | 279 Object.prototype.toString.call(a)); |
272 var desc = Object.getOwnPropertyDescriptor( | 280 var desc = GetPropertyDescriptor(constr.prototype, Symbol.toStringTag, 1); |
273 constr.prototype, Symbol.toStringTag); | |
274 assertTrue(desc.configurable); | 281 assertTrue(desc.configurable); |
275 assertFalse(desc.enumerable); | 282 assertFalse(desc.enumerable); |
276 assertFalse(!!desc.writable); | 283 assertFalse(!!desc.writable); |
277 assertFalse(!!desc.set); | 284 assertFalse(!!desc.set); |
278 assertEquals("function", typeof desc.get); | 285 assertEquals("function", typeof desc.get); |
279 } | 286 } |
280 | 287 |
281 TestTypedArray(Uint8Array, 1, 0xFF); | 288 TestTypedArray(Uint8Array, 1, 0xFF); |
282 TestTypedArray(Int8Array, 1, -0x7F); | 289 TestTypedArray(Int8Array, 1, -0x7F); |
283 TestTypedArray(Uint16Array, 2, 0xFFFF); | 290 TestTypedArray(Uint16Array, 2, 0xFFFF); |
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
373 Uint16Array, | 380 Uint16Array, |
374 Int16Array, | 381 Int16Array, |
375 Uint32Array, | 382 Uint32Array, |
376 Int32Array, | 383 Int32Array, |
377 Uint8ClampedArray, | 384 Uint8ClampedArray, |
378 Float32Array, | 385 Float32Array, |
379 Float64Array]; | 386 Float64Array]; |
380 | 387 |
381 function TestPropertyTypeChecks(constructor) { | 388 function TestPropertyTypeChecks(constructor) { |
382 function CheckProperty(name) { | 389 function CheckProperty(name) { |
383 var d = Object.getOwnPropertyDescriptor(constructor.prototype, name); | 390 var d = GetPropertyDescriptor(constructor.prototype, name, 1); |
384 var o = {}; | 391 var o = {}; |
385 assertThrows(function() {d.get.call(o);}, TypeError); | 392 assertThrows(function() {d.get.call(o);}, TypeError); |
386 for (var i = 0; i < typedArrayConstructors.length; i++) { | 393 for (var i = 0; i < typedArrayConstructors.length; i++) { |
387 var ctor = typedArrayConstructors[i]; | 394 var ctor = typedArrayConstructors[i]; |
388 var a = new ctor(10); | 395 var a = new ctor(10); |
389 if (ctor === constructor) { | 396 d.get.call(a); // shouldn't throw, even from a different type |
390 d.get.call(a); // shouldn't throw | |
391 } else { | |
392 assertThrows(function() {d.get.call(a);}, TypeError); | |
393 } | |
394 } | 397 } |
395 } | 398 } |
396 | 399 |
397 CheckProperty("buffer"); | 400 CheckProperty("buffer"); |
398 CheckProperty("byteOffset"); | 401 CheckProperty("byteOffset"); |
399 CheckProperty("byteLength"); | 402 CheckProperty("byteLength"); |
400 CheckProperty("length"); | 403 CheckProperty("length"); |
401 } | 404 } |
402 | 405 |
403 for(i = 0; i < typedArrayConstructors.length; i++) { | 406 for(i = 0; i < typedArrayConstructors.length; i++) { |
(...skipping 308 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
712 TestArbitrary(new ArrayBuffer(256)); | 715 TestArbitrary(new ArrayBuffer(256)); |
713 for(i = 0; i < typedArrayConstructors.length; i++) { | 716 for(i = 0; i < typedArrayConstructors.length; i++) { |
714 TestArbitrary(new typedArrayConstructors[i](10)); | 717 TestArbitrary(new typedArrayConstructors[i](10)); |
715 } | 718 } |
716 TestArbitrary(new DataView(new ArrayBuffer(256))); | 719 TestArbitrary(new DataView(new ArrayBuffer(256))); |
717 | 720 |
718 | 721 |
719 // Test direct constructor call | 722 // Test direct constructor call |
720 assertThrows(function() { ArrayBuffer(); }, TypeError); | 723 assertThrows(function() { ArrayBuffer(); }, TypeError); |
721 assertThrows(function() { DataView(new ArrayBuffer()); }, TypeError); | 724 assertThrows(function() { DataView(new ArrayBuffer()); }, TypeError); |
OLD | NEW |