Debian Codegraph @

js/src/tests/test262/built-ins/Atomics/waitAsync/symbol-for-index-throws-agent.js

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