From b3a1c6d13cfad8b0519dd7957c2f2db10acf98e8 Mon Sep 17 00:00:00 2001 From: Shelley Vohr Date: Thu, 5 Oct 2023 10:46:53 +0200 Subject: [PATCH] fix: error using `webcrypto.subtle.importKey()` (#40070) fix: error using webcrypto.subtle.importKey() --- patches/node/.patches | 1 + ..._possible_disabled_sharedarraybuffer.patch | 37 +++++++++++++++++++ 2 files changed, 38 insertions(+) create mode 100644 patches/node/fix_handle_possible_disabled_sharedarraybuffer.patch diff --git a/patches/node/.patches b/patches/node/.patches index d3ce9997ee78..48691cc53987 100644 --- a/patches/node/.patches +++ b/patches/node/.patches @@ -51,3 +51,4 @@ net_use_asserts_in_js_socket_stream_to_catch_races_in_future.patch lib_fix_broadcastchannel_initialization_location.patch src_adapt_to_v8_exception_api_change.patch lib_test_do_not_hardcode_buffer_kmaxlength.patch +fix_handle_possible_disabled_sharedarraybuffer.patch diff --git a/patches/node/fix_handle_possible_disabled_sharedarraybuffer.patch b/patches/node/fix_handle_possible_disabled_sharedarraybuffer.patch new file mode 100644 index 000000000000..6fee546d651d --- /dev/null +++ b/patches/node/fix_handle_possible_disabled_sharedarraybuffer.patch @@ -0,0 +1,37 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Shelley Vohr +Date: Mon, 2 Oct 2023 16:03:43 +0200 +Subject: fix: handle possible disabled SharedArrayBuffer + +It's possible for SharedArrayBuffer to be disabled with the -no-harmony-sharedarraybuffer +flag, and so we should guard uses with a check for potential undefined-ness. + +This should be upstreamed to Node.js. + +diff --git a/lib/internal/crypto/webidl.js b/lib/internal/crypto/webidl.js +index 9f5340c223902c5ff61def05e8a4f470b4f328e8..d6dbfa482f9ebff3f99fb810e072cf9a03d1cd4d 100644 +--- a/lib/internal/crypto/webidl.js ++++ b/lib/internal/crypto/webidl.js +@@ -183,7 +183,10 @@ function isNonSharedArrayBuffer(V) { + return ObjectPrototypeIsPrototypeOf(ArrayBufferPrototype, V); + } + ++// SharedArrayBuffers can be disabled with --no-harmony-sharedarraybuffer. + function isSharedArrayBuffer(V) { ++ if (SharedArrayBuffer === undefined) ++ return false; + return ObjectPrototypeIsPrototypeOf(SharedArrayBuffer.prototype, V); + } + +diff --git a/lib/internal/main/worker_thread.js b/lib/internal/main/worker_thread.js +index be4d82086199855a10108528b3dacc663b839454..10c33bacc0529e12f52aaf1baf6d42489b2a75a7 100644 +--- a/lib/internal/main/worker_thread.js ++++ b/lib/internal/main/worker_thread.js +@@ -108,6 +108,7 @@ port.on('message', (message) => { + + require('internal/worker').assignEnvironmentData(environmentData); + ++ // SharedArrayBuffers can be disabled with --no-harmony-sharedarraybuffer. + if (SharedArrayBuffer !== undefined) { + // The counter is only passed to the workers created by the main thread, + // not to workers created by other workers.