Debian Codegraph @

js/src/tests/test262/built-ins/Atomics/waitAsync/bigint/poisoned-object-for-timeout-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 esid: sec-atomics.waitasync
6 description: >
7 False timeout arg should result in an +0 timeout
8 info: |
9 Atomics.waitAsync( typedArray, index, value, timeout )
10
11 1. Return DoWait(async, typedArray, index, value, timeout).
12
13 DoWait ( mode, typedArray, index, value, timeout )
14
15 6. Let q be ? ToNumber(timeout).
16
17 Let primValue be ? ToPrimitive(argument, hint Number).
18 Return ? ToNumber(primValue).
19
20 flags: [async]
21 includes: [atomicsHelper.js]
22 features: [Atomics.waitAsync, SharedArrayBuffer, TypedArray, Atomics, BigInt, arrow-function, async-functions]
23 ---*/
24 assert.sameValue(typeof Atomics.waitAsync, 'function', 'The value of `typeof Atomics.waitAsync` is "function"');
25 const RUNNING = 1;
26
27 $262.agent.start(`
28 const poisonedValueOf = {
29 valueOf() {
30 throw new Error('should not evaluate this code');
31 }
32 };
33
34 const poisonedToPrimitive = {
35 [Symbol.toPrimitive]() {
36 throw new Error('passing a poisoned object using @@ToPrimitive');
37 }
38 };
39
40 $262.agent.receiveBroadcast(function(sab) {
41 const i64a = new BigInt64Array(sab);
42 Atomics.add(i64a, ${RUNNING}, 1n);
43
44 let status1 = '';
45 let status2 = '';
46
47 try {
48 Atomics.waitAsync(i64a, 0, 0n, poisonedValueOf);
49 } catch (error) {
50 status1 = 'poisonedValueOf';
51 }
52 try {
53 Atomics.waitAsync(i64a, 0, 0n, poisonedToPrimitive);
54 } catch (error) {
55 status2 = 'poisonedToPrimitive';
56 }
57
58 $262.agent.report(status1);
59 $262.agent.report(status2);
60 $262.agent.leaving();
61 });
62 `);
63
64 const i64a = new BigInt64Array(new SharedArrayBuffer(BigInt64Array.BYTES_PER_ELEMENT * 4));
65
66 $262.agent.safeBroadcastAsync(i64a, RUNNING, 1n).then(async agentCount => {
67 assert.sameValue(agentCount, 1n, 'The value of `agentCount` is 1n');
68
69 assert.sameValue(
70 await $262.agent.getReportAsync(),
71 'poisonedValueOf',
72 '(await $262.agent.getReportAsync()) resolves to the value "poisonedValueOf"'
73 );
74
75 assert.sameValue(
76 await $262.agent.getReportAsync(),
77 'poisonedToPrimitive',
78 '(await $262.agent.getReportAsync()) resolves to the value "poisonedToPrimitive"'
79 );
80
81 assert.sameValue(
82 Atomics.notify(i64a, 0),
83 0,
84 'Atomics.notify(new BigInt64Array(new SharedArrayBuffer(BigInt64Array.BYTES_PER_ELEMENT * 4)), 0) must return 0'
85 );
86 }).then($DONE, $DONE);