Debian Codegraph @

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

raw
1 // |reftest| skip-if(!xulRuntime.shell||!this.hasOwnProperty('Atomics')||!this.hasOwnProperty('SharedArrayBuffer')||(this.hasOwnProperty('getBuildConfiguration')&&getBuildConfiguration('arm64-simulator'))) -- browser cannot block main thread, 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 Throws a TypeError if index arg can not be converted to an Integer
9 info: |
10 Atomics.wait( typedArray, index, value, timeout )
11
12 4. Let q be ? ToNumber(timeout).
13
14 Object -> Apply the following steps:
15
16 Let primValue be ? ToPrimitive(argument, hint Number).
17 Return ? ToNumber(primValue).
18
19 features: [Atomics, SharedArrayBuffer, Symbol, Symbol.toPrimitive, TypedArray]
20 flags: [CanBlockIsTrue]
21 ---*/
22
23 const i32a = new Int32Array(
24 new SharedArrayBuffer(Int32Array.BYTES_PER_ELEMENT * 4)
25 );
26
27 const valueOf = {
28 valueOf: function() {
29 return 0;
30 }
31 };
32
33 const toString = {
34 toString: function() {
35 return "0";
36 }
37 };
38
39 const toPrimitive = {
40 [Symbol.toPrimitive]: function() {
41 return 0;
42 }
43 };
44
45 assert.sameValue(
46 Atomics.wait(i32a, 0, 0, valueOf),
47 'timed-out',
48 'Atomics.wait(i32a, 0, 0, valueOf) returns "timed-out"'
49 );
50 assert.sameValue(
51 Atomics.wait(i32a, 0, 0, toString),
52 'timed-out',
53 'Atomics.wait(i32a, 0, 0, toString) returns "timed-out"'
54 );
55 assert.sameValue(
56 Atomics.wait(i32a, 0, 0, toPrimitive),
57 'timed-out',
58 'Atomics.wait(i32a, 0, 0, toPrimitive) returns "timed-out"'
59 );
60
61 reportCompare(0, 0);