Debian Codegraph @

js/src/tests/test262/built-ins/Atomics/wait/object-for-timeout-agent.js

raw
1 // |reftest| skip-if(!this.hasOwnProperty('Atomics')||!this.hasOwnProperty('SharedArrayBuffer')||(this.hasOwnProperty('getBuildConfiguration')&&getBuildConfiguration('arm64-simulator'))) -- Atomics,SharedArrayBuffer is not enabled unconditionally, ARM64 Simulator cannot emulate atomics
2 // Copyright (C) 2018 Amal Hussein. All rights reserved.
3 // This code is governed by the BSD license found in the LICENSE file.
4
5 /*---
6 esid: sec-atomics.wait
7 description: >
8 False timeout arg should result in an +0 timeout
9 info: |
10 Atomics.wait( typedArray, index, value, timeout )
11
12 4. Let q be ? ToNumber(timeout).
13
14 Null -> Return +0.
15
16 includes: [atomicsHelper.js]
17 features: [Atomics, SharedArrayBuffer, TypedArray]
18 ---*/
19
20 const RUNNING = 1;
21
22 $262.agent.start(`
23 const valueOf = {
24 valueOf: function() {
25 return 0;
26 }
27 };
28
29 const toString = {
30 toString: function() {
31 return "0";
32 }
33 };
34
35 const toPrimitive = {
36 [Symbol.toPrimitive]: function() {
37 return 0;
38 }
39 };
40
41 $262.agent.receiveBroadcast(function(sab) {
42 const i32a = new Int32Array(sab);
43 Atomics.add(i32a, ${RUNNING}, 1);
44
45 const status1 = Atomics.wait(i32a, 0, 0, valueOf);
46 const status2 = Atomics.wait(i32a, 0, 0, toString);
47 const status3 = Atomics.wait(i32a, 0, 0, toPrimitive);
48
49 $262.agent.report(status1);
50 $262.agent.report(status2);
51 $262.agent.report(status3);
52 $262.agent.leaving();
53 });
54 `);
55
56 const i32a = new Int32Array(
57 new SharedArrayBuffer(Int32Array.BYTES_PER_ELEMENT * 4)
58 );
59
60 $262.agent.safeBroadcast(i32a);
61 $262.agent.waitUntil(i32a, RUNNING, 1);
62
63 // Try to yield control to ensure the agent actually started to wait.
64 $262.agent.tryYield();
65
66 assert.sameValue(
67 $262.agent.getReport(),
68 'timed-out',
69 '$262.agent.getReport() returns "timed-out"'
70 );
71 assert.sameValue(
72 $262.agent.getReport(),
73 'timed-out',
74 '$262.agent.getReport() returns "timed-out"'
75 );
76 assert.sameValue(
77 $262.agent.getReport(),
78 'timed-out',
79 '$262.agent.getReport() returns "timed-out"'
80 );
81
82 assert.sameValue(Atomics.notify(i32a, 0), 0, 'Atomics.notify(i32a, 0) returns 0');
83
84 reportCompare(0, 0);