From ae9007626713f59841a8b24ffecddc93c20832ed Mon Sep 17 00:00:00 2001 From: Shelley Vohr Date: Wed, 14 Jan 2026 22:00:50 +0100 Subject: [PATCH] src: add internal binding for constructing SharedArrayBuffers https://github.com/nodejs/node/pull/60497 --- patches/node/.patches | 1 - ...n_electron_module_via_the_esm_loader.patch | 13 +---- ...buffer_existence_in_fast-utf8-stream.patch | 56 ------------------- 3 files changed, 3 insertions(+), 67 deletions(-) delete mode 100644 patches/node/lib_check_sharedarraybuffer_existence_in_fast-utf8-stream.patch diff --git a/patches/node/.patches b/patches/node/.patches index 8cdf9f618d..5417748572 100644 --- a/patches/node/.patches +++ b/patches/node/.patches @@ -36,7 +36,6 @@ fix_redefined_macos_sdk_header_symbols.patch fix_allow_disabling_fetch_in_renderer_and_worker_processes.patch feat_disable_js_source_phase_imports_by_default.patch fix_avoid_external_memory_leak_on_invalid_tls_protocol_versions.patch -lib_check_sharedarraybuffer_existence_in_fast-utf8-stream.patch api_delete_deprecated_fields_on_v8_isolate.patch api_promote_deprecation_of_v8_context_and_v8_object_api_methods.patch fix_ensure_traverseparent_bails_on_resource_path_exit.patch diff --git a/patches/node/fix_expose_the_built-in_electron_module_via_the_esm_loader.patch b/patches/node/fix_expose_the_built-in_electron_module_via_the_esm_loader.patch index 98a41c5446..2c60fb94ad 100644 --- a/patches/node/fix_expose_the_built-in_electron_module_via_the_esm_loader.patch +++ b/patches/node/fix_expose_the_built-in_electron_module_via_the_esm_loader.patch @@ -64,22 +64,15 @@ index c284163fba86ec820af1996571fbd3d092d41d34..5f1921d15bc1d3a68c35990f85e36a0e } } diff --git a/lib/internal/modules/esm/loader.js b/lib/internal/modules/esm/loader.js -index abfe88c272dcc4aa1e95948bf754f55e1df74ddf..d8e8e6ec291f9eab039e2d31a3566f645bdc0d9c 100644 +index abfe88c272dcc4aa1e95948bf754f55e1df74ddf..7a29cd391fdf050ebda50c5b2f263d27001ced74 100644 --- a/lib/internal/modules/esm/loader.js +++ b/lib/internal/modules/esm/loader.js -@@ -437,7 +437,15 @@ class ModuleLoader { +@@ -437,7 +437,7 @@ class ModuleLoader { assert(wrap instanceof ModuleWrap, `Translator used for require(${url}) should not be async`); const cjsModule = wrap[imported_cjs_symbol]; -+<<<<<<< HEAD +- if (cjsModule) { + if (cjsModule && translatorKey !== 'electron') { -+||||||| constructed fake ancestor - if (cjsModule) { -+ assert(translatorKey === 'commonjs-sync'); -+======= -+ if (cjsModule && translatorKey !== 'electron') { -+ assert(translatorKey === 'commonjs-sync'); -+>>>>>>> fix: expose the built-in electron module via the ESM loader // Check if the ESM initiating import CJS is being required by the same CJS module. if (cjsModule?.[kIsExecuting]) { const parentFilename = urlToFilename(parentURL); diff --git a/patches/node/lib_check_sharedarraybuffer_existence_in_fast-utf8-stream.patch b/patches/node/lib_check_sharedarraybuffer_existence_in_fast-utf8-stream.patch deleted file mode 100644 index 1b0925f115..0000000000 --- a/patches/node/lib_check_sharedarraybuffer_existence_in_fast-utf8-stream.patch +++ /dev/null @@ -1,56 +0,0 @@ -From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 -From: Shelley Vohr -Date: Sat, 25 Oct 2025 11:06:10 +0200 -Subject: lib: check SharedArrayBuffer existence in fast-utf8-stream - -After https://github.com/nodejs/node/pull/58897 calling -Object.entries on fs will lazy-load fast-utf8-stream, which uses -SharedArrayBuffer without checking for its existence first. It -won't exist in the renderer process and will throw -'SharedArrayBuffer is not a constructor'. Refactor to check -for SharedArrayBuffer first. - -This should be upstreamed to Node.js - -diff --git a/lib/internal/modules/esm/loader.js b/lib/internal/modules/esm/loader.js -index d8e8e6ec291f9eab039e2d31a3566f645bdc0d9c..7a29cd391fdf050ebda50c5b2f263d27001ced74 100644 ---- a/lib/internal/modules/esm/loader.js -+++ b/lib/internal/modules/esm/loader.js -@@ -437,15 +437,7 @@ class ModuleLoader { - assert(wrap instanceof ModuleWrap, `Translator used for require(${url}) should not be async`); - - const cjsModule = wrap[imported_cjs_symbol]; --<<<<<<< HEAD - if (cjsModule && translatorKey !== 'electron') { --||||||| constructed fake ancestor -- if (cjsModule) { -- assert(translatorKey === 'commonjs-sync'); --======= -- if (cjsModule && translatorKey !== 'electron') { -- assert(translatorKey === 'commonjs-sync'); -->>>>>>> fix: expose the built-in electron module via the ESM loader - // Check if the ESM initiating import CJS is being required by the same CJS module. - if (cjsModule?.[kIsExecuting]) { - const parentFilename = urlToFilename(parentURL); -diff --git a/lib/internal/streams/fast-utf8-stream.js b/lib/internal/streams/fast-utf8-stream.js -index 25f4771d052a2a2ef35eb910bfd75bd51bc891d9..3028d1a6538ec611d08566c565589c78dda1b6e1 100644 ---- a/lib/internal/streams/fast-utf8-stream.js -+++ b/lib/internal/streams/fast-utf8-stream.js -@@ -60,10 +60,14 @@ function sleep(ms) { - throw new ERR_INVALID_ARG_TYPE('ms', ['number', 'bigint'], ms); - } - throw new ERR_INVALID_ARG_VALUE.RangeError('ms', ms, -- 'must be a number greater than 0 and less than Infinity'); -+ 'must be a number greater than 0 and less than Infinity'); -+ } -+ if (haveSAB) { -+ AtomicsWait(kNil, 0, 0, Number(ms)); -+ } else { -+ const { sleep: _sleep } = internalBinding('util'); -+ _sleep(ms); - } -- -- AtomicsWait(kNil, 0, 0, Number(ms)); - } - - // 16 KB. Don't write more than docker buffer size.