Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 34.2k
Move ESM loaders off-thread#44710
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Uh oh!
There was an error while loading. Please reload this page.
Move ESM loaders off-thread #44710
Changes from all commits
03f6bb4a0bb205cd16ccd01f11915f02297820aa55231b964ed412d54776a6d2aed49a78a28895746d17c1afb3d666ee108198a132d39e13dd6a5d31415d6ea374bd198b55127be92f3382753a2b3e6a5c73001fb4cccd4b272d310ec518a11c14710dd5114d15b425b796c02599a61642d485e8e3e0c676e23d875fe62b350351ff3b2ed97e79b2fc0142d65d7e3b4685590c49a4088d40834d47bd0bf17ff5242065222b0cc21f29d019f8706cbd04ebc5c8aae17eb74dcaa3312b1c7e8be7c7b7e5be3f4c9bf140c03b020b9d768992039d392ef1c7dd71acfa8d91821301b1dcccc0cfc6837fd6fa1a3982ee47b4d83d518e53531c9a33bcf18cb071a890911d150b1c22b88686f51b1583e3f4934a800d151a5a798bf9371ae0b798090cfec42281e9433e31a1c595a95f10bf7b8106b400cc9373aa67af11aab57d7638b497e340d24018ab1880cd74c817d0e80590df4cee03fa258cf8a8863cb913f3d8d473136212717f761ad2a5fa29a70159ca6fb4a8a2f6177afaa85288dbe8090ef6679bc722fd0e544bf8988f90426d8bfc631e7d5d372065e244f916bc8e970f44a246221f2e29436c97ad73db695052c6acc0900f02012fFile filter
Filter by extension
Conversations
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Uh oh!
There was an error while loading. Please reload this page.
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -10,6 +10,7 @@ const{ | ||
| ObjectDefineProperty, | ||
| PromisePrototypeThen, | ||
| RegExpPrototypeExec, | ||
| SafeWeakMap, | ||
| globalThis:{ | ||
| Atomics, | ||
| SharedArrayBuffer, | ||
| @@ -89,23 +90,25 @@ port.on('message', (message) =>{ | ||
| const{ | ||
| argv, | ||
| cwdCounter, | ||
| filename, | ||
| doEval, | ||
| workerData, | ||
| environmentData, | ||
| publicPort, | ||
| filename, | ||
| hasStdin, | ||
| manifestSrc, | ||
| manifestURL, | ||
| hasStdin, | ||
| publicPort, | ||
| workerData, | ||
| } = message; | ||
| if (argv !== undefined){ | ||
| ArrayPrototypePushApply(process.argv, argv); | ||
| } | ||
| if (doEval !== 'internal'){ | ||
| if (argv !== undefined){ | ||
| ArrayPrototypePushApply(process.argv, argv); | ||
| } | ||
| const publicWorker = require('worker_threads'); | ||
| publicWorker.parentPort = publicPort; | ||
| publicWorker.workerData = workerData; | ||
| const publicWorker = require('worker_threads'); | ||
| publicWorker.parentPort = publicPort; | ||
| publicWorker.workerData = workerData; | ||
| } | ||
| require('internal/worker').assignEnvironmentData(environmentData); | ||
| @@ -138,31 +141,47 @@ port.on('message', (message) =>{ | ||
| debug(`[${threadId}] starts worker script ${filename} ` + | ||
| `(eval = ${doEval}) at cwd = ${process.cwd()}`); | ||
| port.postMessage({type: UP_AND_RUNNING }); | ||
| if (doEval === 'classic'){ | ||
| const{evalScript } = require('internal/process/execution'); | ||
| const name = '[worker eval]' | ||
| // This is necessary for CJS module compilation. | ||
| // TODO: pass this with something really internal. | ||
| ObjectDefineProperty(process, '_eval',{ | ||
| __proto__: null, | ||
| configurable: true, | ||
| enumerable: true, | ||
| value: filename, | ||
| }); | ||
| ArrayPrototypeSplice(process.argv, 1, 0, name); | ||
| evalScript(name, filename); | ||
| } else if (doEval === 'module'){ | ||
| const{evalModule } = require('internal/process/execution'); | ||
| PromisePrototypeThen(evalModule(filename), undefined, (e) =>{ | ||
| workerOnGlobalUncaughtException(e, true); | ||
| }); | ||
| } else{ | ||
| // script filename | ||
| // runMain here might be monkey-patched by users in --require. | ||
| // XXX: the monkey-patchability here should probably be deprecated. | ||
| ArrayPrototypeSplice(process.argv, 1, 0, filename); | ||
| const CJSLoader = require('internal/modules/cjs/loader'); | ||
| CJSLoader.Module.runMain(filename); | ||
| switch (doEval){ | ||
MemberAuthor There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: it would be great to somehow directly connect these values to where they ultimately come from ( MemberAuthor There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit (maybe out of scope): these cases are mutually exclusive with no fall-through. I think it might be cleaner and easier to grok as a map instead of a switch (where one might forget to constevaluators={classic(filename){…},default(filename){…},internal(filename){require(filename;},module(filename){…},};evaluators[doEval??'default'](filename); | ||
| case 'internal':{ | ||
| // Create this WeakMap in js-land because V8 has no C++ API for WeakMap. | ||
| internalBinding('module_wrap').callbackMap = new SafeWeakMap(); | ||
| require(filename)(workerData, publicPort); | ||
| break; | ||
| } | ||
| case 'classic':{ | ||
| const{evalScript } = require('internal/process/execution'); | ||
| const name = '[worker eval]' | ||
| // This is necessary for CJS module compilation. | ||
| // TODO: pass this with something really internal. | ||
| ObjectDefineProperty(process, '_eval',{ | ||
| __proto__: null, | ||
| configurable: true, | ||
| enumerable: true, | ||
| value: filename, | ||
| }); | ||
| ArrayPrototypeSplice(process.argv, 1, 0, name); | ||
| evalScript(name, filename); | ||
| break; | ||
| } | ||
| case 'module':{ | ||
| const{evalModule } = require('internal/process/execution'); | ||
| PromisePrototypeThen(evalModule(filename), undefined, (e) =>{ | ||
| workerOnGlobalUncaughtException(e, true); | ||
| }); | ||
| break; | ||
| } | ||
| default:{ | ||
| // script filename | ||
| // runMain here might be monkey-patched by users in --require. | ||
| // XXX: the monkey-patchability here should probably be deprecated. | ||
| ArrayPrototypeSplice(process.argv, 1, 0, filename); | ||
| const CJSLoader = require('internal/modules/cjs/loader'); | ||
| CJSLoader.Module.runMain(filename); | ||
| break; | ||
| } | ||
| } | ||
| } else if (message.type === STDIO_PAYLOAD){ | ||
| const{stream, chunks } = message; | ||
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.