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, expectedDepth) { | |
91 for (var depth = 0; depth < expectedDepth; depth++) { | |
92 assertFalse(Object.hasOwnProperty(object, field)); | |
93 object = object.__proto__; | |
94 } | |
95 return Object.getOwnPropertyDescriptor(object, field); | |
96 } | |
97 | |
98 function TestTypedArray(constr, elementSize, typicalElement) { | 90 function TestTypedArray(constr, elementSize, typicalElement) { |
99 assertSame(elementSize, constr.BYTES_PER_ELEMENT); | 91 assertSame(elementSize, constr.BYTES_PER_ELEMENT); |
100 | 92 |
101 var sab = new SharedArrayBuffer(256*elementSize); | 93 var sab = new SharedArrayBuffer(256*elementSize); |
102 | 94 |
103 var a0 = new constr(30); | 95 var a0 = new constr(30); |
104 assertEquals("[object " + constr.name + "]", | 96 assertEquals("[object " + constr.name + "]", |
105 Object.prototype.toString.call(a0)); | 97 Object.prototype.toString.call(a0)); |
106 | 98 |
107 // TODO(binji): Should this return false here? It is a view, but it doesn't | 99 // 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... |
204 var aOverAbLen0 = new constr(abLen0); | 196 var aOverAbLen0 = new constr(abLen0); |
205 assertSame(abLen0, aOverAbLen0.buffer); | 197 assertSame(abLen0, aOverAbLen0.buffer); |
206 assertSame(elementSize, aOverAbLen0.BYTES_PER_ELEMENT); | 198 assertSame(elementSize, aOverAbLen0.BYTES_PER_ELEMENT); |
207 assertSame(0, aOverAbLen0.length); | 199 assertSame(0, aOverAbLen0.length); |
208 assertSame(0, aOverAbLen0.byteLength); | 200 assertSame(0, aOverAbLen0.byteLength); |
209 assertSame(0, aOverAbLen0.byteOffset); | 201 assertSame(0, aOverAbLen0.byteOffset); |
210 | 202 |
211 var a = new constr(sab, 64*elementSize, 128); | 203 var a = new constr(sab, 64*elementSize, 128); |
212 assertEquals("[object " + constr.name + "]", | 204 assertEquals("[object " + constr.name + "]", |
213 Object.prototype.toString.call(a)); | 205 Object.prototype.toString.call(a)); |
214 var desc = getPropertyDescriptor(constr.prototype, Symbol.toStringTag, 1); | 206 var desc = Object.getOwnPropertyDescriptor( |
| 207 constr.prototype, Symbol.toStringTag); |
215 assertTrue(desc.configurable); | 208 assertTrue(desc.configurable); |
216 assertFalse(desc.enumerable); | 209 assertFalse(desc.enumerable); |
217 assertFalse(!!desc.writable); | 210 assertFalse(!!desc.writable); |
218 assertFalse(!!desc.set); | 211 assertFalse(!!desc.set); |
219 assertEquals("function", typeof desc.get); | 212 assertEquals("function", typeof desc.get); |
220 } | 213 } |
221 | 214 |
222 TestTypedArray(Uint8Array, 1, 0xFF); | 215 TestTypedArray(Uint8Array, 1, 0xFF); |
223 TestTypedArray(Int8Array, 1, -0x7F); | 216 TestTypedArray(Int8Array, 1, -0x7F); |
224 TestTypedArray(Uint16Array, 2, 0xFFFF); | 217 TestTypedArray(Uint16Array, 2, 0xFFFF); |
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
310 Uint16Array, | 303 Uint16Array, |
311 Int16Array, | 304 Int16Array, |
312 Uint32Array, | 305 Uint32Array, |
313 Int32Array, | 306 Int32Array, |
314 Uint8ClampedArray, | 307 Uint8ClampedArray, |
315 Float32Array, | 308 Float32Array, |
316 Float64Array]; | 309 Float64Array]; |
317 | 310 |
318 function TestPropertyTypeChecks(constructor) { | 311 function TestPropertyTypeChecks(constructor) { |
319 function CheckProperty(name) { | 312 function CheckProperty(name) { |
320 var d = getPropertyDescriptor(constructor.prototype, name, 1); | 313 var d = Object.getOwnPropertyDescriptor(constructor.prototype, name); |
321 var o = {}; | 314 var o = {}; |
322 assertThrows(function() {d.get.call(o);}, TypeError); | 315 assertThrows(function() {d.get.call(o);}, TypeError); |
323 for (var i = 0; i < typedArrayConstructors.length; i++) { | 316 for (var i = 0; i < typedArrayConstructors.length; i++) { |
324 var ctor = typedArrayConstructors[i]; | 317 var ctor = typedArrayConstructors[i]; |
325 var a = MakeSharedTypedArray(ctor, 10); | 318 var a = MakeSharedTypedArray(ctor, 10); |
326 d.get.call(a); // shouldn't throw on any type | 319 if (ctor === constructor) { |
| 320 d.get.call(a); // shouldn't throw |
| 321 } else { |
| 322 assertThrows(function() {d.get.call(a);}, TypeError); |
| 323 } |
327 } | 324 } |
328 } | 325 } |
329 | 326 |
330 CheckProperty("buffer"); | 327 CheckProperty("buffer"); |
331 CheckProperty("byteOffset"); | 328 CheckProperty("byteOffset"); |
332 CheckProperty("byteLength"); | 329 CheckProperty("byteLength"); |
333 CheckProperty("length"); | 330 CheckProperty("length"); |
334 } | 331 } |
335 | 332 |
336 for(i = 0; i < typedArrayConstructors.length; i++) { | 333 for(i = 0; i < typedArrayConstructors.length; i++) { |
(...skipping 234 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
571 for(i = 0; i < typedArrayConstructors.length; i++) { | 568 for(i = 0; i < typedArrayConstructors.length; i++) { |
572 TestArbitrary(MakeSharedTypedArray(typedArrayConstructors[i], 10)); | 569 TestArbitrary(MakeSharedTypedArray(typedArrayConstructors[i], 10)); |
573 } | 570 } |
574 | 571 |
575 // Test direct constructor call | 572 // Test direct constructor call |
576 assertThrows(function() { SharedArrayBuffer(); }, TypeError); | 573 assertThrows(function() { SharedArrayBuffer(); }, TypeError); |
577 for(i = 0; i < typedArrayConstructors.length; i++) { | 574 for(i = 0; i < typedArrayConstructors.length; i++) { |
578 assertThrows(function(i) { typedArrayConstructors[i](); }.bind(this, i), | 575 assertThrows(function(i) { typedArrayConstructors[i](); }.bind(this, i), |
579 TypeError); | 576 TypeError); |
580 } | 577 } |
OLD | NEW |