Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
fixup! src: handle fatal error when Environment is not assigned to co…
…ntext
  • Loading branch information
joyeecheung committed Apr 15, 2019
commit 7933801bed4f24252c4f8b8ee0ae139a27dab2cf
15 changes: 9 additions & 6 deletions src/env-inl.h
Original file line number Diff line number Diff line change
Expand Up @@ -302,15 +302,18 @@ inline Environment* Environment::GetCurrent(v8::Isolate* isolate) {
}

inline Environment* Environment::GetCurrent(v8::Local<v8::Context> context) {
if (UNLIKELY(context.IsEmpty() ||
context->GetNumberOfEmbedderDataFields() <=
ContextEmbedderIndex::kContextTag ||
context->GetAlignedPointerFromEmbedderData(
if (UNLIKELY(context.IsEmpty())) {
return nullptr;
}
if (UNLIKELY(context->GetNumberOfEmbedderDataFields() <=
ContextEmbedderIndex::kContextTag)) {
return nullptr;
}
if (UNLIKELY(context->GetAlignedPointerFromEmbedderData(
ContextEmbedderIndex::kContextTag) !=
Environment::kNodeContextTagPtr)) {
Environment::kNodeContextTagPtr)) {
return nullptr;
}

return static_cast<Environment*>(
context->GetAlignedPointerFromEmbedderData(
ContextEmbedderIndex::kEnvironment));
Expand Down
20 changes: 8 additions & 12 deletions src/node_errors.cc
Original file line number Diff line number Diff line change
Expand Up @@ -184,11 +184,7 @@ void PrintException(Isolate* isolate,
fprintf(stderr, "%s\n", *reason);

Local<v8::StackTrace> stack = message->GetStackTrace();
if (stack.IsEmpty()) {
return;
} else {
PrintStackTrace(isolate, stack);
}
if (!stack.IsEmpty()) PrintStackTrace(isolate, stack);
}

void PrintCaughtException(Isolate* isolate,
Expand Down Expand Up @@ -790,14 +786,14 @@ void FatalException(Isolate* isolate,
Local<Context> context = isolate->GetCurrentContext();
Environment* env = Environment::GetCurrent(context);
if (env == nullptr) {
// This could happen before Environment is assigned to the context.
// This means that the exception happens before Environment is assigned
// to the context e.g. when there is a SyntaxError in a per-context
// script - which usually indicates that there is a bug because no JS
// error is supposed to be thrown at this point.
// Since we don't have access to Environment here, there is not
// much we can do, so we just print whatever useful and crash.
Comment thread
joyeecheung marked this conversation as resolved.
PrintException(isolate, context, error, message);
// XXX(joyeecheung): this could also happen to a worker, but since
// we don't have access to Environment yet, there is not much
// we can do at this point but to exit directly.
isolate->TerminateExecution();
DisposePlatform();
exit(6);
Abort();
}

Local<Object> process_object = env->process_object();
Expand Down