| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 8ac05cf commit d8da197
4 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -291,10 +291,11 @@ rawMethods.resetStdioForTesting = function() { | |||
| 291 | 291 | require('fs'); | |
| 292 | 292 | require('util'); | |
| 293 | 293 | require('url'); // eslint-disable-line no-restricted-modules | |
| 294 | - | ||
| 294 | + internalBinding('module_wrap'); | ||
| 295 | 295 | require('internal/modules/cjs/loader'); | |
| 296 | 296 | require('internal/modules/esm/utils'); | |
| 297 | 297 | require('internal/vm/module'); | |
| 298 | + | ||
| 298 | 299 | // Needed to refresh the time origin. | |
| 299 | 300 | require('internal/perf/utils'); | |
| 300 | 301 | // Needed to register the async hooks. | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -65,12 +65,19 @@ const { | |||
| 65 | 65 | ||
| 66 | 66 | // Map used to store CJS parsing data. | |
| 67 | 67 | const cjsParseCache = new SafeWeakMap(); | |
| 68 | + /** | ||
| 69 | + * Map of already-loaded CJS modules to use. | ||
| 70 | + */ | ||
| 71 | + const cjsExportsCache = new SafeWeakMap(); | ||
| 68 | 72 | ||
| 69 | 73 | // Set first due to cycle with ESM loader functions. | |
| 70 | 74 | module.exports = { | |
| 71 | - wrapSafe, Module, cjsParseCache, | ||
| 72 | - get hasLoadedAnyUserCJSModule() { return hasLoadedAnyUserCJSModule; }, | ||
| 75 | + cjsExportsCache, | ||
| 76 | + cjsParseCache, | ||
| 73 | 77 | initializeCJS, | |
| 78 | + Module, | ||
| 79 | + wrapSafe, | ||
| 80 | + get hasLoadedAnyUserCJSModule() { return hasLoadedAnyUserCJSModule; }, | ||
| 74 | 81 | }; | |
| 75 | 82 | ||
| 76 | 83 | const { BuiltinModule } = require('internal/bootstrap/realm'); | |
@@ -150,7 +157,6 @@ const { | |||
| 150 | 157 | isProxy, | |
| 151 | 158 | } = require('internal/util/types'); | |
| 152 | 159 | ||
| 153 | - const { kEvaluated } = internalBinding('module_wrap'); | ||
| 154 | 160 | const isWindows = process.platform === 'win32'; | |
| 155 | 161 | ||
| 156 | 162 | const relativeResolveCache = { __proto__: null }; | |
@@ -1207,14 +1213,11 @@ Module.prototype.load = function(filename) { | |||
| 1207 | 1213 | Module._extensions[extension](this, filename); | |
| 1208 | 1214 | this.loaded = true; | |
| 1209 | 1215 | ||
| 1210 | - const cascadedLoader = getCascadedLoader(); | ||
| 1211 | 1216 | // Create module entry at load time to snapshot exports correctly | |
| 1212 | 1217 | const exports = this.exports; | |
| 1213 | - // Preemptively cache | ||
| 1214 | - if ((module?.module === undefined || | ||
| 1215 | - module.module.getStatus() < kEvaluated) && | ||
| 1216 | - !cascadedLoader.cjsCache.has(this)) { | ||
| 1217 | - cascadedLoader.cjsCache.set(this, exports); | ||
| 1218 | + // Preemptively cache for ESM loader. | ||
| 1219 | + if (!cjsExportsCache.has(this)) { | ||
| 1220 | + cjsExportsCache.set(this, exports); | ||
| 1218 | 1221 | } | |
| 1219 | 1222 | }; | |
| 1220 | 1223 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -11,7 +11,6 @@ const { | |||
| 11 | 11 | JSONStringify, | |
| 12 | 12 | ObjectSetPrototypeOf, | |
| 13 | 13 | RegExpPrototypeSymbolReplace, | |
| 14 | - SafeWeakMap, | ||
| 15 | 14 | encodeURIComponent, | |
| 16 | 15 | hardenRegExp, | |
| 17 | 16 | } = primordials; | |
@@ -86,11 +85,6 @@ class ModuleLoader { | |||
| 86 | 85 | */ | |
| 87 | 86 | #defaultConditions = getDefaultConditions(); | |
| 88 | 87 | ||
| 89 | - /** | ||
| 90 | - * Map of already-loaded CJS modules to use | ||
| 91 | - */ | ||
| 92 | - cjsCache = new SafeWeakMap(); | ||
| 93 | - | ||
| 94 | 88 | /** | |
| 95 | 89 | * The index for assigning unique URLs to anonymous module evaluation | |
| 96 | 90 | */ | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -42,6 +42,7 @@ const { | |||
| 42 | 42 | const { | |
| 43 | 43 | Module: CJSModule, | |
| 44 | 44 | cjsParseCache, | |
| 45 | + cjsExportsCache, | ||
| 45 | 46 | } = require('internal/modules/cjs/loader'); | |
| 46 | 47 | const { fileURLToPath, pathToFileURL, URL } = require('internal/url'); | |
| 47 | 48 | let debug = require('internal/util/debuglog').debuglog('esm', (fn) => { | |
@@ -308,9 +309,9 @@ function createCJSModuleWrap(url, source, isMain, loadCJS = loadCJSModule) { | |||
| 308 | 309 | } | |
| 309 | 310 | ||
| 310 | 311 | let exports; | |
| 311 | - if (asyncESM.esmLoader.cjsCache.has(module)) { | ||
| 312 | - exports = asyncESM.esmLoader.cjsCache.get(module); | ||
| 313 | - asyncESM.esmLoader.cjsCache.delete(module); | ||
| 312 | + if (cjsExportsCache.has(module)) { | ||
| 313 | + exports = cjsExportsCache.get(module); | ||
| 314 | + cjsExportsCache.delete(module); | ||
| 314 | 315 | } else { | |
| 315 | 316 | ({ exports } = module); | |
| 316 | 317 | } | |
| Back | FazBrowse Home | New Git URL |
0 commit comments