| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 7639259 commit 6679e6b
4 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -76,7 +76,6 @@ module.exports = { | |||
| 76 | 76 | initializeCJS, | |
| 77 | 77 | Module, | |
| 78 | 78 | wrapSafe, | |
| 79 | - get hasLoadedAnyUserCJSModule() { return hasLoadedAnyUserCJSModule; }, | ||
| 80 | 79 | }; | |
| 81 | 80 | ||
| 82 | 81 | const { BuiltinModule } = require('internal/bootstrap/realm'); | |
@@ -113,6 +112,7 @@ const { | |||
| 113 | 112 | initializeCjsConditions, | |
| 114 | 113 | loadBuiltinModule, | |
| 115 | 114 | makeRequireFunction, | |
| 115 | + setHasStartedUserCJSExecution, | ||
| 116 | 116 | stripBOM, | |
| 117 | 117 | toRealPath, | |
| 118 | 118 | } = require('internal/modules/helpers'); | |
@@ -127,9 +127,6 @@ const permission = require('internal/process/permission'); | |||
| 127 | 127 | const { | |
| 128 | 128 | vm_dynamic_import_default_internal, | |
| 129 | 129 | } = internalBinding('symbols'); | |
| 130 | - // Whether any user-provided CJS modules had been loaded (executed). | ||
| 131 | - // Used for internal assertions. | ||
| 132 | - let hasLoadedAnyUserCJSModule = false; | ||
| 133 | 130 | ||
| 134 | 131 | const { | |
| 135 | 132 | codes: { | |
@@ -1364,14 +1361,14 @@ Module.prototype._compile = function(content, filename) { | |||
| 1364 | 1361 | const thisValue = exports; | |
| 1365 | 1362 | const module = this; | |
| 1366 | 1363 | if (requireDepth === 0) { statCache = new SafeMap(); } | |
| 1364 | + setHasStartedUserCJSExecution(); | ||
| 1367 | 1365 | if (inspectorWrapper) { | |
| 1368 | 1366 | result = inspectorWrapper(compiledWrapper, thisValue, exports, | |
| 1369 | 1367 | require, module, filename, dirname); | |
| 1370 | 1368 | } else { | |
| 1371 | 1369 | result = ReflectApply(compiledWrapper, thisValue, | |
| 1372 | 1370 | [exports, require, module, filename, dirname]); | |
| 1373 | 1371 | } | |
| 1374 | - hasLoadedAnyUserCJSModule = true; | ||
| 1375 | 1372 | if (requireDepth === 0) { statCache = null; } | |
| 1376 | 1373 | return result; | |
| 1377 | 1374 | }; | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -27,7 +27,9 @@ const { | |||
| 27 | 27 | } = require('internal/source_map/source_map_cache'); | |
| 28 | 28 | const assert = require('internal/assert'); | |
| 29 | 29 | const resolvedPromise = PromiseResolve(); | |
| 30 | - | ||
| 30 | + const { | ||
| 31 | + setHasStartedUserESMExecution, | ||
| 32 | + } = require('internal/modules/helpers'); | ||
| 31 | 33 | const noop = FunctionPrototype; | |
| 32 | 34 | ||
| 33 | 35 | let hasPausedEntry = false; | |
@@ -206,6 +208,7 @@ class ModuleJob { | |||
| 206 | 208 | this.instantiated = PromiseResolve(); | |
| 207 | 209 | const timeout = -1; | |
| 208 | 210 | const breakOnSigint = false; | |
| 211 | + setHasStartedUserESMExecution(); | ||
| 209 | 212 | this.module.evaluate(timeout, breakOnSigint); | |
| 210 | 213 | return { __proto__: null, module: this.module }; | |
| 211 | 214 | } | |
@@ -214,6 +217,7 @@ class ModuleJob { | |||
| 214 | 217 | await this.instantiate(); | |
| 215 | 218 | const timeout = -1; | |
| 216 | 219 | const breakOnSigint = false; | |
| 220 | + setHasStartedUserESMExecution(); | ||
| 217 | 221 | try { | |
| 218 | 222 | await this.module.evaluate(timeout, breakOnSigint); | |
| 219 | 223 | } catch (e) { | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -319,6 +319,19 @@ function normalizeReferrerURL(referrerName) { | |||
| 319 | 319 | assert.fail('Unreachable code reached by ' + inspect(referrerName)); | |
| 320 | 320 | } | |
| 321 | 321 | ||
| 322 | + | ||
| 323 | + // Whether we have started executing any user-provided CJS code. | ||
| 324 | + // This is set right before we call the wrapped CJS code (not after, | ||
| 325 | + // in case we are half-way in the execution when internals check this). | ||
| 326 | + // Used for internal assertions. | ||
| 327 | + let _hasStartedUserCJSExecution = false; | ||
| 328 | + // Similar to _hasStartedUserCJSExecution but for ESM. This is set | ||
| 329 | + // right before ESM evaluation in the default ESM loader. We do not | ||
| 330 | + // update this during vm SourceTextModule execution because at that point | ||
| 331 | + // some user code must already have been run to execute code via vm | ||
| 332 | + // there is little value checking whether any user JS code is run anyway. | ||
| 333 | + let _hasStartedUserESMExecution = false; | ||
| 334 | + | ||
| 322 | 335 | module.exports = { | |
| 323 | 336 | addBuiltinLibsToObject, | |
| 324 | 337 | getCjsConditions, | |
@@ -328,4 +341,16 @@ module.exports = { | |||
| 328 | 341 | normalizeReferrerURL, | |
| 329 | 342 | stripBOM, | |
| 330 | 343 | toRealPath, | |
| 344 | + hasStartedUserCJSExecution() { | ||
| 345 | + return _hasStartedUserCJSExecution; | ||
| 346 | + }, | ||
| 347 | + setHasStartedUserCJSExecution() { | ||
| 348 | + _hasStartedUserCJSExecution = true; | ||
| 349 | + }, | ||
| 350 | + hasStartedUserESMExecution() { | ||
| 351 | + return _hasStartedUserESMExecution; | ||
| 352 | + }, | ||
| 353 | + setHasStartedUserESMExecution() { | ||
| 354 | + _hasStartedUserESMExecution = true; | ||
| 355 | + }, | ||
| 331 | 356 | }; | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -190,8 +190,12 @@ function setupSymbolDisposePolyfill() { | |||
| 190 | 190 | function setupUserModules(forceDefaultLoader = false) { | |
| 191 | 191 | initializeCJSLoader(); | |
| 192 | 192 | initializeESMLoader(forceDefaultLoader); | |
| 193 | - const CJSLoader = require('internal/modules/cjs/loader'); | ||
| 194 | - assert(!CJSLoader.hasLoadedAnyUserCJSModule); | ||
| 193 | + const { | ||
| 194 | + hasStartedUserCJSExecution, | ||
| 195 | + hasStartedUserESMExecution, | ||
| 196 | + } = require('internal/modules/helpers'); | ||
| 197 | + assert(!hasStartedUserCJSExecution()); | ||
| 198 | + assert(!hasStartedUserESMExecution()); | ||
| 195 | 199 | // Do not enable preload modules if custom loaders are disabled. | |
| 196 | 200 | // For example, loader workers are responsible for doing this themselves. | |
| 197 | 201 | // And preload modules are not supported in ShadowRealm as well. | |
| Back | FazBrowse Home | New Git URL |
0 commit comments