diff options
author | Harshitha KP <harshi46@in.ibm.com> | 2020-02-21 10:32:51 +0300 |
---|---|---|
committer | Anna Henningsen <anna@addaleax.net> | 2020-03-09 15:25:02 +0300 |
commit | e9fa5ae3a1198213f8f58d4b97eb6233c05a28b4 (patch) | |
tree | 814784900b870bedd5ca1023a453d6831540f772 /src/module_wrap.cc | |
parent | 8ce6315e8896dd30f5d21caca542b031f33e6b8d (diff) |
src: handle NULL env scenario
Convert hard assertion into a throw with a useful error
message in src/module_wrap.cc.
PR-URL: https://github.com/nodejs/node/pull/31899
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Diffstat (limited to 'src/module_wrap.cc')
-rw-r--r-- | src/module_wrap.cc | 13 |
1 files changed, 11 insertions, 2 deletions
diff --git a/src/module_wrap.cc b/src/module_wrap.cc index 2b1708088bf..b2afefce17e 100644 --- a/src/module_wrap.cc +++ b/src/module_wrap.cc @@ -451,7 +451,12 @@ MaybeLocal<Module> ModuleWrap::ResolveCallback(Local<Context> context, Local<String> specifier, Local<Module> referrer) { Environment* env = Environment::GetCurrent(context); - CHECK_NOT_NULL(env); // TODO(addaleax): Handle nullptr here. + if (env == nullptr) { + Isolate* isolate = context->GetIsolate(); + THROW_ERR_EXECUTION_ENVIRONMENT_NOT_AVAILABLE(isolate); + return MaybeLocal<Module>(); + } + Isolate* isolate = env->isolate(); ModuleWrap* dependent = GetFromModule(env, referrer); @@ -1443,7 +1448,11 @@ static MaybeLocal<Promise> ImportModuleDynamically( Local<String> specifier) { Isolate* iso = context->GetIsolate(); Environment* env = Environment::GetCurrent(context); - CHECK_NOT_NULL(env); // TODO(addaleax): Handle nullptr here. + if (env == nullptr) { + THROW_ERR_EXECUTION_ENVIRONMENT_NOT_AVAILABLE(iso); + return MaybeLocal<Promise>(); + } + EscapableHandleScope handle_scope(iso); Local<Function> import_callback = |