| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 88d1ca8 commit 15cbd39
5 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -387,7 +387,7 @@ class ModuleLoader { | |||
| 387 | 387 | if (!job.module) { | |
| 388 | 388 | assert.fail(getRaceMessage(filename, parentFilename)); | |
| 389 | 389 | } | |
| 390 | - if (job.module.async) { | ||
| 390 | + if (job.module.hasAsyncGraph) { | ||
| 391 | 391 | throw new ERR_REQUIRE_ASYNC_MODULE(filename, parentFilename); | |
| 392 | 392 | } | |
| 393 | 393 | const status = job.module.getStatus(); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -327,13 +327,13 @@ class ModuleJob extends ModuleJobBase { | |||
| 327 | 327 | // FIXME(joyeecheung): this cannot fully handle < kInstantiated. Make the linking | |
| 328 | 328 | // fully synchronous instead. | |
| 329 | 329 | if (status === kUninstantiated) { | |
| 330 | - this.module.async = this.module.instantiateSync(); | ||
| 330 | + this.module.hasAsyncGraph = this.module.instantiateSync(); | ||
| 331 | 331 | status = this.module.getStatus(); | |
| 332 | 332 | } | |
| 333 | 333 | if (status === kInstantiated || status === kErrored) { | |
| 334 | 334 | const filename = urlToFilename(this.url); | |
| 335 | 335 | const parentFilename = urlToFilename(parent?.filename); | |
| 336 | - this.module.async ??= this.module.isGraphAsync(); | ||
| 336 | + this.module.hasAsyncGraph ??= this.module.isGraphAsync(); | ||
| 337 | 337 | ||
| 338 | 338 | if (this.module.async && !getOptionValue('--experimental-print-required-tla')) { | |
| 339 | 339 | throw new ERR_REQUIRE_ASYNC_MODULE(filename, parentFilename); | |
@@ -370,7 +370,7 @@ class ModuleJob extends ModuleJobBase { | |||
| 370 | 370 | try { | |
| 371 | 371 | await this.module.evaluate(timeout, breakOnSigint); | |
| 372 | 372 | } catch (e) { | |
| 373 | - explainCommonJSGlobalLikeNotDefinedError(e, this.module.url, this.module.hasTopLevelAwait()); | ||
| 373 | + explainCommonJSGlobalLikeNotDefinedError(e, this.module.url, this.module.hasTopLevelAwait); | ||
| 374 | 374 | throw e; | |
| 375 | 375 | } | |
| 376 | 376 | return { __proto__: null, module: this.module }; | |
@@ -490,24 +490,25 @@ class ModuleJobSync extends ModuleJobBase { | |||
| 490 | 490 | debug('ModuleJobSync.runSync()', this.module); | |
| 491 | 491 | assert(this.phase === kEvaluationPhase); | |
| 492 | 492 | // TODO(joyeecheung): add the error decoration logic from the async instantiate. | |
| 493 | - this.module.async = this.module.instantiateSync(); | ||
| 493 | + this.module.hasAsyncGraph = this.module.instantiateSync(); | ||
| 494 | 494 | // If --experimental-print-required-tla is true, proceeds to evaluation even | |
| 495 | 495 | // if it's async because we want to search for the TLA and help users locate | |
| 496 | 496 | // them. | |
| 497 | 497 | // TODO(joyeecheung): track the asynchroniticy using v8::Module::HasTopLevelAwait() | |
| 498 | 498 | // and we'll be able to throw right after compilation of the modules, using acron | |
| 499 | - // to find and print the TLA. | ||
| 499 | + // to find and print the TLA. This requires the linking to be synchronous in case | ||
| 500 | + // it runs into cached asynchronous modules that are not yet fetched. | ||
| 500 | 501 | const parentFilename = urlToFilename(parent?.filename); | |
| 501 | 502 | const filename = urlToFilename(this.url); | |
| 502 | - if (this.module.async && !getOptionValue('--experimental-print-required-tla')) { | ||
| 503 | + if (this.module.hasAsyncGraph && !getOptionValue('--experimental-print-required-tla')) { | ||
| 503 | 504 | throw new ERR_REQUIRE_ASYNC_MODULE(filename, parentFilename); | |
| 504 | 505 | } | |
| 505 | 506 | setHasStartedUserESMExecution(); | |
| 506 | 507 | try { | |
| 507 | 508 | const namespace = this.module.evaluateSync(filename, parentFilename); | |
| 508 | 509 | return { __proto__: null, module: this.module, namespace }; | |
| 509 | 510 | } catch (e) { | |
| 510 | - explainCommonJSGlobalLikeNotDefinedError(e, this.module.url, this.module.hasTopLevelAwait()); | ||
| 511 | + explainCommonJSGlobalLikeNotDefinedError(e, this.module.url, this.module.hasTopLevelAwait); | ||
| 511 | 512 | throw e; | |
| 512 | 513 | } | |
| 513 | 514 | } | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -208,6 +208,7 @@ | |||
| 208 | 208 | V(gid_string, "gid") \ | |
| 209 | 209 | V(groups_string, "groups") \ | |
| 210 | 210 | V(has_regexp_groups_string, "hasRegExpGroups") \ | |
| 211 | + V(has_top_level_await_string, "hasTopLevelAwait") \ | ||
| 211 | 212 | V(hash_string, "hash") \ | |
| 212 | 213 | V(h2_string, "h2") \ | |
| 213 | 214 | V(handle_string, "handle") \ | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -22,6 +22,7 @@ using errors::TryCatchScope; | |||
| 22 | 22 | using node::contextify::ContextifyContext; | |
| 23 | 23 | using v8::Array; | |
| 24 | 24 | using v8::ArrayBufferView; | |
| 25 | + using v8::Boolean; | ||
| 25 | 26 | using v8::Context; | |
| 26 | 27 | using v8::Data; | |
| 27 | 28 | using v8::EscapableHandleScope; | |
@@ -414,6 +415,13 @@ void ModuleWrap::New(const FunctionCallbackInfo<Value>& args) { | |||
| 414 | 415 | return; | |
| 415 | 416 | } | |
| 416 | 417 | ||
| 418 | + if (that->Set(context, | ||
| 419 | + realm->env()->has_top_level_await_string(), | ||
| 420 | + Boolean::New(isolate, module->HasTopLevelAwait())) | ||
| 421 | + .IsNothing()) { | ||
| 422 | + return; | ||
| 423 | + } | ||
| 424 | + | ||
| 417 | 425 | if (that->Set(context, | |
| 418 | 426 | realm->env()->source_url_string(), | |
| 419 | 427 | module->GetUnboundModuleScript()->GetSourceURL()) | |
@@ -999,27 +1007,6 @@ void ModuleWrap::IsGraphAsync(const FunctionCallbackInfo<Value>& args) { | |||
| 999 | 1007 | args.GetReturnValue().Set(module->IsGraphAsync()); | |
| 1000 | 1008 | } | |
| 1001 | 1009 | ||
| 1002 | - void ModuleWrap::HasTopLevelAwait(const FunctionCallbackInfo<Value>& args) { | ||
| 1003 | - Isolate* isolate = args.GetIsolate(); | ||
| 1004 | - ModuleWrap* obj; | ||
| 1005 | - ASSIGN_OR_RETURN_UNWRAP(&obj, args.This()); | ||
| 1006 | - | ||
| 1007 | - Local<Module> module = obj->module_.Get(isolate); | ||
| 1008 | - | ||
| 1009 | - // Check if module is valid | ||
| 1010 | - if (module.IsEmpty()) { | ||
| 1011 | - args.GetReturnValue().Set(false); | ||
| 1012 | - return; | ||
| 1013 | - } | ||
| 1014 | - | ||
| 1015 | - // For source text modules, check if the graph is async | ||
| 1016 | - // For synthetic modules, it's always false | ||
| 1017 | - bool has_top_level_await = | ||
| 1018 | - module->IsSourceTextModule() && module->IsGraphAsync(); | ||
| 1019 | - | ||
| 1020 | - args.GetReturnValue().Set(has_top_level_await); | ||
| 1021 | - } | ||
| 1022 | - | ||
| 1023 | 1010 | void ModuleWrap::GetError(const FunctionCallbackInfo<Value>& args) { | |
| 1024 | 1011 | Isolate* isolate = args.GetIsolate(); | |
| 1025 | 1012 | ModuleWrap* obj; | |
@@ -1443,8 +1430,6 @@ void ModuleWrap::CreatePerIsolateProperties(IsolateData* isolate_data, | |||
| 1443 | 1430 | SetProtoMethodNoSideEffect(isolate, tpl, "getNamespace", GetNamespace); | |
| 1444 | 1431 | SetProtoMethodNoSideEffect(isolate, tpl, "getStatus", GetStatus); | |
| 1445 | 1432 | SetProtoMethodNoSideEffect(isolate, tpl, "isGraphAsync", IsGraphAsync); | |
| 1446 | - SetProtoMethodNoSideEffect( | ||
| 1447 | - isolate, tpl, "hasTopLevelAwait", HasTopLevelAwait); | ||
| 1448 | 1433 | SetProtoMethodNoSideEffect(isolate, tpl, "getError", GetError); | |
| 1449 | 1434 | SetConstructorFunction(isolate, target, "ModuleWrap", tpl); | |
| 1450 | 1435 | isolate_data->set_module_wrap_constructor_template(tpl); | |
@@ -1507,7 +1492,6 @@ void ModuleWrap::RegisterExternalReferences( | |||
| 1507 | 1492 | registry->Register(GetStatus); | |
| 1508 | 1493 | registry->Register(GetError); | |
| 1509 | 1494 | registry->Register(IsGraphAsync); | |
| 1510 | - registry->Register(HasTopLevelAwait); | ||
| 1511 | 1495 | ||
| 1512 | 1496 | registry->Register(CreateRequiredModuleFacade); | |
| 1513 | 1497 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -119,8 +119,6 @@ class ModuleWrap : public BaseObject { | |||
| 119 | 119 | v8::Local<v8::Module> module, | |
| 120 | 120 | v8::Local<v8::Object> meta); | |
| 121 | 121 | ||
| 122 | - static void HasTopLevelAwait(const v8::FunctionCallbackInfo<v8::Value>& args); | ||
| 123 | - | ||
| 124 | 122 | v8::Local<v8::Context> context() const; | |
| 125 | 123 | v8::Maybe<bool> CheckUnsettledTopLevelAwait(); | |
| 126 | 124 | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments