Debian Codegraph @

js/src/tests/test262/built-ins/Atomics/wait/null-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 null;
26 }
27 };
28
29 const toPrimitive = {
30 [Symbol.toPrimitive]: function() {
31 return null;
32 }
33 };
34
35 $262.agent.receiveBroadcast(function(sab) {
36 const i32a = new Int32Array(sab);
37 Atomics.add(i32a, ${RUNNING}, 1);
38
39 const status1 = Atomics.wait(i32a, 0, 0, null);
40 const status2 = Atomics.wait(i32a, 0, 0, valueOf);
41 const status3 = Atomics.wait(i32a, 0, 0, toPrimitive);
42
43 $262.agent.report(status1);
44 $262.agent.report(status2);
45 $262.agent.report(status3);
46 $262.agent.leaving();
47 });
48 `);
49
50 const i32a = new Int32Array(
51 new SharedArrayBuffer(Int32Array.BYTES_PER_ELEMENT * 4)
52 );
53
54 $262.agent.safeBroadcast(i32a);
55 $262.agent.waitUntil(i32a, RUNNING, 1);
56
57 // Try to yield control to ensure the agent actually started to wait.
58 $262.agent.tryYield();
59
60 assert.sameValue(
61 $262.agent.getReport(),
62 'timed-out',
63 '$262.agent.getReport() returns "timed-out"'
64 );
65 assert.sameValue(
66 $262.agent.getReport(),
67 'timed-out',
68 '$262.agent.getReport() returns "timed-out"'
69 );
70 assert.sameValue(
71 $262.agent.getReport(),
72 'timed-out',
73 '$262.agent.getReport() returns "timed-out"'
74 );
75
76 assert.sameValue(Atomics.notify(i32a, 0), 0, 'Atomics.notify(i32a, 0) returns 0');
77
78 reportCompare(0, 0);