symbol-for-value-throws-agent.js (2883B)
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 value arg is a Symbol 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 5. Otherwise, let v be ? ToInt32(value). 16 17 ToInt32(value) 18 19 1.Let number be ? ToNumber(argument). 20 21 Symbol --> Throw a TypeError exception. 22 23 flags: [async] 24 includes: [atomicsHelper.js] 25 features: [Atomics.waitAsync, SharedArrayBuffer, Symbol, Symbol.toPrimitive, TypedArray, Atomics, BigInt, arrow-function, async-functions] 26 ---*/ 27 assert.sameValue(typeof Atomics.waitAsync, 'function', 'The value of `typeof Atomics.waitAsync` is "function"'); 28 const RUNNING = 1; 29 30 $262.agent.start(` 31 const poisonedValueOf = { 32 valueOf: function() { 33 throw new Test262Error('should not evaluate this code'); 34 } 35 }; 36 37 const poisonedToPrimitive = { 38 [Symbol.toPrimitive]: function() { 39 throw new Test262Error("passing a poisoned object using @@ToPrimitive"); 40 } 41 }; 42 43 $262.agent.receiveBroadcast(function(sab) { 44 const i64a = new BigInt64Array(sab); 45 Atomics.add(i64a, ${RUNNING}, 1n); 46 47 let status1 = ""; 48 let status2 = ""; 49 50 try { 51 Atomics.waitAsync(i64a, 0, Symbol("1"), poisonedValueOf); 52 } catch (error) { 53 status1 = 'A ' + error.name; 54 } 55 try { 56 Atomics.waitAsync(i64a, 0, Symbol("2"), poisonedToPrimitive); 57 } catch (error) { 58 status2 = 'B ' + error.name; 59 } 60 61 $262.agent.report(status1); 62 $262.agent.report(status2); 63 $262.agent.leaving(); 64 }); 65 `); 66 67 const i64a = new BigInt64Array(new SharedArrayBuffer(BigInt64Array.BYTES_PER_ELEMENT * 4)); 68 69 $262.agent.safeBroadcastAsync(i64a, RUNNING, 1n).then(async agentCount => { 70 assert.sameValue(agentCount, 1n, 'The value of `agentCount` is 1n'); 71 72 assert.sameValue( 73 await $262.agent.getReportAsync(), 74 'A TypeError', 75 '(await $262.agent.getReportAsync()) resolves to the value "A TypeError"' 76 ); 77 78 assert.sameValue( 79 await $262.agent.getReportAsync(), 80 'B TypeError', 81 '(await $262.agent.getReportAsync()) resolves to the value "B TypeError"' 82 ); 83 84 assert.sameValue( 85 Atomics.notify(i64a, 0), 86 0, 87 'Atomics.notify(new BigInt64Array(new SharedArrayBuffer(BigInt64Array.BYTES_PER_ELEMENT * 4)), 0) must return 0' 88 ); 89 }).then($DONE, $DONE);