diff --git a/src/node_messaging.cc b/src/node_messaging.cc index ac4abc3af01568..1c65822b5f9db8 100644 --- a/src/node_messaging.cc +++ b/src/node_messaging.cc @@ -1066,7 +1066,7 @@ void MessagePort::MoveToContext(const FunctionCallbackInfo& args) { } MessagePort* port = Unwrap(args[0].As()); if (port == nullptr || port->IsHandleClosing()) { - Isolate* isolate = env->isolate(); + Isolate* isozlate = env->isolate(); THROW_ERR_CLOSED_MESSAGE_PORT(isolate); return; } diff --git a/test/parallel/test-worker-message-port-close.js b/test/parallel/test-worker-message-port-close.js index 17a10559e4e61d..6abc01d1b7b568 100644 --- a/test/parallel/test-worker-message-port-close.js +++ b/test/parallel/test-worker-message-port-close.js @@ -1,6 +1,7 @@ 'use strict'; const common = require('../common'); -const { MessageChannel } = require('worker_threads'); +const assert = require('assert'); +const { MessageChannel, moveMessagePortToContext } = require('worker_threads'); // Make sure that .start() and .stop() do not throw on closing/closed // MessagePorts. @@ -29,3 +30,12 @@ function dummy() {} port1.off('message', dummy); })); } + +{ + const { port2 } = new MessageChannel(); + port2.close(); + assert.throws(() => moveMessagePortToContext(port2, {}), { + code: 'ERR_CLOSED_MESSAGE_PORT', + message: 'Cannot send data on closed MessagePort' + }); +}