| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent fdff838 commit 219d2e9
5 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -11,9 +11,6 @@ const { | |||
| 11 | 11 | ObjectDefineProperty, | |
| 12 | 12 | PromisePrototypeThen, | |
| 13 | 13 | RegExpPrototypeExec, | |
| 14 | - globalThis: { | ||
| 15 | - SharedArrayBuffer, | ||
| 16 | - }, | ||
| 17 | 14 | } = primordials; | |
| 18 | 15 | ||
| 19 | 16 | const { | |
@@ -119,23 +116,21 @@ port.on('message', (message) => { | |||
| 119 | 116 | require('internal/worker').assignEnvironmentData(environmentData); | |
| 120 | 117 | setupMainThreadPort(mainThreadPort); | |
| 121 | 118 | ||
| 122 | - if (SharedArrayBuffer !== undefined) { | ||
| 123 | - // The counter is only passed to the workers created by the main thread, | ||
| 124 | - // not to workers created by other workers. | ||
| 125 | - let cachedCwd = ''; | ||
| 126 | - let lastCounter = -1; | ||
| 127 | - const originalCwd = process.cwd; | ||
| 128 | - | ||
| 129 | - process.cwd = function() { | ||
| 130 | - const currentCounter = AtomicsLoad(cwdCounter, 0); | ||
| 131 | - if (currentCounter === lastCounter) | ||
| 132 | - return cachedCwd; | ||
| 133 | - lastCounter = currentCounter; | ||
| 134 | - cachedCwd = originalCwd(); | ||
| 119 | + // The counter is only passed to the workers created by the main thread, | ||
| 120 | + // not to workers created by other workers. | ||
| 121 | + let cachedCwd = ''; | ||
| 122 | + let lastCounter = -1; | ||
| 123 | + const originalCwd = process.cwd; | ||
| 124 | + | ||
| 125 | + process.cwd = function() { | ||
| 126 | + const currentCounter = AtomicsLoad(cwdCounter, 0); | ||
| 127 | + if (currentCounter === lastCounter) | ||
| 135 | 128 | return cachedCwd; | |
| 136 | - }; | ||
| 137 | - workerIo.sharedCwdCounter = cwdCounter; | ||
| 138 | - } | ||
| 129 | + lastCounter = currentCounter; | ||
| 130 | + cachedCwd = originalCwd(); | ||
| 131 | + return cachedCwd; | ||
| 132 | + }; | ||
| 133 | + workerIo.sharedCwdCounter = cwdCounter; | ||
| 139 | 134 | ||
| 140 | 135 | const isLoaderHookWorker = (filename === 'internal/modules/esm/worker' && doEval === 'internal'); | |
| 141 | 136 | if (!isLoaderHookWorker) { | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -15,13 +15,8 @@ const { | |||
| 15 | 15 | SafeSet, | |
| 16 | 16 | StringPrototypeSlice, | |
| 17 | 17 | StringPrototypeToUpperCase, | |
| 18 | - globalThis, | ||
| 19 | 18 | } = primordials; | |
| 20 | 19 | ||
| 21 | - const { | ||
| 22 | - SharedArrayBuffer, | ||
| 23 | - } = globalThis; | ||
| 24 | - | ||
| 25 | 20 | const { | |
| 26 | 21 | ERR_ASYNC_LOADER_REQUEST_NEVER_SETTLED, | |
| 27 | 22 | ERR_INTERNAL_ASSERTION, | |
@@ -44,6 +39,7 @@ const { | |||
| 44 | 39 | validateString, | |
| 45 | 40 | } = require('internal/validators'); | |
| 46 | 41 | const { | |
| 42 | + constructSharedArrayBuffer, | ||
| 47 | 43 | kEmptyObject, | |
| 48 | 44 | } = require('internal/util'); | |
| 49 | 45 | ||
@@ -535,7 +531,7 @@ class AsyncLoaderHookWorker { | |||
| 535 | 531 | const { InternalWorker } = require('internal/worker'); | |
| 536 | 532 | MessageChannel ??= require('internal/worker/io').MessageChannel; | |
| 537 | 533 | ||
| 538 | - const lock = new SharedArrayBuffer(SHARED_MEMORY_BYTE_LENGTH); | ||
| 534 | + const lock = constructSharedArrayBuffer(SHARED_MEMORY_BYTE_LENGTH); | ||
| 539 | 535 | this.#lock = new Int32Array(lock); | |
| 540 | 536 | ||
| 541 | 537 | this.#worker = new InternalWorker('internal/modules/esm/worker', { | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -9,13 +9,14 @@ const { | |||
| 9 | 9 | AtomicsWait, | |
| 10 | 10 | Int32Array, | |
| 11 | 11 | MathMax, | |
| 12 | + Number, | ||
| 12 | 13 | SymbolDispose, | |
| 13 | - globalThis: { | ||
| 14 | - Number, | ||
| 15 | - SharedArrayBuffer, | ||
| 16 | - }, | ||
| 17 | 14 | } = primordials; | |
| 18 | 15 | ||
| 16 | + const { | ||
| 17 | + constructSharedArrayBuffer, | ||
| 18 | + } = require('internal/util'); | ||
| 19 | + | ||
| 19 | 20 | const { | |
| 20 | 21 | Buffer, | |
| 21 | 22 | } = require('buffer'); | |
@@ -49,7 +50,7 @@ const { | |||
| 49 | 50 | const BUSY_WRITE_TIMEOUT = 100; | |
| 50 | 51 | const kEmptyBuffer = Buffer.allocUnsafe(0); | |
| 51 | 52 | ||
| 52 | - const kNil = new Int32Array(new SharedArrayBuffer(4)); | ||
| 53 | + const kNil = new Int32Array(constructSharedArrayBuffer(4)); | ||
| 53 | 54 | ||
| 54 | 55 | function sleep(ms) { | |
| 55 | 56 | // Also filters out NaN, non-number types, including empty strings, but allows bigints | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -24,7 +24,6 @@ const { | |||
| 24 | 24 | SymbolFor, | |
| 25 | 25 | TypedArrayPrototypeFill, | |
| 26 | 26 | Uint32Array, | |
| 27 | - globalThis: { SharedArrayBuffer }, | ||
| 28 | 27 | } = primordials; | |
| 29 | 28 | ||
| 30 | 29 | const EventEmitter = require('events'); | |
@@ -62,7 +61,10 @@ const { | |||
| 62 | 61 | const { createMainThreadPort, destroyMainThreadPort } = require('internal/worker/messaging'); | |
| 63 | 62 | const { deserializeError } = require('internal/error_serdes'); | |
| 64 | 63 | const { fileURLToPath, isURL, pathToFileURL } = require('internal/url'); | |
| 65 | - const { kEmptyObject } = require('internal/util'); | ||
| 64 | + const { | ||
| 65 | + constructSharedArrayBuffer, | ||
| 66 | + kEmptyObject, | ||
| 67 | + } = require('internal/util'); | ||
| 66 | 68 | const { validateArray, validateString, validateObject, validateNumber } = require('internal/validators'); | |
| 67 | 69 | const { | |
| 68 | 70 | throwIfBuildingSnapshot, | |
@@ -106,9 +108,8 @@ let cwdCounter; | |||
| 106 | 108 | ||
| 107 | 109 | const environmentData = new SafeMap(); | |
| 108 | 110 | ||
| 109 | - // SharedArrayBuffers can be disabled with --enable-sharedarraybuffer-per-context. | ||
| 110 | - if (isMainThread && SharedArrayBuffer !== undefined) { | ||
| 111 | - cwdCounter = new Uint32Array(new SharedArrayBuffer(4)); | ||
| 111 | + if (isMainThread) { | ||
| 112 | + cwdCounter = new Uint32Array(constructSharedArrayBuffer(4)); | ||
| 112 | 113 | const originalChdir = process.chdir; | |
| 113 | 114 | process.chdir = function(path) { | |
| 114 | 115 | AtomicsAdd(cwdCounter, 0, 1); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -6,18 +6,17 @@ const { | |||
| 6 | 6 | AtomicsWaitAsync, | |
| 7 | 7 | Int32Array, | |
| 8 | 8 | SafeMap, | |
| 9 | - globalThis, | ||
| 10 | 9 | } = primordials; | |
| 11 | 10 | ||
| 12 | - const { | ||
| 13 | - SharedArrayBuffer, | ||
| 14 | - } = globalThis; | ||
| 15 | - | ||
| 16 | 11 | const { | |
| 17 | 12 | isMainThread, | |
| 18 | 13 | threadId: currentThreadId, | |
| 19 | 14 | } = internalBinding('worker'); | |
| 20 | 15 | ||
| 16 | + const { | ||
| 17 | + constructSharedArrayBuffer, | ||
| 18 | + } = require('internal/util'); | ||
| 19 | + | ||
| 21 | 20 | const { | |
| 22 | 21 | codes: { | |
| 23 | 22 | ERR_WORKER_MESSAGING_ERRORED, | |
@@ -203,7 +202,7 @@ async function postMessageToThread(threadId, value, transferList, timeout) { | |||
| 203 | 202 | throw new ERR_WORKER_MESSAGING_SAME_THREAD(); | |
| 204 | 203 | } | |
| 205 | 204 | ||
| 206 | - const memory = new SharedArrayBuffer(WORKER_MESSAGING_SHARED_DATA); | ||
| 205 | + const memory = constructSharedArrayBuffer(WORKER_MESSAGING_SHARED_DATA); | ||
| 207 | 206 | const status = new Int32Array(memory); | |
| 208 | 207 | const promise = AtomicsWaitAsync(status, WORKER_MESSAGING_STATUS_INDEX, 0, timeout).value; | |
| 209 | 208 | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments