OLD | NEW |
---|---|
1 // Copyright 2015 the V8 project authors. All rights reserved. | 1 // Copyright 2015 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 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
80 // Typed arrays using SharedArrayBuffers | 80 // Typed arrays using SharedArrayBuffers |
81 | 81 |
82 // TODO(binji): how many of these tests are necessary if there are no new | 82 // TODO(binji): how many of these tests are necessary if there are no new |
83 // TypedArray types? | 83 // TypedArray types? |
84 | 84 |
85 function MakeSharedTypedArray(constr, numElements) { | 85 function MakeSharedTypedArray(constr, numElements) { |
86 var sab = new SharedArrayBuffer(constr.BYTES_PER_ELEMENT * numElements); | 86 var sab = new SharedArrayBuffer(constr.BYTES_PER_ELEMENT * numElements); |
87 return new constr(sab); | 87 return new constr(sab); |
88 } | 88 } |
89 | 89 |
90 function GetPropertyDescriptor(object, field) { | |
adamk
2015/06/13 00:49:38
Same worry here, I'd prefer not to do a prototype
| |
91 var descriptor; | |
92 while (descriptor === undefined && object !== Object.prototype) { | |
93 descriptor = Object.getOwnPropertyDescriptor(object, field); | |
94 object = object.__proto__; | |
95 } | |
96 return descriptor; | |
97 } | |
98 | |
90 function TestTypedArray(constr, elementSize, typicalElement) { | 99 function TestTypedArray(constr, elementSize, typicalElement) { |
91 assertSame(elementSize, constr.BYTES_PER_ELEMENT); | 100 assertSame(elementSize, constr.BYTES_PER_ELEMENT); |
92 | 101 |
93 var sab = new SharedArrayBuffer(256*elementSize); | 102 var sab = new SharedArrayBuffer(256*elementSize); |
94 | 103 |
95 var a0 = new constr(30); | 104 var a0 = new constr(30); |
96 assertEquals("[object " + constr.name + "]", | 105 assertEquals("[object " + constr.name + "]", |
97 Object.prototype.toString.call(a0)); | 106 Object.prototype.toString.call(a0)); |
98 | 107 |
99 // TODO(binji): Should this return false here? It is a view, but it doesn't | 108 // TODO(binji): Should this return false here? It is a view, but it doesn't |
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
196 var aOverAbLen0 = new constr(abLen0); | 205 var aOverAbLen0 = new constr(abLen0); |
197 assertSame(abLen0, aOverAbLen0.buffer); | 206 assertSame(abLen0, aOverAbLen0.buffer); |
198 assertSame(elementSize, aOverAbLen0.BYTES_PER_ELEMENT); | 207 assertSame(elementSize, aOverAbLen0.BYTES_PER_ELEMENT); |
199 assertSame(0, aOverAbLen0.length); | 208 assertSame(0, aOverAbLen0.length); |
200 assertSame(0, aOverAbLen0.byteLength); | 209 assertSame(0, aOverAbLen0.byteLength); |
201 assertSame(0, aOverAbLen0.byteOffset); | 210 assertSame(0, aOverAbLen0.byteOffset); |
202 | 211 |
203 var a = new constr(sab, 64*elementSize, 128); | 212 var a = new constr(sab, 64*elementSize, 128); |
204 assertEquals("[object " + constr.name + "]", | 213 assertEquals("[object " + constr.name + "]", |
205 Object.prototype.toString.call(a)); | 214 Object.prototype.toString.call(a)); |
206 var desc = Object.getOwnPropertyDescriptor( | 215 var desc = GetPropertyDescriptor(constr.prototype, Symbol.toStringTag); |
207 constr.prototype, Symbol.toStringTag); | |
208 assertTrue(desc.configurable); | 216 assertTrue(desc.configurable); |
209 assertFalse(desc.enumerable); | 217 assertFalse(desc.enumerable); |
210 assertFalse(!!desc.writable); | 218 assertFalse(!!desc.writable); |
211 assertFalse(!!desc.set); | 219 assertFalse(!!desc.set); |
212 assertEquals("function", typeof desc.get); | 220 assertEquals("function", typeof desc.get); |
213 } | 221 } |
214 | 222 |
215 TestTypedArray(Uint8Array, 1, 0xFF); | 223 TestTypedArray(Uint8Array, 1, 0xFF); |
216 TestTypedArray(Int8Array, 1, -0x7F); | 224 TestTypedArray(Int8Array, 1, -0x7F); |
217 TestTypedArray(Uint16Array, 2, 0xFFFF); | 225 TestTypedArray(Uint16Array, 2, 0xFFFF); |
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
303 Uint16Array, | 311 Uint16Array, |
304 Int16Array, | 312 Int16Array, |
305 Uint32Array, | 313 Uint32Array, |
306 Int32Array, | 314 Int32Array, |
307 Uint8ClampedArray, | 315 Uint8ClampedArray, |
308 Float32Array, | 316 Float32Array, |
309 Float64Array]; | 317 Float64Array]; |
310 | 318 |
311 function TestPropertyTypeChecks(constructor) { | 319 function TestPropertyTypeChecks(constructor) { |
312 function CheckProperty(name) { | 320 function CheckProperty(name) { |
313 var d = Object.getOwnPropertyDescriptor(constructor.prototype, name); | 321 var d = GetPropertyDescriptor(constructor.prototype, name); |
314 var o = {}; | 322 var o = {}; |
315 assertThrows(function() {d.get.call(o);}, TypeError); | 323 assertThrows(function() {d.get.call(o);}, TypeError); |
316 for (var i = 0; i < typedArrayConstructors.length; i++) { | 324 for (var i = 0; i < typedArrayConstructors.length; i++) { |
317 var ctor = typedArrayConstructors[i]; | 325 var ctor = typedArrayConstructors[i]; |
318 var a = MakeSharedTypedArray(ctor, 10); | 326 var a = MakeSharedTypedArray(ctor, 10); |
319 if (ctor === constructor) { | 327 d.get.call(a); // shouldn't throw on any type |
320 d.get.call(a); // shouldn't throw | |
321 } else { | |
322 assertThrows(function() {d.get.call(a);}, TypeError); | |
323 } | |
324 } | 328 } |
325 } | 329 } |
326 | 330 |
327 CheckProperty("buffer"); | 331 CheckProperty("buffer"); |
328 CheckProperty("byteOffset"); | 332 CheckProperty("byteOffset"); |
329 CheckProperty("byteLength"); | 333 CheckProperty("byteLength"); |
330 CheckProperty("length"); | 334 CheckProperty("length"); |
331 } | 335 } |
332 | 336 |
333 for(i = 0; i < typedArrayConstructors.length; i++) { | 337 for(i = 0; i < typedArrayConstructors.length; i++) { |
(...skipping 234 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
568 for(i = 0; i < typedArrayConstructors.length; i++) { | 572 for(i = 0; i < typedArrayConstructors.length; i++) { |
569 TestArbitrary(MakeSharedTypedArray(typedArrayConstructors[i], 10)); | 573 TestArbitrary(MakeSharedTypedArray(typedArrayConstructors[i], 10)); |
570 } | 574 } |
571 | 575 |
572 // Test direct constructor call | 576 // Test direct constructor call |
573 assertThrows(function() { SharedArrayBuffer(); }, TypeError); | 577 assertThrows(function() { SharedArrayBuffer(); }, TypeError); |
574 for(i = 0; i < typedArrayConstructors.length; i++) { | 578 for(i = 0; i < typedArrayConstructors.length; i++) { |
575 assertThrows(function(i) { typedArrayConstructors[i](); }.bind(this, i), | 579 assertThrows(function(i) { typedArrayConstructors[i](); }.bind(this, i), |
576 TypeError); | 580 TypeError); |
577 } | 581 } |
OLD | NEW |