electron/patches/node/fix_capture_embedder_except...

83 lines
3.1 KiB
Diff

From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: deepak1556 <hop2deep@gmail.com>
Date: Tue, 26 Dec 2023 02:10:42 +0900
Subject: fix: capture embedder exceptions before entering V8
Upstrem bug: https://github.com/nodejs/node-v8/issues/274
The patch only addresses the callsites that triggered failing DCHECKS
in the nodejs test suite. Need to be followed-up with upstream
on the broader change as there maybe other callsites.
diff --git a/src/handle_wrap.cc b/src/handle_wrap.cc
index 69e2a389f9e1480a1a4ba37f5df5356b42f7d52d..0c29b00298b44b97f88a63aa5b89f1c201f6326a 100644
--- a/src/handle_wrap.cc
+++ b/src/handle_wrap.cc
@@ -148,6 +148,9 @@ void HandleWrap::OnClose(uv_handle_t* handle) {
wrap->OnClose();
wrap->handle_wrap_queue_.Remove();
+ if (env->isolate()->IsExecutionTerminating())
+ return;
+
if (!wrap->persistent().IsEmpty() &&
wrap->object()->Has(env->context(), env->handle_onclose_symbol())
.FromMaybe(false)) {
diff --git a/src/node_contextify.cc b/src/node_contextify.cc
index e9d50ac402b01208eb06504afcdfaf8d1e982bcd..c728c11145bdc7bfce59c3c20fa43508ea4482fb 100644
--- a/src/node_contextify.cc
+++ b/src/node_contextify.cc
@@ -459,6 +459,7 @@ bool ContextifyContext::IsStillInitializing(const ContextifyContext* ctx) {
void ContextifyContext::PropertyGetterCallback(
Local<Name> property,
const PropertyCallbackInfo<Value>& args) {
+ Environment* env = Environment::GetCurrent(args);
ContextifyContext* ctx = ContextifyContext::Get(args);
// Still initializing
@@ -466,6 +467,8 @@ void ContextifyContext::PropertyGetterCallback(
Local<Context> context = ctx->context();
Local<Object> sandbox = ctx->sandbox();
+
+ TryCatchScope try_catch(env);
MaybeLocal<Value> maybe_rv =
sandbox->GetRealNamedProperty(context, property);
if (maybe_rv.IsEmpty()) {
@@ -475,6 +478,11 @@ void ContextifyContext::PropertyGetterCallback(
Local<Value> rv;
if (maybe_rv.ToLocal(&rv)) {
+ if (try_catch.HasCaught() &&
+ !try_catch.HasTerminated()) {
+ try_catch.ReThrow();
+ }
+
if (rv == sandbox)
rv = ctx->global_proxy();
diff --git a/src/node_messaging.cc b/src/node_messaging.cc
index e7d2bfbafef13f04a73dcbefe7d6e90b37b904d1..31b870c5f003b62b848c00d6032ed98eb829778d 100644
--- a/src/node_messaging.cc
+++ b/src/node_messaging.cc
@@ -907,7 +907,7 @@ Maybe<bool> MessagePort::PostMessage(Environment* env,
const TransferList& transfer_v) {
Isolate* isolate = env->isolate();
Local<Object> obj = object(isolate);
-
+ TryCatchScope try_catch(env);
std::shared_ptr<Message> msg = std::make_shared<Message>();
// Per spec, we need to both check if transfer list has the source port, and
@@ -915,6 +915,10 @@ Maybe<bool> MessagePort::PostMessage(Environment* env,
Maybe<bool> serialization_maybe =
msg->Serialize(env, context, message_v, transfer_v, obj);
+ if (try_catch.HasCaught() &&
+ !try_catch.HasTerminated()) {
+ try_catch.ReThrow();
+ }
if (data_ == nullptr) {
return serialization_maybe;
}