Skip to content

Commit 60aed92

Browse files
committed
repl: fix crash when SharedArrayBuffer disabled
1 parent 602fe4e commit 60aed92

File tree

3 files changed

+10
-2
lines changed

3 files changed

+10
-2
lines changed

benchmark/worker/atomics-wait.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@ const bench = common.createBenchmark(main, {
77
});
88

99
function main({ n }) {
10+
if (typeof SharedArrayBuffer === 'undefined') {
11+
throw new Error('SharedArrayBuffers must be enabled to run this benchmark');
12+
}
13+
1014
const i32arr = new Int32Array(new SharedArrayBuffer(4));
1115
bench.start();
1216
for (let i = 0; i < n; i++)

lib/internal/main/worker_thread.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ const {
99
ArrayPrototypeSplice,
1010
ObjectDefineProperty,
1111
PromisePrototypeCatch,
12-
globalThis: { Atomics },
12+
globalThis: { Atomics, SharedArrayBuffer },
1313
} = primordials;
1414

1515
const {
@@ -142,6 +142,9 @@ port.on('message', (message) => {
142142
const originalCwd = process.cwd;
143143

144144
process.cwd = function() {
145+
// SharedArrayBuffers can be disabled with --no-harmony-sharedarraybuffer.
146+
if (typeof SharedArrayBuffer === 'undefined') return originalCwd();
147+
145148
const currentCounter = Atomics.load(cwdCounter, 0);
146149
if (currentCounter === lastCounter)
147150
return cachedCwd;

lib/internal/worker.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,8 @@ let cwdCounter;
9292

9393
const environmentData = new SafeMap();
9494

95-
if (isMainThread) {
95+
// SharedArrayBuffers can be disabled with --no-harmony-sharedarraybuffer.
96+
if (isMainThread && typeof SharedArrayBuffer !== 'undefined') {
9697
cwdCounter = new Uint32Array(new SharedArrayBuffer(4));
9798
const originalChdir = process.chdir;
9899
process.chdir = function(path) {

0 commit comments

Comments
 (0)