| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent c6b2f56 commit 939c876
10 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -35,7 +35,7 @@ ${ArrayPrototypeJoin(ArrayPrototypeMap(imports, createImport), '\n')} | |||
| 35 | 35 | ${ArrayPrototypeJoin(ArrayPrototypeMap(exports, createExport), '\n')} | |
| 36 | 36 | import.meta.done(); | |
| 37 | 37 | `; | |
| 38 | - const { ModuleWrap, callbackMap } = internalBinding('module_wrap'); | ||
| 38 | + const { ModuleWrap } = internalBinding('module_wrap'); | ||
| 39 | 39 | const m = new ModuleWrap(`${url}`, undefined, source, 0, 0); | |
| 40 | 40 | ||
| 41 | 41 | const readyfns = new SafeSet(); | |
@@ -46,8 +46,8 @@ import.meta.done(); | |||
| 46 | 46 | ||
| 47 | 47 | if (imports.length) | |
| 48 | 48 | reflect.imports = ObjectCreate(null); | |
| 49 | - | ||
| 50 | - callbackMap.set(m, { | ||
| 49 | + const { setCallbackForWrap } = require('internal/modules/esm/utils'); | ||
| 50 | + setCallbackForWrap(m, { | ||
| 51 | 51 | initializeImportMeta: (meta, wrap) => { | |
| 52 | 52 | meta.exports = reflect.exports; | |
| 53 | 53 | if (reflect.imports) | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -47,9 +47,12 @@ function newModuleMap() { | |||
| 47 | 47 | ||
| 48 | 48 | const { | |
| 49 | 49 | defaultResolve, | |
| 50 | - DEFAULT_CONDITIONS, | ||
| 51 | 50 | } = require('internal/modules/esm/resolve'); | |
| 52 | 51 | ||
| 52 | + const { | ||
| 53 | + getDefaultConditions, | ||
| 54 | + } = require('internal/modules/esm/utils'); | ||
| 55 | + | ||
| 53 | 56 | function getTranslators() { | |
| 54 | 57 | const { translators } = require('internal/modules/esm/translators'); | |
| 55 | 58 | return translators; | |
@@ -375,9 +378,10 @@ class ESMLoader { | |||
| 375 | 378 | url = pathToFileURL(`${process.cwd()}/[eval${++this.evalIndex}]`).href, | |
| 376 | 379 | ) { | |
| 377 | 380 | const evalInstance = (url) => { | |
| 378 | - const { ModuleWrap, callbackMap } = internalBinding('module_wrap'); | ||
| 381 | + const { ModuleWrap } = internalBinding('module_wrap'); | ||
| 382 | + const { setCallbackForWrap } = require('internal/modules/esm/utils'); | ||
| 379 | 383 | const module = new ModuleWrap(url, undefined, source, 0, 0); | |
| 380 | - callbackMap.set(module, { | ||
| 384 | + setCallbackForWrap(module, { | ||
| 381 | 385 | importModuleDynamically: (specifier, { url }, importAssertions) => { | |
| 382 | 386 | return this.import(specifier, url, importAssertions); | |
| 383 | 387 | }, | |
@@ -802,7 +806,7 @@ class ESMLoader { | |||
| 802 | 806 | } | |
| 803 | 807 | const chain = this.#hooks.resolve; | |
| 804 | 808 | const context = { | |
| 805 | - conditions: DEFAULT_CONDITIONS, | ||
| 809 | + conditions: getDefaultConditions(), | ||
| 806 | 810 | importAssertions, | |
| 807 | 811 | parentURL, | |
| 808 | 812 | }; | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -6,7 +6,6 @@ const { | |||
| 6 | 6 | ArrayPrototypeShift, | |
| 7 | 7 | JSONParse, | |
| 8 | 8 | JSONStringify, | |
| 9 | - ObjectFreeze, | ||
| 10 | 9 | ObjectGetOwnPropertyNames, | |
| 11 | 10 | ObjectPrototypeHasOwnProperty, | |
| 12 | 11 | RegExp, | |
@@ -46,7 +45,6 @@ const typeFlag = getOptionValue('--input-type'); | |||
| 46 | 45 | const { URL, pathToFileURL, fileURLToPath } = require('internal/url'); | |
| 47 | 46 | const { | |
| 48 | 47 | ERR_INPUT_TYPE_NOT_ALLOWED, | |
| 49 | - ERR_INVALID_ARG_VALUE, | ||
| 50 | 48 | ERR_INVALID_MODULE_SPECIFIER, | |
| 51 | 49 | ERR_INVALID_PACKAGE_CONFIG, | |
| 52 | 50 | ERR_INVALID_PACKAGE_TARGET, | |
@@ -61,25 +59,13 @@ const { | |||
| 61 | 59 | const { Module: CJSModule } = require('internal/modules/cjs/loader'); | |
| 62 | 60 | const packageJsonReader = require('internal/modules/package_json_reader'); | |
| 63 | 61 | const { getPackageConfig, getPackageScopeConfig } = require('internal/modules/esm/package_config'); | |
| 62 | + const { getConditionsSet } = require('internal/modules/esm/utils'); | ||
| 64 | 63 | ||
| 65 | 64 | /** | |
| 66 | 65 | * @typedef {import('internal/modules/esm/package_config.js').PackageConfig} PackageConfig | |
| 67 | 66 | */ | |
| 68 | 67 | ||
| 69 | 68 | ||
| 70 | - const userConditions = getOptionValue('--conditions'); | ||
| 71 | - const noAddons = getOptionValue('--no-addons'); | ||
| 72 | - const addonConditions = noAddons ? [] : ['node-addons']; | ||
| 73 | - | ||
| 74 | - const DEFAULT_CONDITIONS = ObjectFreeze([ | ||
| 75 | - 'node', | ||
| 76 | - 'import', | ||
| 77 | - ...addonConditions, | ||
| 78 | - ...userConditions, | ||
| 79 | - ]); | ||
| 80 | - | ||
| 81 | - const DEFAULT_CONDITIONS_SET = new SafeSet(DEFAULT_CONDITIONS); | ||
| 82 | - | ||
| 83 | 69 | const emittedPackageWarnings = new SafeSet(); | |
| 84 | 70 | ||
| 85 | 71 | function emitTrailingSlashPatternDeprecation(match, pjsonUrl, base) { | |
@@ -150,21 +136,6 @@ function emitLegacyIndexDeprecation(url, packageJSONUrl, base, main) { | |||
| 150 | 136 | } | |
| 151 | 137 | } | |
| 152 | 138 | ||
| 153 | - /** | ||
| 154 | - * @param {string[]} [conditions] | ||
| 155 | - * @returns {Set<string>} | ||
| 156 | - */ | ||
| 157 | - function getConditionsSet(conditions) { | ||
| 158 | - if (conditions !== undefined && conditions !== DEFAULT_CONDITIONS) { | ||
| 159 | - if (!ArrayIsArray(conditions)) { | ||
| 160 | - throw new ERR_INVALID_ARG_VALUE('conditions', conditions, | ||
| 161 | - 'expected an array'); | ||
| 162 | - } | ||
| 163 | - return new SafeSet(conditions); | ||
| 164 | - } | ||
| 165 | - return DEFAULT_CONDITIONS_SET; | ||
| 166 | - } | ||
| 167 | - | ||
| 168 | 139 | const realpathCache = new SafeMap(); | |
| 169 | 140 | ||
| 170 | 141 | /** | |
@@ -1167,7 +1138,6 @@ async function defaultResolve(specifier, context = {}) { | |||
| 1167 | 1138 | } | |
| 1168 | 1139 | ||
| 1169 | 1140 | module.exports = { | |
| 1170 | - DEFAULT_CONDITIONS, | ||
| 1171 | 1141 | defaultResolve, | |
| 1172 | 1142 | encodedSepRegEx, | |
| 1173 | 1143 | getPackageScopeConfig, | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -115,7 +115,8 @@ translators.set('module', async function moduleStrategy(url, source, isMain) { | |||
| 115 | 115 | maybeCacheSourceMap(url, source); | |
| 116 | 116 | debug(`Translating StandardModule ${url}`); | |
| 117 | 117 | const module = new ModuleWrap(url, undefined, source, 0, 0); | |
| 118 | - moduleWrap.callbackMap.set(module, { | ||
| 118 | + const { setCallbackForWrap } = require('internal/modules/esm/utils'); | ||
| 119 | + setCallbackForWrap(module, { | ||
| 119 | 120 | initializeImportMeta: (meta, wrap) => this.importMetaInitialize(meta, { url }), | |
| 120 | 121 | importModuleDynamically, | |
| 121 | 122 | }); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -5,40 +5,11 @@ const { | |||
| 5 | 5 | ObjectCreate, | |
| 6 | 6 | } = primordials; | |
| 7 | 7 | ||
| 8 | - const { | ||
| 9 | - ERR_VM_DYNAMIC_IMPORT_CALLBACK_MISSING, | ||
| 10 | - } = require('internal/errors').codes; | ||
| 11 | 8 | const { ESMLoader } = require('internal/modules/esm/loader'); | |
| 12 | 9 | const { | |
| 13 | 10 | hasUncaughtExceptionCaptureCallback, | |
| 14 | 11 | } = require('internal/process/execution'); | |
| 15 | 12 | const { pathToFileURL } = require('internal/url'); | |
| 16 | - const { | ||
| 17 | - getModuleFromWrap, | ||
| 18 | - } = require('internal/vm/module'); | ||
| 19 | - | ||
| 20 | - exports.initializeImportMetaObject = function(wrap, meta) { | ||
| 21 | - const { callbackMap } = internalBinding('module_wrap'); | ||
| 22 | - if (callbackMap.has(wrap)) { | ||
| 23 | - const { initializeImportMeta } = callbackMap.get(wrap); | ||
| 24 | - if (initializeImportMeta !== undefined) { | ||
| 25 | - initializeImportMeta(meta, getModuleFromWrap(wrap) || wrap); | ||
| 26 | - } | ||
| 27 | - } | ||
| 28 | - }; | ||
| 29 | - | ||
| 30 | - exports.importModuleDynamicallyCallback = | ||
| 31 | - async function importModuleDynamicallyCallback(wrap, specifier, assertions) { | ||
| 32 | - const { callbackMap } = internalBinding('module_wrap'); | ||
| 33 | - if (callbackMap.has(wrap)) { | ||
| 34 | - const { importModuleDynamically } = callbackMap.get(wrap); | ||
| 35 | - if (importModuleDynamically !== undefined) { | ||
| 36 | - return importModuleDynamically( | ||
| 37 | - specifier, getModuleFromWrap(wrap) || wrap, assertions); | ||
| 38 | - } | ||
| 39 | - } | ||
| 40 | - throw new ERR_VM_DYNAMIC_IMPORT_CALLBACK_MISSING(); | ||
| 41 | - }; | ||
| 42 | 13 | ||
| 43 | 14 | const esmLoader = new ESMLoader(); | |
| 44 | 15 | exports.esmLoader = esmLoader; | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -5,7 +5,6 @@ const { | |||
| 5 | 5 | ObjectDefineProperties, | |
| 6 | 6 | ObjectDefineProperty, | |
| 7 | 7 | SafeMap, | |
| 8 | - SafeWeakMap, | ||
| 9 | 8 | StringPrototypeStartsWith, | |
| 10 | 9 | Symbol, | |
| 11 | 10 | SymbolDispose, | |
@@ -551,20 +550,10 @@ function initializeCJSLoader() { | |||
| 551 | 550 | } | |
| 552 | 551 | ||
| 553 | 552 | function initializeESMLoader() { | |
| 554 | - // Create this WeakMap in js-land because V8 has no C++ API for WeakMap. | ||
| 555 | - internalBinding('module_wrap').callbackMap = new SafeWeakMap(); | ||
| 556 | - | ||
| 557 | 553 | if (getEmbedderOptions().shouldNotRegisterESMLoader) return; | |
| 558 | 554 | ||
| 559 | - const { | ||
| 560 | - setImportModuleDynamicallyCallback, | ||
| 561 | - setInitializeImportMetaObjectCallback, | ||
| 562 | - } = internalBinding('module_wrap'); | ||
| 563 | - const esm = require('internal/process/esm_loader'); | ||
| 564 | - // Setup per-isolate callbacks that locate data or callbacks that we keep | ||
| 565 | - // track of for different ESM modules. | ||
| 566 | - setInitializeImportMetaObjectCallback(esm.initializeImportMetaObject); | ||
| 567 | - setImportModuleDynamicallyCallback(esm.importModuleDynamicallyCallback); | ||
| 555 | + const { initializeESM } = require('internal/modules/esm/utils'); | ||
| 556 | + initializeESM(); | ||
| 568 | 557 | ||
| 569 | 558 | // Patch the vm module when --experimental-vm-modules is on. | |
| 570 | 559 | // Please update the comments in vm.js when this block changes. | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -97,12 +97,11 @@ function internalCompileFunction(code, params, options) { | |||
| 97 | 97 | if (importModuleDynamically !== undefined) { | |
| 98 | 98 | validateFunction(importModuleDynamically, | |
| 99 | 99 | 'options.importModuleDynamically'); | |
| 100 | - const { importModuleDynamicallyWrap } = | ||
| 101 | - require('internal/vm/module'); | ||
| 102 | - const { callbackMap } = internalBinding('module_wrap'); | ||
| 100 | + const { importModuleDynamicallyWrap } = require('internal/vm/module'); | ||
| 103 | 101 | const wrapped = importModuleDynamicallyWrap(importModuleDynamically); | |
| 104 | 102 | const func = result.function; | |
| 105 | - callbackMap.set(result.cacheKey, { | ||
| 103 | + const { setCallbackForWrap } = require('internal/modules/esm/utils'); | ||
| 104 | + setCallbackForWrap(result.cacheKey, { | ||
| 106 | 105 | importModuleDynamically: (s, _k, i) => wrapped(s, func, i), | |
| 107 | 106 | }); | |
| 108 | 107 | } | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -125,8 +125,8 @@ class Module { | |||
| 125 | 125 | this[kWrap] = new ModuleWrap(identifier, context, sourceText, | |
| 126 | 126 | options.lineOffset, options.columnOffset, | |
| 127 | 127 | options.cachedData); | |
| 128 | - | ||
| 129 | - binding.callbackMap.set(this[kWrap], { | ||
| 128 | + const { setCallbackForWrap } = require('internal/modules/esm/utils'); | ||
| 129 | + setCallbackForWrap(this[kWrap], { | ||
| 130 | 130 | initializeImportMeta: options.initializeImportMeta, | |
| 131 | 131 | importModuleDynamically: options.importModuleDynamically ? | |
| 132 | 132 | importModuleDynamicallyWrap(options.importModuleDynamically) : | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -105,10 +105,9 @@ class Script extends ContextifyScript { | |||
| 105 | 105 | if (importModuleDynamically !== undefined) { | |
| 106 | 106 | validateFunction(importModuleDynamically, | |
| 107 | 107 | 'options.importModuleDynamically'); | |
| 108 | - const { importModuleDynamicallyWrap } = | ||
| 109 | - require('internal/vm/module'); | ||
| 110 | - const { callbackMap } = internalBinding('module_wrap'); | ||
| 111 | - callbackMap.set(this, { | ||
| 108 | + const { importModuleDynamicallyWrap } = require('internal/vm/module'); | ||
| 109 | + const { setCallbackForWrap } = require('internal/modules/esm/utils'); | ||
| 110 | + setCallbackForWrap(this, { | ||
| 112 | 111 | importModuleDynamically: | |
| 113 | 112 | importModuleDynamicallyWrap(importModuleDynamically), | |
| 114 | 113 | }); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -63,6 +63,7 @@ const expectedModules = new Set([ | |||
| 63 | 63 | 'NativeModule internal/modules/esm/package_config', | |
| 64 | 64 | 'NativeModule internal/modules/esm/resolve', | |
| 65 | 65 | 'NativeModule internal/modules/esm/translators', | |
| 66 | + 'NativeModule internal/modules/esm/utils', | ||
| 66 | 67 | 'NativeModule internal/modules/package_json_reader', | |
| 67 | 68 | 'NativeModule internal/modules/run_main', | |
| 68 | 69 | 'NativeModule internal/net', | |
| Back | FazBrowse Home | New Git URL |
0 commit comments