From e06a2ad21f84fef3fa06f6a3e664296e89c4d72e Mon Sep 17 00:00:00 2001 From: James M Snell Date: Sat, 5 Apr 2025 11:07:52 -0700 Subject: [PATCH] src: improve error handing in node_messaging MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit PR-URL: https://github.com/nodejs/node/pull/57760 Reviewed-By: Michaƫl Zasso Reviewed-By: Yagiz Nizipli --- src/node_messaging.cc | 29 ++++++++++++++++++++++------- 1 file changed, 22 insertions(+), 7 deletions(-) diff --git a/src/node_messaging.cc b/src/node_messaging.cc index 9ddbb211ac..30987ca04b 100644 --- a/src/node_messaging.cc +++ b/src/node_messaging.cc @@ -491,8 +491,12 @@ Maybe Message::Serialize(Environment* env, Local entry = entry_val.As(); // See https://github.com/nodejs/node/pull/30339#issuecomment-552225353 // for details. - if (entry->HasPrivate(context, env->untransferable_object_private_symbol()) - .ToChecked()) { + bool ans; + if (!entry->HasPrivate(context, env->untransferable_object_private_symbol()) + .To(&ans)) { + return Nothing(); + } + if (ans) { ThrowDataCloneException(context, env->transfer_unsupported_type_str()); return Nothing(); } @@ -591,7 +595,9 @@ Maybe Message::Serialize(Environment* env, for (Local ab : array_buffers) { // If serialization succeeded, we render it inaccessible in this Isolate. std::shared_ptr backing_store = ab->GetBackingStore(); - ab->Detach(Local()).Check(); + if (ab->Detach(Local()).IsNothing()) { + return Nothing(); + } array_buffers_.emplace_back(std::move(backing_store)); } @@ -1073,7 +1079,10 @@ bool GetTransferList(Environment* env, void MessagePort::PostMessage(const FunctionCallbackInfo& args) { Environment* env = Environment::GetCurrent(args); Local obj = args.This(); - Local context = obj->GetCreationContextChecked(); + Local context; + if (!obj->GetCreationContext().ToLocal(&context)) { + return; + } if (args.Length() == 0) { return THROW_ERR_MISSING_ARGS(env, "Not enough arguments to " @@ -1160,8 +1169,11 @@ void MessagePort::ReceiveMessage(const FunctionCallbackInfo& args) { } Local payload; - if (port->ReceiveMessage(port->object()->GetCreationContextChecked(), - MessageProcessingMode::kForceReadMessages) + Local context; + if (!port->object()->GetCreationContext().ToLocal(&context)) { + return; + } + if (port->ReceiveMessage(context, MessageProcessingMode::kForceReadMessages) .ToLocal(&payload)) { args.GetReturnValue().Set(payload); } @@ -1619,7 +1631,10 @@ static void MessageChannel(const FunctionCallbackInfo& args) { return; } - Local context = args.This()->GetCreationContextChecked(); + Local context; + if (!args.This()->GetCreationContext().ToLocal(&context)) { + return; + } Context::Scope context_scope(context); MessagePort* port1 = MessagePort::New(env, context);