electron/patches/node/repl_fix_crash_when_sharedarraybuffer_disabled.patch

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

64 lines
2.5 KiB
Diff
Raw Normal View History

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
chore: bump node to v16.17.0 (main) (#35350) * chore: bump node in DEPS to v16.17.0 * chore: fixup asar patch * lib: use null-prototype objects for property descriptors https://github.com/nodejs/node/pull/43270 * src: make SecureContext fields private https://github.com/nodejs/node/pull/43173 * crypto: remove Node.js-specific webcrypto extensions https://github.com/nodejs/node/pull/43310 * test: refactor to top-level await https://github.com/nodejs/node/pull/43500 * deps: cherry-pick two libuv fixes https://github.com/nodejs/node/pull/43950 * src: slim down env-inl.h https://github.com/nodejs/node/pull/43745 * util: add AggregateError.prototype.errors to inspect output https://github.com/nodejs/node/pull/43646 * esm: improve performance & tidy tests https://github.com/nodejs/node/pull/43784 * src: NodeArrayBufferAllocator delegates to v8's allocator https://github.com/nodejs/node/pull/43594 * chore: update patch indices * chore: update filenames * src: refactor IsSupportedAuthenticatedMode https://github.com/nodejs/node/pull/42368 * src: add --openssl-legacy-provider option https://github.com/nodejs/node/pull/40478 * lib,src: add source map support for global eval https://github.com/nodejs/node/pull/43428 * trace_events: trace net connect event https://github.com/nodejs/node/pull/43903 * deps: update ICU to 71.1 https://github.com/nodejs/node/pull/42655 This fails the test because it's missing https://chromium-review.googlesource.com/c/chromium/deps/icu/+/3841093 * lib: give names to promisified exists() and question() https://github.com/nodejs/node/pull/43218 * crypto: add CFRG curves to Web Crypto API https://github.com/nodejs/node/pull/42507 * src: fix memory leak for v8.serialize https://github.com/nodejs/node/pull/42695 This test does not work for Electron as they do not use V8's ArrayBufferAllocator. * buffer: fix atob input validation https://github.com/nodejs/node/pull/42539 * src: fix ssize_t error from nghttp2.h https://github.com/nodejs/node/pull/44393 Co-authored-by: electron-roller[bot] <84116207+electron-roller[bot]@users.noreply.github.com> Co-authored-by: Shelley Vohr <shelley.vohr@gmail.com>
2022-08-29 13:55:36 +00:00
index e21c1b1fe2cc7f55d3782419913568f51f1a87ea..1b6a8242bbd9eeb901950f1b9016bc2b85af5951 100644
--- a/lib/internal/main/worker_thread.js
+++ b/lib/internal/main/worker_thread.js
@@ -9,7 +9,7 @@ const {
ArrayPrototypeSplice,
ObjectDefineProperty,
PromisePrototypeCatch,
- globalThis: { Atomics },
+ globalThis: { Atomics, SharedArrayBuffer },
} = primordials;
const {
chore: bump node to v16.17.0 (main) (#35350) * chore: bump node in DEPS to v16.17.0 * chore: fixup asar patch * lib: use null-prototype objects for property descriptors https://github.com/nodejs/node/pull/43270 * src: make SecureContext fields private https://github.com/nodejs/node/pull/43173 * crypto: remove Node.js-specific webcrypto extensions https://github.com/nodejs/node/pull/43310 * test: refactor to top-level await https://github.com/nodejs/node/pull/43500 * deps: cherry-pick two libuv fixes https://github.com/nodejs/node/pull/43950 * src: slim down env-inl.h https://github.com/nodejs/node/pull/43745 * util: add AggregateError.prototype.errors to inspect output https://github.com/nodejs/node/pull/43646 * esm: improve performance & tidy tests https://github.com/nodejs/node/pull/43784 * src: NodeArrayBufferAllocator delegates to v8's allocator https://github.com/nodejs/node/pull/43594 * chore: update patch indices * chore: update filenames * src: refactor IsSupportedAuthenticatedMode https://github.com/nodejs/node/pull/42368 * src: add --openssl-legacy-provider option https://github.com/nodejs/node/pull/40478 * lib,src: add source map support for global eval https://github.com/nodejs/node/pull/43428 * trace_events: trace net connect event https://github.com/nodejs/node/pull/43903 * deps: update ICU to 71.1 https://github.com/nodejs/node/pull/42655 This fails the test because it's missing https://chromium-review.googlesource.com/c/chromium/deps/icu/+/3841093 * lib: give names to promisified exists() and question() https://github.com/nodejs/node/pull/43218 * crypto: add CFRG curves to Web Crypto API https://github.com/nodejs/node/pull/42507 * src: fix memory leak for v8.serialize https://github.com/nodejs/node/pull/42695 This test does not work for Electron as they do not use V8's ArrayBufferAllocator. * buffer: fix atob input validation https://github.com/nodejs/node/pull/42539 * src: fix ssize_t error from nghttp2.h https://github.com/nodejs/node/pull/44393 Co-authored-by: electron-roller[bot] <84116207+electron-roller[bot]@users.noreply.github.com> Co-authored-by: Shelley Vohr <shelley.vohr@gmail.com>
2022-08-29 13:55:36 +00:00
@@ -150,6 +150,9 @@ port.on('message', (message) => {
const originalCwd = process.cwd;
process.cwd = function() {
+ // SharedArrayBuffers can be disabled with --no-harmony-sharedarraybuffer.
+ if (typeof SharedArrayBuffer === 'undefined') return originalCwd();
+
const currentCounter = Atomics.load(cwdCounter, 0);
if (currentCounter === lastCounter)
return cachedCwd;
diff --git a/lib/internal/worker.js b/lib/internal/worker.js
chore: bump node to v16.17.0 (main) (#35350) * chore: bump node in DEPS to v16.17.0 * chore: fixup asar patch * lib: use null-prototype objects for property descriptors https://github.com/nodejs/node/pull/43270 * src: make SecureContext fields private https://github.com/nodejs/node/pull/43173 * crypto: remove Node.js-specific webcrypto extensions https://github.com/nodejs/node/pull/43310 * test: refactor to top-level await https://github.com/nodejs/node/pull/43500 * deps: cherry-pick two libuv fixes https://github.com/nodejs/node/pull/43950 * src: slim down env-inl.h https://github.com/nodejs/node/pull/43745 * util: add AggregateError.prototype.errors to inspect output https://github.com/nodejs/node/pull/43646 * esm: improve performance & tidy tests https://github.com/nodejs/node/pull/43784 * src: NodeArrayBufferAllocator delegates to v8's allocator https://github.com/nodejs/node/pull/43594 * chore: update patch indices * chore: update filenames * src: refactor IsSupportedAuthenticatedMode https://github.com/nodejs/node/pull/42368 * src: add --openssl-legacy-provider option https://github.com/nodejs/node/pull/40478 * lib,src: add source map support for global eval https://github.com/nodejs/node/pull/43428 * trace_events: trace net connect event https://github.com/nodejs/node/pull/43903 * deps: update ICU to 71.1 https://github.com/nodejs/node/pull/42655 This fails the test because it's missing https://chromium-review.googlesource.com/c/chromium/deps/icu/+/3841093 * lib: give names to promisified exists() and question() https://github.com/nodejs/node/pull/43218 * crypto: add CFRG curves to Web Crypto API https://github.com/nodejs/node/pull/42507 * src: fix memory leak for v8.serialize https://github.com/nodejs/node/pull/42695 This test does not work for Electron as they do not use V8's ArrayBufferAllocator. * buffer: fix atob input validation https://github.com/nodejs/node/pull/42539 * src: fix ssize_t error from nghttp2.h https://github.com/nodejs/node/pull/44393 Co-authored-by: electron-roller[bot] <84116207+electron-roller[bot]@users.noreply.github.com> Co-authored-by: Shelley Vohr <shelley.vohr@gmail.com>
2022-08-29 13:55:36 +00:00
index 8e396195209b83dff572792a78ee75d12d1f6610..4bb09b6ab5c31206a622814cbcd793c434b885d4 100644
--- a/lib/internal/worker.js
+++ b/lib/internal/worker.js
chore: bump node to v16.17.0 (main) (#35350) * chore: bump node in DEPS to v16.17.0 * chore: fixup asar patch * lib: use null-prototype objects for property descriptors https://github.com/nodejs/node/pull/43270 * src: make SecureContext fields private https://github.com/nodejs/node/pull/43173 * crypto: remove Node.js-specific webcrypto extensions https://github.com/nodejs/node/pull/43310 * test: refactor to top-level await https://github.com/nodejs/node/pull/43500 * deps: cherry-pick two libuv fixes https://github.com/nodejs/node/pull/43950 * src: slim down env-inl.h https://github.com/nodejs/node/pull/43745 * util: add AggregateError.prototype.errors to inspect output https://github.com/nodejs/node/pull/43646 * esm: improve performance & tidy tests https://github.com/nodejs/node/pull/43784 * src: NodeArrayBufferAllocator delegates to v8's allocator https://github.com/nodejs/node/pull/43594 * chore: update patch indices * chore: update filenames * src: refactor IsSupportedAuthenticatedMode https://github.com/nodejs/node/pull/42368 * src: add --openssl-legacy-provider option https://github.com/nodejs/node/pull/40478 * lib,src: add source map support for global eval https://github.com/nodejs/node/pull/43428 * trace_events: trace net connect event https://github.com/nodejs/node/pull/43903 * deps: update ICU to 71.1 https://github.com/nodejs/node/pull/42655 This fails the test because it's missing https://chromium-review.googlesource.com/c/chromium/deps/icu/+/3841093 * lib: give names to promisified exists() and question() https://github.com/nodejs/node/pull/43218 * crypto: add CFRG curves to Web Crypto API https://github.com/nodejs/node/pull/42507 * src: fix memory leak for v8.serialize https://github.com/nodejs/node/pull/42695 This test does not work for Electron as they do not use V8's ArrayBufferAllocator. * buffer: fix atob input validation https://github.com/nodejs/node/pull/42539 * src: fix ssize_t error from nghttp2.h https://github.com/nodejs/node/pull/44393 Co-authored-by: electron-roller[bot] <84116207+electron-roller[bot]@users.noreply.github.com> Co-authored-by: Shelley Vohr <shelley.vohr@gmail.com>
2022-08-29 13:55:36 +00:00
@@ -91,7 +91,8 @@ let cwdCounter;
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) {