Skip to content

Commit

Permalink
Add proper callback exception handling
Browse files Browse the repository at this point in the history
Expceptions thrown inside callback handlers didn't get caught

since the Node.js upgrade
  • Loading branch information
Alexander committed Nov 27, 2021
1 parent 42613a4 commit 0e50ab2
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
8 changes: 4 additions & 4 deletions src/events.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -385,7 +385,7 @@ namespace sampnode


v8::Local<v8::Function> function = listener.function.Get(isolate);
v8::Local<v8::Value> returnValue = function->Call(ctx, ctx->Global(), argc, argv).ToLocalChecked();
v8::MaybeLocal<v8::Value> returnValue = function->Call(ctx, ctx->Global(), argc, argv);

if (argc > 0) delete[] argv;

Expand All @@ -398,7 +398,7 @@ namespace sampnode
}
else
{
int cppIntReturnValue = returnValue->Int32Value(ctx).ToChecked();
int cppIntReturnValue = returnValue.ToLocalChecked()->Int32Value(ctx).ToChecked();
if (retval != nullptr) *retval = static_cast<cell>(cppIntReturnValue);
}
}
Expand Down Expand Up @@ -507,7 +507,7 @@ namespace sampnode
}

v8::Local<v8::Function> function = listener.function.Get(listener.isolate);
v8::Local<v8::Value> returnValue = function->Call(ctx, ctx->Global(), argc, argv).ToLocalChecked();
v8::MaybeLocal<v8::Value> returnValue = function->Call(ctx, ctx->Global(), argc, argv);

if (argc > 0) delete[] argv;

Expand All @@ -520,7 +520,7 @@ namespace sampnode
}
else
{
int cppIntReturnValue = returnValue->Int32Value(ctx).ToChecked();
int cppIntReturnValue = returnValue.ToLocalChecked()->Int32Value(ctx).ToChecked();
if (retval != nullptr) *retval = static_cast<cell>(cppIntReturnValue);
}
}
Expand Down
6 changes: 4 additions & 2 deletions src/nodeimpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,9 @@ namespace sampnode
v8Isolate = node::NewIsolate(arrayBufferAllocator.get(), nodeLoop->GetLoop(), v8Platform.get());
v8Isolate->SetFatalErrorHandler([](const char* location, const char* message)
{
exit(0);
L_ERROR << "at " << location;
L_ERROR << message;
exit(1);
});

v8Isolate->SetCaptureStackTraceForUncaughtExceptions(true);
Expand All @@ -98,7 +100,7 @@ namespace sampnode
v8::Locker locker(v8Isolate);
v8::Isolate::Scope isolateScope(v8Isolate);

std::vector<std::string> args{"--expose-internals", "--trace-uncaught", "--inspect"};
std::vector<std::string> args{"--expose-internals", "--trace-uncaught", "--inspect", "--trace-warnings"};
std::vector<std::string> exec_args;
std::vector<std::string> errors;

Expand Down

0 comments on commit 0e50ab2

Please sign in to comment.