good-views.js (2358B)
1 // |reftest| shell-option(--setpref=atomics_wait_async) skip-if(!this.hasOwnProperty('Atomics')||!xulRuntime.shell) async -- Atomics is not enabled unconditionally, 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 Test Atomics.waitAsync on arrays that allow atomic operations 9 flags: [async] 10 includes: [atomicsHelper.js, asyncHelpers.js] 11 features: [Atomics.waitAsync, Atomics] 12 ---*/ 13 assert.sameValue(typeof Atomics.waitAsync, 'function', 'The value of `typeof Atomics.waitAsync` is "function"'); 14 15 $262.agent.start(` 16 (async () => { 17 var sab = new SharedArrayBuffer(1024); 18 var good_indices = [ (view) => 0/-1, // -0 19 (view) => '-0', 20 (view) => view.length - 1, 21 (view) => ({ valueOf: () => 0 }), 22 (view) => ({ toString: () => '0', valueOf: false }) // non-callable valueOf triggers invocation of toString 23 ]; 24 25 var view = new Int32Array(sab, 32, 20); 26 27 view[0] = 0; 28 $262.agent.report("A " + (await Atomics.waitAsync(view, 0, 0, 0).value)) 29 $262.agent.report("B " + (await Atomics.waitAsync(view, 0, 37, 0).value)); 30 31 const results = []; 32 // In-bounds boundary cases for indexing 33 for ( let IdxGen of good_indices ) { 34 let Idx = IdxGen(view); 35 view.fill(0); 36 // Atomics.store() computes an index from Idx in the same way as other 37 // Atomics operations, not quite like view[Idx]. 38 Atomics.store(view, Idx, 37); 39 results.push(await Atomics.waitAsync(view, Idx, 0).value); 40 } 41 $262.agent.report("C " + results.join(",")); 42 $262.agent.leaving(); 43 })(); 44 `); 45 46 47 asyncTest(async () => { 48 const outcomes = []; 49 50 for (let i = 0; i < 3; i++) { 51 outcomes.push(await $262.agent.getReportAsync()); 52 } 53 54 assert.sameValue( 55 outcomes[0], 56 'A timed-out', 57 'The value of outcomes[0] is "A timed-out"' 58 ); 59 60 assert.sameValue( 61 outcomes[1], 62 'B not-equal', 63 'The value of outcomes[1] is "B not-equal"' 64 ); 65 assert.sameValue( 66 outcomes[2], 67 'C not-equal,not-equal,not-equal,not-equal,not-equal', 68 'The value of outcomes[2] is "C not-equal,not-equal,not-equal,not-equal,not-equal"' 69 ); 70 });