Debian Codegraph @

js/src/tests/test262/built-ins/Atomics/wait/symbol-for-index-throws-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 Throws a TypeError if index arg can not be converted to an Integer
9 info: |
10 Atomics.wait( typedArray, index, value, timeout )
11
12 2. Let i be ? ValidateAtomicAccess(typedArray, index).
13
14 ValidateAtomicAccess( typedArray, requestIndex )
15
16 2. Let accessIndex be ? ToIndex(requestIndex).
17
18 ToIndex ( value )
19
20 2. Else,
21 a. Let integerIndex be ? ToInteger(value).
22
23 ToInteger(value)
24
25 1. Let number be ? ToNumber(argument).
26
27 Symbol --> Throw a TypeError exception.
28
29 includes: [atomicsHelper.js]
30 features: [Atomics, SharedArrayBuffer, Symbol, Symbol.toPrimitive, TypedArray]
31 ---*/
32
33 const RUNNING = 1;
34
35 $262.agent.start(`
36 const poisonedValueOf = {
37 valueOf: function() {
38 throw new Test262Error('should not evaluate this code');
39 }
40 };
41
42 const poisonedToPrimitive = {
43 [Symbol.toPrimitive]: function() {
44 throw new Test262Error("passing a poisoned object using @@ToPrimitive");
45 }
46 };
47
48 $262.agent.receiveBroadcast(function(sab) {
49 const i32a = new Int32Array(sab);
50 Atomics.add(i32a, ${RUNNING}, 1);
51
52 let status1 = "";
53 let status2 = "";
54
55 try {
56 Atomics.wait(i32a, Symbol("1"), poisonedValueOf, poisonedValueOf);
57 } catch (error) {
58 status1 = 'Symbol("1")';
59 }
60 try {
61 Atomics.wait(i32a, Symbol("2"), poisonedToPrimitive, poisonedToPrimitive);
62 } catch (error) {
63 status2 = 'Symbol("2")';
64 }
65
66 $262.agent.report(status1);
67 $262.agent.report(status2);
68 $262.agent.leaving();
69 });
70 `);
71
72 const i32a = new Int32Array(
73 new SharedArrayBuffer(Int32Array.BYTES_PER_ELEMENT * 4)
74 );
75
76 $262.agent.safeBroadcast(i32a);
77 $262.agent.waitUntil(i32a, RUNNING, 1);
78
79 // Try to yield control to ensure the agent actually started to wait.
80 $262.agent.tryYield();
81
82 assert.sameValue(
83 $262.agent.getReport(),
84 'Symbol("1")',
85 '$262.agent.getReport() returns "Symbol("1")"'
86 );
87 assert.sameValue(
88 $262.agent.getReport(),
89 'Symbol("2")',
90 '$262.agent.getReport() returns "Symbol("2")"'
91 );
92
93 assert.sameValue(Atomics.notify(i32a, 0), 0, 'Atomics.notify(i32a, 0) returns 0');
94
95 reportCompare(0, 0);