symbol-for-index-throws-agent.js (3101B)
1 // |reftest| shell-option(--setpref=atomics_wait_async) skip-if(!this.hasOwnProperty('SharedArrayBuffer')||!this.hasOwnProperty('Atomics')||(this.hasOwnProperty('getBuildConfiguration')&&getBuildConfiguration('arm64-simulator'))||!xulRuntime.shell) async -- 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 esid: sec-atomics.waitasync 6 description: > 7 Throws a TypeError if index arg can not be converted to an Integer 8 info: | 9 Atomics.waitAsync( typedArray, index, value, timeout ) 10 11 1. Return DoWait(async, typedArray, index, value, timeout). 12 13 DoWait ( mode, typedArray, index, value, timeout ) 14 15 2. Let i be ? ValidateAtomicAccess(typedArray, index). 16 17 ValidateAtomicAccess( typedArray, requestIndex ) 18 19 2. Let accessIndex be ? ToIndex(requestIndex). 20 21 ToIndex ( value ) 22 23 2. Else, 24 a. Let integerIndex be ? ToInteger(value). 25 26 ToInteger(value) 27 28 1. Let number be ? ToNumber(argument). 29 30 Symbol --> Throw a TypeError exception. 31 32 flags: [async] 33 includes: [atomicsHelper.js] 34 features: [Atomics.waitAsync, SharedArrayBuffer, Symbol, Symbol.toPrimitive, TypedArray, Atomics, BigInt, arrow-function, async-functions] 35 ---*/ 36 assert.sameValue(typeof Atomics.waitAsync, 'function', 'The value of `typeof Atomics.waitAsync` is "function"'); 37 const RUNNING = 1; 38 39 $262.agent.start(` 40 const poisonedValueOf = { 41 valueOf() { 42 throw new Test262Error('should not evaluate this code'); 43 } 44 }; 45 46 const poisonedToPrimitive = { 47 [Symbol.toPrimitive]() { 48 throw new Test262Error('should not evaluate this code'); 49 } 50 }; 51 52 $262.agent.receiveBroadcast(function(sab) { 53 const i64a = new BigInt64Array(sab); 54 Atomics.add(i64a, ${RUNNING}, 1n); 55 56 let status1 = ''; 57 let status2 = ''; 58 59 try { 60 Atomics.waitAsync(i64a, Symbol('1'), poisonedValueOf, poisonedValueOf); 61 } catch (error) { 62 status1 = 'A ' + error.name; 63 } 64 try { 65 Atomics.waitAsync(i64a, Symbol('2'), poisonedToPrimitive, poisonedToPrimitive); 66 } catch (error) { 67 status2 = 'B ' + error.name; 68 } 69 70 $262.agent.report(status1); 71 $262.agent.report(status2); 72 $262.agent.leaving(); 73 }); 74 `); 75 76 const i64a = new BigInt64Array(new SharedArrayBuffer(BigInt64Array.BYTES_PER_ELEMENT * 4)); 77 78 $262.agent.safeBroadcastAsync(i64a, RUNNING, 1n).then(async agentCount => { 79 assert.sameValue(agentCount, 1n, 'The value of `agentCount` is 1n'); 80 81 assert.sameValue( 82 await $262.agent.getReportAsync(), 83 'A TypeError', 84 '(await $262.agent.getReportAsync()) resolves to the value "A TypeError"' 85 ); 86 87 assert.sameValue( 88 await $262.agent.getReportAsync(), 89 'B TypeError', 90 '(await $262.agent.getReportAsync()) resolves to the value "B TypeError"' 91 ); 92 93 assert.sameValue( 94 Atomics.notify(i64a, 0), 95 0, 96 'Atomics.notify(new BigInt64Array(new SharedArrayBuffer(BigInt64Array.BYTES_PER_ELEMENT * 4)), 0) must return 0' 97 ); 98 }).then($DONE, $DONE);