From cb4adabb4a68a5b7a85bcbd04c8c620c4305964e Mon Sep 17 00:00:00 2001 From: Ruben Bridgewater Date: Mon, 29 Nov 2021 21:54:35 +0100 Subject: [PATCH] lib: do not crash using workers with disabled shared array buffers This allows the repl to function normally while using the `--no-harmony-sharedarraybuffer` V8 flag. Fixes: https://github.com/nodejs/node/issues/39717 Signed-off-by: Ruben Bridgewater --- lib/internal/bootstrap/switches/does_own_process_state.js | 2 +- lib/internal/worker.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/internal/bootstrap/switches/does_own_process_state.js b/lib/internal/bootstrap/switches/does_own_process_state.js index 2924e7f8cc17fa..b8def5c0272d9f 100644 --- a/lib/internal/bootstrap/switches/does_own_process_state.js +++ b/lib/internal/bootstrap/switches/does_own_process_state.js @@ -6,7 +6,7 @@ const rawMethods = internalBinding('process_methods'); process.abort = rawMethods.abort; process.umask = wrappedUmask; process.chdir = wrappedChdir; -process.cwd = wrappedCwd; +process.cwd = typeof SharedArrayBuffer === 'undefined' ? rawMethods.cwd : wrappedCwd; if (credentials.implementsPosixCredentials) { const wrapped = wrapPosixCredentialSetters(credentials); diff --git a/lib/internal/worker.js b/lib/internal/worker.js index 1d2cd8cefd2996..2c3dd26d03ea4a 100644 --- a/lib/internal/worker.js +++ b/lib/internal/worker.js @@ -90,7 +90,7 @@ let cwdCounter; const environmentData = new SafeMap(); -if (isMainThread) { +if (isMainThread && typeof SharedArrayBuffer !== 'undefined') { cwdCounter = new Uint32Array(new SharedArrayBuffer(4)); const originalChdir = process.chdir; process.chdir = function(path) {