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