Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit fd21429

Browse filesBrowse files
committed
lib: update usage of always on Atomics API
PR-URL: #49639 Reviewed-By: Jiawen Geng <technicalcute@gmail.com> Reviewed-By: Rafael Gonzaga <rafael.nunu@hotmail.com> Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
1 parent 8568de3 commit fd21429
Copy full SHA for fd21429

File tree

Expand file treeCollapse file tree

10 files changed

+18
-51
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

10 files changed

+18
-51
lines changed
Open diff view settings
Collapse file

‎benchmark/worker/atomics-wait.js‎

Copy file name to clipboardExpand all lines: benchmark/worker/atomics-wait.js
-4Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,6 @@ if (typeof SharedArrayBuffer === 'undefined') {
44
throw new Error('SharedArrayBuffers must be enabled to run this benchmark');
55
}
66

7-
if (typeof Atomics === 'undefined') {
8-
throw new Error('Atomics must be enabled to run this benchmark');
9-
}
10-
117
const common = require('../common.js');
128
const bench = common.createBenchmark(main, {
139
n: [1e7],
Collapse file

‎lib/.eslintrc.yaml‎

Copy file name to clipboardExpand all lines: lib/.eslintrc.yaml
+1-4Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,6 @@ rules:
3333
message: Use `const { AbortController } = require('internal/abort_controller');` instead of the global.
3434
- name: AbortSignal
3535
message: Use `const { AbortSignal } = require('internal/abort_controller');` instead of the global.
36-
# Atomics is not available in primordials because it can be
37-
# disabled with --no-harmony-atomics CLI flag.
38-
- name: Atomics
39-
message: Use `const { Atomics } = globalThis;` instead of the global.
4036
- name: Blob
4137
message: Use `const { Blob } = require('buffer');` instead of the global.
4238
- name: BroadcastChannel
@@ -193,6 +189,7 @@ rules:
193189
- name: AggregateError
194190
- name: Array
195191
- name: ArrayBuffer
192+
- name: Atomics
196193
- name: BigInt
197194
- name: BigInt64Array
198195
- name: BigUint64Array
Collapse file

‎lib/internal/freeze_intrinsics.js‎

Copy file name to clipboardExpand all lines: lib/internal/freeze_intrinsics.js
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ const {
3131
ArrayPrototype,
3232
ArrayPrototypeForEach,
3333
ArrayPrototypePush,
34+
Atomics,
3435
BigInt,
3536
BigInt64Array,
3637
BigInt64ArrayPrototype,
@@ -128,7 +129,6 @@ const {
128129
} = primordials;
129130

130131
const {
131-
Atomics,
132132
Intl,
133133
SharedArrayBuffer,
134134
WebAssembly,
Collapse file

‎lib/internal/main/worker_thread.js‎

Copy file name to clipboardExpand all lines: lib/internal/main/worker_thread.js
+3-3Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,12 @@ const {
77
ArrayPrototypeForEach,
88
ArrayPrototypePushApply,
99
ArrayPrototypeSplice,
10+
AtomicsLoad,
1011
ObjectDefineProperty,
1112
PromisePrototypeThen,
1213
RegExpPrototypeExec,
1314
SafeWeakMap,
1415
globalThis: {
15-
Atomics,
1616
SharedArrayBuffer,
1717
},
1818
} = primordials;
@@ -112,15 +112,15 @@ port.on('message', (message) => {
112112

113113
require('internal/worker').assignEnvironmentData(environmentData);
114114

115-
if (SharedArrayBuffer !== undefined && Atomics !== undefined) {
115+
if (SharedArrayBuffer !== undefined) {
116116
// The counter is only passed to the workers created by the main thread,
117117
// not to workers created by other workers.
118118
let cachedCwd = '';
119119
let lastCounter = -1;
120120
const originalCwd = process.cwd;
121121

122122
process.cwd = function() {
123-
const currentCounter = Atomics.load(cwdCounter, 0);
123+
const currentCounter = AtomicsLoad(cwdCounter, 0);
124124
if (currentCounter === lastCounter)
125125
return cachedCwd;
126126
lastCounter = currentCounter;
Collapse file

‎lib/internal/modules/esm/hooks.js‎

Copy file name to clipboardExpand all lines: lib/internal/modules/esm/hooks.js
+3-5Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@
33
const {
44
ArrayPrototypePush,
55
ArrayPrototypePushApply,
6+
AtomicsLoad,
7+
AtomicsWait,
8+
AtomicsWaitAsync,
69
Int32Array,
710
ObjectAssign,
811
ObjectDefineProperty,
@@ -15,11 +18,6 @@ const {
1518
} = primordials;
1619

1720
const {
18-
Atomics: {
19-
load: AtomicsLoad,
20-
wait: AtomicsWait,
21-
waitAsync: AtomicsWaitAsync,
22-
},
2321
SharedArrayBuffer,
2422
} = globalThis;
2523

Collapse file

‎lib/internal/modules/esm/worker.js‎

Copy file name to clipboardExpand all lines: lib/internal/modules/esm/worker.js
+2-6Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,14 @@
11
'use strict';
22

33
const {
4+
AtomicsAdd,
5+
AtomicsNotify,
46
DataViewPrototypeGetBuffer,
57
Int32Array,
68
PromisePrototypeThen,
79
ReflectApply,
810
SafeSet,
911
TypedArrayPrototypeGetBuffer,
10-
globalThis: {
11-
Atomics: {
12-
add: AtomicsAdd,
13-
notify: AtomicsNotify,
14-
},
15-
},
1612
} = primordials;
1713
const assert = require('internal/assert');
1814
const { clearImmediate, setImmediate } = require('timers');
Collapse file

‎lib/internal/per_context/primordials.js‎

Copy file name to clipboardExpand all lines: lib/internal/per_context/primordials.js
+1Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,7 @@ function copyPrototype(src, dest, prefix) {
172172

173173
// Create copies of the namespace objects
174174
[
175+
'Atomics',
175176
'JSON',
176177
'Math',
177178
'Proxy',
Collapse file

‎lib/internal/worker.js‎

Copy file name to clipboardExpand all lines: lib/internal/worker.js
+4-4Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ const {
44
ArrayPrototypeForEach,
55
ArrayPrototypeMap,
66
ArrayPrototypePush,
7+
AtomicsAdd,
78
Float64Array,
89
FunctionPrototypeBind,
910
JSONStringify,
@@ -21,7 +22,7 @@ const {
2122
SymbolFor,
2223
TypedArrayPrototypeFill,
2324
Uint32Array,
24-
globalThis: { Atomics, SharedArrayBuffer },
25+
globalThis: { SharedArrayBuffer },
2526
} = primordials;
2627

2728
const EventEmitter = require('events');
@@ -101,12 +102,11 @@ let cwdCounter;
101102
const environmentData = new SafeMap();
102103

103104
// SharedArrayBuffers can be disabled with --no-harmony-sharedarraybuffer.
104-
// Atomics can be disabled with --no-harmony-atomics.
105-
if (isMainThread && SharedArrayBuffer !== undefined && Atomics !== undefined) {
105+
if (isMainThread && SharedArrayBuffer !== undefined) {
106106
cwdCounter = new Uint32Array(new SharedArrayBuffer(4));
107107
const originalChdir = process.chdir;
108108
process.chdir = function(path) {
109-
Atomics.add(cwdCounter, 0, 1);
109+
AtomicsAdd(cwdCounter, 0, 1);
110110
originalChdir(path);
111111
};
112112
}
Collapse file

‎test/parallel/test-worker-no-atomics.js‎

Copy file name to clipboardExpand all lines: test/parallel/test-worker-no-atomics.js
-21Lines changed: 0 additions & 21 deletions
This file was deleted.
Collapse file

‎test/parallel/test-worker-process-cwd.js‎

Copy file name to clipboardExpand all lines: test/parallel/test-worker-process-cwd.js
+3-3Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ if (!process.env.HAS_STARTED_WORKER) {
1616
// Normalize the current working dir to also work with the root folder.
1717
process.chdir(__dirname);
1818

19-
assert(!process.cwd.toString().includes('Atomics.load'));
19+
assert.doesNotMatch(process.cwd.toString(), /AtomicsLoad/);
2020

2121
// 1. Start the first worker.
2222
const w = new Worker(__filename);
@@ -32,7 +32,7 @@ if (!process.env.HAS_STARTED_WORKER) {
3232
// 2. Save the current cwd and verify that `process.cwd` includes the
3333
// Atomics.load call and spawn a new worker.
3434
const cwd = process.cwd();
35-
assert(process.cwd.toString().includes('Atomics.load'));
35+
assert.match(process.cwd.toString(), /AtomicsLoad/);
3636

3737
const w = new Worker(__filename);
3838
w.once('message', common.mustCall((message) => {
@@ -56,7 +56,7 @@ if (!process.env.HAS_STARTED_WORKER) {
5656
const cwd = process.cwd();
5757
// Send the current cwd to the parent.
5858
parentPort.postMessage(cwd);
59-
assert(process.cwd.toString().includes('Atomics.load'));
59+
assert.match(process.cwd.toString(), /AtomicsLoad/);
6060

6161
parentPort.once('message', common.mustCall((message) => {
6262
// 7. Verify that the current cwd is identical to the received one but

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.