poisoned-object-for-timeout-throws-agent.js (2780B)
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 /*--- 6 esid: sec-atomics.waitasync 7 description: > 8 False timeout arg should result in an +0 timeout 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 flags: [async] 22 includes: [atomicsHelper.js] 23 features: [Atomics.waitAsync, SharedArrayBuffer, TypedArray, Atomics, arrow-function, async-functions] 24 ---*/ 25 assert.sameValue(typeof Atomics.waitAsync, 'function', 'The value of `typeof Atomics.waitAsync` is "function"'); 26 27 const RUNNING = 1; 28 29 $262.agent.start(` 30 const poisonedValueOf = { 31 valueOf() { 32 throw new Error('should not evaluate this code'); 33 } 34 }; 35 36 const poisonedToPrimitive = { 37 [Symbol.toPrimitive]() { 38 throw new Error('passing a poisoned object using @@ToPrimitive'); 39 } 40 }; 41 42 $262.agent.receiveBroadcast(function(sab) { 43 const i32a = new Int32Array(sab); 44 Atomics.add(i32a, ${RUNNING}, 1); 45 46 let status1 = ''; 47 let status2 = ''; 48 49 try { 50 Atomics.waitAsync(i32a, 0, 0, poisonedValueOf); 51 } catch (error) { 52 status1 = 'poisonedValueOf'; 53 } 54 try { 55 Atomics.waitAsync(i32a, 0, 0, poisonedToPrimitive); 56 } catch (error) { 57 status2 = 'poisonedToPrimitive'; 58 } 59 60 $262.agent.report(status1); 61 $262.agent.report(status2); 62 $262.agent.leaving(); 63 }); 64 `); 65 66 const i32a = new Int32Array( 67 new SharedArrayBuffer(Int32Array.BYTES_PER_ELEMENT * 4) 68 ); 69 70 $262.agent.safeBroadcastAsync(i32a, RUNNING, 1).then(async (agentCount) => { 71 72 assert.sameValue(agentCount, 1, 'The value of `agentCount` is 1'); 73 74 assert.sameValue( 75 await $262.agent.getReportAsync(), 76 'poisonedValueOf', 77 '(await $262.agent.getReportAsync()) resolves to the value "poisonedValueOf"' 78 ); 79 80 assert.sameValue( 81 await $262.agent.getReportAsync(), 82 'poisonedToPrimitive', 83 '(await $262.agent.getReportAsync()) resolves to the value "poisonedToPrimitive"' 84 ); 85 86 assert.sameValue(Atomics.notify(i32a, 0), 0, 'Atomics.notify(new Int32Array(new SharedArrayBuffer(Int32Array.BYTES_PER_ELEMENT * 4)), 0) must return 0'); 87 88 }).then($DONE, $DONE);