Skip to content

Commit

Permalink
worker: do not look up context twice in PostMessage
Browse files Browse the repository at this point in the history
Refs: #38780 (comment)

PR-URL: #38784
Reviewed-By: Gireesh Punathil <gpunathi@in.ibm.com>
Reviewed-By: Michaël Zasso <targos@protonmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Minwoo Jung <nodecorelab@gmail.com>
  • Loading branch information
addaleax authored and richardlau committed Jul 16, 2021
1 parent 9b85e03 commit c53184e
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/node_messaging.cc
Original file line number Diff line number Diff line change
Expand Up @@ -824,11 +824,11 @@ BaseObjectPtr<BaseObject> MessagePortData::Deserialize(
}

Maybe<bool> MessagePort::PostMessage(Environment* env,
Local<Context> context,
Local<Value> message_v,
const TransferList& transfer_v) {
Isolate* isolate = env->isolate();
Local<Object> obj = object(isolate);
Local<Context> context = obj->CreationContext();

Message msg;

Expand Down Expand Up @@ -970,7 +970,9 @@ void MessagePort::PostMessage(const FunctionCallbackInfo<Value>& args) {
return;
}

port->PostMessage(env, args[0], transfer_list);
Maybe<bool> res = port->PostMessage(env, context, args[0], transfer_list);
if (res.IsJust())
args.GetReturnValue().Set(res.FromJust());
}

void MessagePort::Start() {
Expand Down
1 change: 1 addition & 0 deletions src/node_messaging.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<bool> PostMessage(Environment* env,
v8::Local<v8::Context> context,
v8::Local<v8::Value> message,
const TransferList& transfer);

Expand Down

0 comments on commit c53184e

Please sign in to comment.