2021-08-11 00:42:15 +00:00
|
|
|
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
|
|
|
From: Shelley Vohr <shelley.vohr@gmail.com>
|
|
|
|
Date: Mon, 9 Aug 2021 18:42:15 +0200
|
|
|
|
Subject: repl: fix crash when SharedArrayBuffer disabled
|
|
|
|
|
|
|
|
It's possible for SharedArrayBuffers to be disabled with
|
|
|
|
--no-harmony-sharedarraybuffer so we first need to check that this
|
|
|
|
isn't the case before attempting to use them in the repl or a crash occurs.
|
|
|
|
|
|
|
|
Upstreamed at https://github.com/nodejs/node/pull/39718.
|
|
|
|
|
|
|
|
diff --git a/benchmark/worker/atomics-wait.js b/benchmark/worker/atomics-wait.js
|
|
|
|
index a771b1813731edf4f0dd60f3505799e389f1d876..b9461677e2d7d1df192e752496e62cca837717b5 100644
|
|
|
|
--- a/benchmark/worker/atomics-wait.js
|
|
|
|
+++ b/benchmark/worker/atomics-wait.js
|
|
|
|
@@ -7,6 +7,10 @@ const bench = common.createBenchmark(main, {
|
|
|
|
});
|
|
|
|
|
|
|
|
function main({ n }) {
|
|
|
|
+ if (typeof SharedArrayBuffer === 'undefined') {
|
|
|
|
+ throw new Error('SharedArrayBuffers must be enabled to run this benchmark');
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
const i32arr = new Int32Array(new SharedArrayBuffer(4));
|
|
|
|
bench.start();
|
|
|
|
for (let i = 0; i < n; i++)
|
|
|
|
diff --git a/lib/internal/main/worker_thread.js b/lib/internal/main/worker_thread.js
|
2023-01-11 10:33:48 +00:00
|
|
|
index fe2e132af1166a05c3e94cdae362dd46f62bf65b..caa9214fa30a715a5eea00e7fc3b091e40c07131 100644
|
2021-08-11 00:42:15 +00:00
|
|
|
--- a/lib/internal/main/worker_thread.js
|
|
|
|
+++ b/lib/internal/main/worker_thread.js
|
2022-11-10 21:31:20 +00:00
|
|
|
@@ -10,7 +10,7 @@ const {
|
2021-08-11 00:42:15 +00:00
|
|
|
ObjectDefineProperty,
|
2022-11-10 21:31:20 +00:00
|
|
|
PromisePrototypeThen,
|
|
|
|
RegExpPrototypeExec,
|
2021-08-11 00:42:15 +00:00
|
|
|
- globalThis: { Atomics },
|
|
|
|
+ globalThis: { Atomics, SharedArrayBuffer },
|
|
|
|
} = primordials;
|
|
|
|
|
|
|
|
const {
|
2023-01-11 10:33:48 +00:00
|
|
|
@@ -113,6 +113,8 @@ port.on('message', (message) => {
|
2021-08-11 00:42:15 +00:00
|
|
|
|
|
|
|
process.cwd = function() {
|
2022-11-10 21:31:20 +00:00
|
|
|
const currentCounter = Atomics.load(cwdCounter, 0);
|
2021-08-11 00:42:15 +00:00
|
|
|
+ // SharedArrayBuffers can be disabled with --no-harmony-sharedarraybuffer.
|
|
|
|
+ if (typeof SharedArrayBuffer === 'undefined') return originalCwd();
|
|
|
|
if (currentCounter === lastCounter)
|
|
|
|
return cachedCwd;
|
2022-11-10 21:31:20 +00:00
|
|
|
lastCounter = currentCounter;
|
2021-08-11 00:42:15 +00:00
|
|
|
diff --git a/lib/internal/worker.js b/lib/internal/worker.js
|
2022-08-29 13:55:36 +00:00
|
|
|
index 8e396195209b83dff572792a78ee75d12d1f6610..4bb09b6ab5c31206a622814cbcd793c434b885d4 100644
|
2021-08-11 00:42:15 +00:00
|
|
|
--- a/lib/internal/worker.js
|
|
|
|
+++ b/lib/internal/worker.js
|
2022-08-29 13:55:36 +00:00
|
|
|
@@ -91,7 +91,8 @@ let cwdCounter;
|
2021-08-11 00:42:15 +00:00
|
|
|
|
|
|
|
const environmentData = new SafeMap();
|
|
|
|
|
|
|
|
-if (isMainThread) {
|
|
|
|
+// SharedArrayBuffers can be disabled with --no-harmony-sharedarraybuffer.
|
|
|
|
+if (isMainThread && typeof SharedArrayBuffer !== 'undefined') {
|
|
|
|
cwdCounter = new Uint32Array(new SharedArrayBuffer(4));
|
|
|
|
const originalChdir = process.chdir;
|
|
|
|
process.chdir = function(path) {
|