| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent fdf5028 commit 011e6e0
5 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1692,6 +1692,9 @@ E('ERR_PARSE_ARGS_UNKNOWN_OPTION', (option, allowPositionals) => { | |||
| 1692 | 1692 | E('ERR_PERFORMANCE_INVALID_TIMESTAMP', | |
| 1693 | 1693 | '%d is not a valid timestamp', TypeError); | |
| 1694 | 1694 | E('ERR_PERFORMANCE_MEASURE_INVALID_OPTIONS', '%s', TypeError); | |
| 1695 | + E('ERR_REQUIRE_ASYNC_MODULE', 'require() cannot be used on an ESM ' + | ||
| 1696 | + 'graph with top-level await. Use import() instead. To see where the' + | ||
| 1697 | + ' top-level await comes from, use --experimental-print-required-tla.', Error); | ||
| 1695 | 1698 | E('ERR_REQUIRE_CYCLE_MODULE', '%s', Error); | |
| 1696 | 1699 | E('ERR_REQUIRE_ESM', | |
| 1697 | 1700 | function(filename, hasEsmSyntax, parentPath = null, packageJsonPath = null) { | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -22,6 +22,7 @@ const { imported_cjs_symbol } = internalBinding('symbols'); | |||
| 22 | 22 | ||
| 23 | 23 | const assert = require('internal/assert'); | |
| 24 | 24 | const { | |
| 25 | + ERR_REQUIRE_ASYNC_MODULE, | ||
| 25 | 26 | ERR_REQUIRE_CYCLE_MODULE, | |
| 26 | 27 | ERR_REQUIRE_ESM, | |
| 27 | 28 | ERR_NETWORK_IMPORT_DISALLOWED, | |
@@ -293,6 +294,9 @@ class ModuleLoader { | |||
| 293 | 294 | // evaluated at this point. | |
| 294 | 295 | if (job !== undefined) { | |
| 295 | 296 | mod[kRequiredModuleSymbol] = job.module; | |
| 297 | + if (job.module.async) { | ||
| 298 | + throw new ERR_REQUIRE_ASYNC_MODULE(); | ||
| 299 | + } | ||
| 296 | 300 | if (job.module.getStatus() !== kEvaluated) { | |
| 297 | 301 | const parentFilename = urlToFilename(parent?.filename); | |
| 298 | 302 | let message = `Cannot require() ES Module ${filename} in a cycle.`; | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -32,8 +32,11 @@ const resolvedPromise = PromiseResolve(); | |||
| 32 | 32 | const { | |
| 33 | 33 | setHasStartedUserESMExecution, | |
| 34 | 34 | } = require('internal/modules/helpers'); | |
| 35 | + const { getOptionValue } = require('internal/options'); | ||
| 35 | 36 | const noop = FunctionPrototype; | |
| 36 | - | ||
| 37 | + const { | ||
| 38 | + ERR_REQUIRE_ASYNC_MODULE, | ||
| 39 | + } = require('internal/errors').codes; | ||
| 37 | 40 | let hasPausedEntry = false; | |
| 38 | 41 | ||
| 39 | 42 | const CJSGlobalLike = [ | |
@@ -370,7 +373,16 @@ class ModuleJobSync extends ModuleJobBase { | |||
| 370 | 373 | ||
| 371 | 374 | runSync() { | |
| 372 | 375 | // TODO(joyeecheung): add the error decoration logic from the async instantiate. | |
| 373 | - this.module.instantiateSync(); | ||
| 376 | + this.module.async = this.module.instantiateSync(); | ||
| 377 | + // If --experimental-print-required-tla is true, proceeds to evaluation even | ||
| 378 | + // if it's async because we want to search for the TLA and help users locate | ||
| 379 | + // them. | ||
| 380 | + // TODO(joyeecheung): track the asynchroniticy using v8::Module::HasTopLevelAwait() | ||
| 381 | + // and we'll be able to throw right after compilation of the modules, using acron | ||
| 382 | + // to find and print the TLA. | ||
| 383 | + if (this.module.async && !getOptionValue('--experimental-print-required-tla')) { | ||
| 384 | + throw new ERR_REQUIRE_ASYNC_MODULE(); | ||
| 385 | + } | ||
| 374 | 386 | setHasStartedUserESMExecution(); | |
| 375 | 387 | const namespace = this.module.evaluateSync(); | |
| 376 | 388 | return { __proto__: null, module: this.module, namespace }; | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -31,7 +31,6 @@ using v8::FunctionTemplate; | |||
| 31 | 31 | using v8::HandleScope; | |
| 32 | 32 | using v8::Int32; | |
| 33 | 33 | using v8::Integer; | |
| 34 | - using v8::IntegrityLevel; | ||
| 35 | 34 | using v8::Isolate; | |
| 36 | 35 | using v8::Local; | |
| 37 | 36 | using v8::MaybeLocal; | |
@@ -290,7 +289,6 @@ void ModuleWrap::New(const FunctionCallbackInfo<Value>& args) { | |||
| 290 | 289 | ||
| 291 | 290 | obj->contextify_context_ = contextify_context; | |
| 292 | 291 | ||
| 293 | - that->SetIntegrityLevel(context, IntegrityLevel::kFrozen); | ||
| 294 | 292 | args.GetReturnValue().Set(that); | |
| 295 | 293 | } | |
| 296 | 294 | ||
@@ -581,13 +579,9 @@ void ModuleWrap::InstantiateSync(const FunctionCallbackInfo<Value>& args) { | |||
| 581 | 579 | } | |
| 582 | 580 | } | |
| 583 | 581 | ||
| 584 | - // If --experimental-print-required-tla is true, proceeds to evaluation even | ||
| 585 | - // if it's async because we want to search for the TLA and help users locate | ||
| 586 | - // them. | ||
| 587 | - if (module->IsGraphAsync() && !env->options()->print_required_tla) { | ||
| 588 | - THROW_ERR_REQUIRE_ASYNC_MODULE(env); | ||
| 589 | - return; | ||
| 590 | - } | ||
| 582 | + // TODO(joyeecheung): record Module::HasTopLevelAwait() in every ModuleWrap | ||
| 583 | + // and infer the asynchronicity from a module's children during linking. | ||
| 584 | + args.GetReturnValue().Set(module->IsGraphAsync()); | ||
| 591 | 585 | } | |
| 592 | 586 | ||
| 593 | 587 | void ModuleWrap::EvaluateSync(const FunctionCallbackInfo<Value>& args) { | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,16 @@ | |||
| 1 | + // This tests that after failing to require an ESM that contains TLA, | ||
| 2 | + // retrying with require() still throws, and produces consistent results. | ||
| 3 | + 'use strict'; | ||
| 4 | + require('../common'); | ||
| 5 | + const assert = require('assert'); | ||
| 6 | + | ||
| 7 | + assert.throws(() => { | ||
| 8 | + require('../fixtures/es-modules/tla/resolved.mjs'); | ||
| 9 | + }, { | ||
| 10 | + code: 'ERR_REQUIRE_ASYNC_MODULE' | ||
| 11 | + }); | ||
| 12 | + assert.throws(() => { | ||
| 13 | + require('../fixtures/es-modules/tla/resolved.mjs'); | ||
| 14 | + }, { | ||
| 15 | + code: 'ERR_REQUIRE_ASYNC_MODULE' | ||
| 16 | + }); | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments