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 <[email protected]>
Reviewed-By: Michaël Zasso <[email protected]>
Reviewed-By: James M Snell <[email protected]>
Reviewed-By: Colin Ihrig <[email protected]>
Reviewed-By: Minwoo Jung <[email protected]>
  • Loading branch information
addaleax authored and richardlau committed Jul 20, 2021
1 parent 1ffbe3d commit 2c28e00
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 2c28e00

Please sign in to comment.