poisoned-object-for-timeout-throws.js (1903B)
1 // |reftest| shell-option(--setpref=atomics_wait_async) skip-if(!this.hasOwnProperty('SharedArrayBuffer')||!this.hasOwnProperty('Atomics')||(this.hasOwnProperty('getBuildConfiguration')&&getBuildConfiguration('arm64-simulator'))||!xulRuntime.shell) -- SharedArrayBuffer,Atomics is not enabled unconditionally, ARM64 Simulator cannot emulate atomics, requires shell-options 2 // Copyright (C) 2020 Rick Waldron. All rights reserved. 3 // This code is governed by the BSD license found in the LICENSE file. 4 5 /*--- 6 esid: sec-atomics.waitasync 7 description: > 8 Throws a TypeError if index arg can not be converted to an Integer 9 info: | 10 Atomics.waitAsync( typedArray, index, value, timeout ) 11 12 1. Return DoWait(async, typedArray, index, value, timeout). 13 14 DoWait ( mode, typedArray, index, value, timeout ) 15 16 6. Let q be ? ToNumber(timeout). 17 18 Let primValue be ? ToPrimitive(argument, hint Number). 19 Return ? ToNumber(primValue). 20 21 features: [Atomics.waitAsync, SharedArrayBuffer, Symbol, Symbol.toPrimitive, TypedArray, computed-property-names, Atomics] 22 ---*/ 23 assert.sameValue(typeof Atomics.waitAsync, 'function', 'The value of `typeof Atomics.waitAsync` is "function"'); 24 25 const i32a = new Int32Array( 26 new SharedArrayBuffer(Int32Array.BYTES_PER_ELEMENT * 4) 27 ); 28 29 const poisonedValueOf = { 30 valueOf() { 31 throw new Test262Error('should not evaluate this code'); 32 } 33 }; 34 35 const poisonedToPrimitive = { 36 [Symbol.toPrimitive]() { 37 throw new Test262Error('passing a poisoned object using @@ToPrimitive'); 38 } 39 }; 40 41 assert.throws(Test262Error, function() { 42 Atomics.waitAsync(i32a, 0, 0, poisonedValueOf); 43 }, '`Atomics.waitAsync(i32a, 0, 0, poisonedValueOf)` throws a Test262Error exception'); 44 45 assert.throws(Test262Error, function() { 46 Atomics.waitAsync(i32a, 0, 0, poisonedToPrimitive); 47 }, '`Atomics.waitAsync(i32a, 0, 0, poisonedToPrimitive)` throws a Test262Error exception'); 48 49 reportCompare(0, 0);