Files
electron/patches/node/lib_check_sharedarraybuffer_existence_in_fast-utf8-stream.patch
2026-01-15 17:23:22 +01:00

57 lines
2.4 KiB
Diff

From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Shelley Vohr <shelley.vohr@gmail.com>
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.