-
Notifications
You must be signed in to change notification settings - Fork 15k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
repl: fix crash when SharedArrayBuffer disabled
- Loading branch information
1 parent
66c458a
commit 51d65a8
Showing
2 changed files
with
40 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
39 changes: 39 additions & 0 deletions
39
patches/node/repl_fix_crash_when_sharedarraybuffer_disabled.patch
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
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..1ec99b89b53b48339ca0daa62b2e591e3f3d2913 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 in order 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/worker.js b/lib/internal/worker.js | ||
index 931bce0c518fc3355a9f94a7760556b6f0b75b96..7d756f6c3f769a3a5976fcde594c072c69e997f1 100644 | ||
--- a/lib/internal/worker.js | ||
+++ b/lib/internal/worker.js | ||
@@ -92,7 +92,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) { |