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