diff options
author | Gus Caplan <me@gus.host> | 2019-11-12 09:30:02 +0300 |
---|---|---|
committer | Gus Caplan <me@gus.host> | 2020-05-14 20:39:23 +0300 |
commit | 5ae5262f448295e314393dad4c491259793cea3f (patch) | |
tree | 412178bf21e1eb5e5727fcad1744233c0931ef5e /src/module_wrap.cc | |
parent | 241ed44a0b06db45c97681c164fc1098e7c9f0d2 (diff) |
src: add support for TLA
PR-URL: https://github.com/nodejs/node/pull/30370
Reviewed-By: Guy Bedford <guybedford@gmail.com>
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
Reviewed-By: Myles Borins <myles.borins@gmail.com>
Diffstat (limited to 'src/module_wrap.cc')
-rw-r--r-- | src/module_wrap.cc | 20 |
1 files changed, 15 insertions, 5 deletions
diff --git a/src/module_wrap.cc b/src/module_wrap.cc index 13dd331e6b2..59ef9daf727 100644 --- a/src/module_wrap.cc +++ b/src/module_wrap.cc @@ -375,7 +375,13 @@ void ModuleWrap::Evaluate(const FunctionCallbackInfo<Value>& args) { return; } - args.GetReturnValue().Set(result.ToLocalChecked()); + // If TLA is enabled, `result` is the evaluation's promise. + // Otherwise, `result` is the last evaluated value of the module, + // which could be a promise, which would result in it being incorrectly + // unwrapped when the higher level code awaits the evaluation. + if (env->isolate_data()->options()->experimental_top_level_await) { + args.GetReturnValue().Set(result.ToLocalChecked()); + } } void ModuleWrap::GetNamespace(const FunctionCallbackInfo<Value>& args) { @@ -387,13 +393,17 @@ void ModuleWrap::GetNamespace(const FunctionCallbackInfo<Value>& args) { Local<Module> module = obj->module_.Get(isolate); switch (module->GetStatus()) { - default: + case v8::Module::Status::kUninstantiated: + case v8::Module::Status::kInstantiating: return env->ThrowError( - "cannot get namespace, Module has not been instantiated"); + "cannot get namespace, module has not been instantiated"); case v8::Module::Status::kInstantiated: case v8::Module::Status::kEvaluating: case v8::Module::Status::kEvaluated: + case v8::Module::Status::kErrored: break; + default: + UNREACHABLE(); } Local<Value> result = module->GetModuleNamespace(); @@ -616,19 +626,19 @@ MaybeLocal<Value> ModuleWrap::SyntheticModuleEvaluationStepsCallback( TryCatchScope try_catch(env); Local<Function> synthetic_evaluation_steps = obj->synthetic_evaluation_steps_.Get(isolate); + obj->synthetic_evaluation_steps_.Reset(); MaybeLocal<Value> ret = synthetic_evaluation_steps->Call(context, obj->object(), 0, nullptr); if (ret.IsEmpty()) { CHECK(try_catch.HasCaught()); } - obj->synthetic_evaluation_steps_.Reset(); if (try_catch.HasCaught() && !try_catch.HasTerminated()) { CHECK(!try_catch.Message().IsEmpty()); CHECK(!try_catch.Exception().IsEmpty()); try_catch.ReThrow(); return MaybeLocal<Value>(); } - return ret; + return Undefined(isolate); } void ModuleWrap::SetSyntheticExport(const FunctionCallbackInfo<Value>& args) { |