src: Handle NULL env scenario by HarshithaKP · Pull Request #31899 · nodejs/node · GitHub
Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions doc/api/errors.md
13 changes: 11 additions & 2 deletions src/module_wrap.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Comment thread
addaleax marked this conversation as resolved.
Outdated
return MaybeLocal<Module>();
}

Isolate* isolate = env->isolate();

ModuleWrap* dependent = GetFromModule(env, referrer);
Expand Down Expand Up @@ -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 =
Expand Down
47 changes: 25 additions & 22 deletions src/node_errors.h