src: separate module.hasAsyncGraph and module.hasTopLevelAwait · nodejs/node@15cbd39

@@ -22,6 +22,7 @@ using errors::TryCatchScope;

2222

using node::contextify::ContextifyContext;

2323

using v8::Array;

2424

using v8::ArrayBufferView;

25+

using v8::Boolean;

2526

using v8::Context;

2627

using v8::Data;

2728

using v8::EscapableHandleScope;

@@ -414,6 +415,13 @@ void ModuleWrap::New(const FunctionCallbackInfo<Value>& args) {

414415

return;

415416

}

416417418+

if (that->Set(context,

419+

realm->env()->has_top_level_await_string(),

420+

Boolean::New(isolate, module->HasTopLevelAwait()))

421+

.IsNothing()) {

422+

return;

423+

}

424+417425

if (that->Set(context,

418426

realm->env()->source_url_string(),

419427

module->GetUnboundModuleScript()->GetSourceURL())

@@ -999,27 +1007,6 @@ void ModuleWrap::IsGraphAsync(const FunctionCallbackInfo<Value>& args) {

9991007

args.GetReturnValue().Set(module->IsGraphAsync());

10001008

}

100110091002-

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-10231010

void ModuleWrap::GetError(const FunctionCallbackInfo<Value>& args) {

10241011

Isolate* isolate = args.GetIsolate();

10251012

ModuleWrap* obj;

@@ -1443,8 +1430,6 @@ void ModuleWrap::CreatePerIsolateProperties(IsolateData* isolate_data,

14431430

SetProtoMethodNoSideEffect(isolate, tpl, "getNamespace", GetNamespace);

14441431

SetProtoMethodNoSideEffect(isolate, tpl, "getStatus", GetStatus);

14451432

SetProtoMethodNoSideEffect(isolate, tpl, "isGraphAsync", IsGraphAsync);

1446-

SetProtoMethodNoSideEffect(

1447-

isolate, tpl, "hasTopLevelAwait", HasTopLevelAwait);

14481433

SetProtoMethodNoSideEffect(isolate, tpl, "getError", GetError);

14491434

SetConstructorFunction(isolate, target, "ModuleWrap", tpl);

14501435

isolate_data->set_module_wrap_constructor_template(tpl);

@@ -1507,7 +1492,6 @@ void ModuleWrap::RegisterExternalReferences(

15071492

registry->Register(GetStatus);

15081493

registry->Register(GetError);

15091494

registry->Register(IsGraphAsync);

1510-

registry->Register(HasTopLevelAwait);

1511149515121496

registry->Register(CreateRequiredModuleFacade);

15131497