From 2c28e006859e7ecf7183db9fbcea82beed58fa5f Mon Sep 17 00:00:00 2001 From: Anna Henningsen Date: Sun, 23 May 2021 16:20:41 +0200 Subject: [PATCH] worker: do not look up context twice in PostMessage MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Refs: https://github.com/nodejs/node/issues/38780#issuecomment-846548949 PR-URL: https://github.com/nodejs/node/pull/38784 Reviewed-By: Gireesh Punathil Reviewed-By: Michaƫl Zasso Reviewed-By: James M Snell Reviewed-By: Colin Ihrig Reviewed-By: Minwoo Jung --- src/node_messaging.cc | 6 ++++-- src/node_messaging.h | 1 + 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/src/node_messaging.cc b/src/node_messaging.cc index 9d17e670aec459..804d520497cf3a 100644 --- a/src/node_messaging.cc +++ b/src/node_messaging.cc @@ -824,11 +824,11 @@ BaseObjectPtr MessagePortData::Deserialize( } Maybe MessagePort::PostMessage(Environment* env, + Local context, Local message_v, const TransferList& transfer_v) { Isolate* isolate = env->isolate(); Local obj = object(isolate); - Local context = obj->CreationContext(); Message msg; @@ -970,7 +970,9 @@ void MessagePort::PostMessage(const FunctionCallbackInfo& args) { return; } - port->PostMessage(env, args[0], transfer_list); + Maybe res = port->PostMessage(env, context, args[0], transfer_list); + if (res.IsJust()) + args.GetReturnValue().Set(res.FromJust()); } void MessagePort::Start() { diff --git a/src/node_messaging.h b/src/node_messaging.h index 34215349343722..76fc2898430baa 100644 --- a/src/node_messaging.h +++ b/src/node_messaging.h @@ -181,6 +181,7 @@ class MessagePort : public HandleWrap { // If this port is closed, or if there is no sibling, this message is // serialized with transfers, then silently discarded. v8::Maybe PostMessage(Environment* env, + v8::Local context, v8::Local message, const TransferList& transfer);