Skip to content

Commit

Permalink
src: simplify MessagePort construction code a bit
Browse files Browse the repository at this point in the history
Using `ASSIGN_OR_RETURN_UNWRAP` would return if the
created `MessagePort` object had no internal fields.
That would be a bug, so switch to a checked conversion instead.

PR-URL: #23036
Reviewed-By: Gus Caplan <[email protected]>
Reviewed-By: James M Snell <[email protected]>
Reviewed-By: Colin Ihrig <[email protected]>
Reviewed-By: Joyee Cheung <[email protected]>
  • Loading branch information
addaleax authored and targos committed Sep 27, 2018
1 parent 4d61c34 commit f3d09b6
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/node_messaging.cc
Original file line number Diff line number Diff line change
Expand Up @@ -483,14 +483,14 @@ MessagePort* MessagePort::New(
Local<Function> ctor;
if (!GetMessagePortConstructor(env, context).ToLocal(&ctor))
return nullptr;
MessagePort* port = nullptr;

// Construct a new instance, then assign the listener instance and possibly
// the MessagePortData to it.
Local<Object> instance;
if (!ctor->NewInstance(context).ToLocal(&instance))
return nullptr;
ASSIGN_OR_RETURN_UNWRAP(&port, instance, nullptr);
MessagePort* port = Unwrap<MessagePort>(instance);
CHECK_NOT_NULL(port);
if (data) {
port->Detach();
port->data_ = std::move(data);
Expand Down

0 comments on commit f3d09b6

Please sign in to comment.