From ee83f91f83cbf9b7a60067b11763089838cb9da9 Mon Sep 17 00:00:00 2001 From: James M Snell Date: Sat, 6 Sep 2025 20:01:13 -0700 Subject: [PATCH] src: fixup node_messaging error handling Replace ToLocalChecked uses --- src/node_messaging.cc | 41 ++++++++++++++++++++++++++++------------- 1 file changed, 28 insertions(+), 13 deletions(-) diff --git a/src/node_messaging.cc b/src/node_messaging.cc index 084ff03dbe8124..ad4a7b3974df90 100644 --- a/src/node_messaging.cc +++ b/src/node_messaging.cc @@ -328,6 +328,7 @@ class SerializerDelegate : public ValueSerializer::Delegate { if (JSTransferable::IsJSTransferable(env_, context_, object)) { BaseObjectPtr js_transferable = JSTransferable::Wrap(env_, object); + if (!js_transferable) return Nothing(); return WriteHostObject(js_transferable); } @@ -550,6 +551,7 @@ Maybe Message::Serialize(Environment* env, return Nothing(); } host_object = JSTransferable::Wrap(env, entry); + if (!host_object) return Nothing(); } if (env->message_port_constructor_template()->HasInstance(entry) && @@ -1245,27 +1247,38 @@ Local GetMessagePortConstructorTemplate( BaseObjectPtr JSTransferable::Wrap(Environment* env, Local target) { Local context = env->context(); - Local wrapper_val = - target->GetPrivate(context, env->js_transferable_wrapper_private_symbol()) - .ToLocalChecked(); + Local wrapper_val; + if (!target + ->GetPrivate(context, env->js_transferable_wrapper_private_symbol()) + .ToLocal(&wrapper_val)) { + return {}; + } DCHECK(wrapper_val->IsObject() || wrapper_val->IsUndefined()); BaseObjectPtr wrapper; if (wrapper_val->IsObject()) { wrapper = BaseObjectPtr{Unwrap(wrapper_val)}; } else { - Local wrapper_obj = env->js_transferable_constructor_template() - ->GetFunction(context) - .ToLocalChecked() - ->NewInstance(context) - .ToLocalChecked(); + Local ctor; + if (!env->js_transferable_constructor_template() + ->GetFunction(context) + .ToLocal(&ctor)) { + return {}; + } + Local wrapper_obj; + if (!ctor->NewInstance(context).ToLocal(&wrapper_obj)) { + return {}; + } // Make sure the JSTransferable wrapper object is not garbage collected // until the strong BaseObjectPtr's reference count is decreased to 0. wrapper = MakeDetachedBaseObject(env, wrapper_obj, target); - target - ->SetPrivate( - context, env->js_transferable_wrapper_private_symbol(), wrapper_obj) - .ToChecked(); + if (target + ->SetPrivate(context, + env->js_transferable_wrapper_private_symbol(), + wrapper_obj) + .IsNothing()) { + return {}; + } } return wrapper; } @@ -1396,7 +1409,9 @@ Maybe JSTransferable::NestedTransferables() const { if (!JSTransferable::IsJSTransferable(env(), context, obj)) { continue; } - ret.emplace_back(JSTransferable::Wrap(env(), obj)); + auto wrapped = JSTransferable::Wrap(env(), obj); + if (!wrapped) return Nothing(); + ret.emplace_back(wrapped); } return Just(ret); }