From 269c1d69c957811d7f5054a524df8f151b5c5781 Mon Sep 17 00:00:00 2001 From: Anna Henningsen Date: Sun, 2 Jun 2019 20:24:22 +0200 Subject: worker: add typechecking for postMessage transfer list If the transfer list argument is present, it should be an array. This commit adds typechecking to that effect. This aligns behaviour with browsers. PR-URL: https://github.com/nodejs/node/pull/28033 Reviewed-By: Rich Trott Reviewed-By: Luigi Pinca Reviewed-By: Colin Ihrig Reviewed-By: Ruben Bridgewater --- src/node_messaging.cc | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'src') diff --git a/src/node_messaging.cc b/src/node_messaging.cc index ba39d01dc3..79fa510ed7 100644 --- a/src/node_messaging.cc +++ b/src/node_messaging.cc @@ -714,6 +714,15 @@ void MessagePort::PostMessage(const FunctionCallbackInfo& args) { return THROW_ERR_MISSING_ARGS(env, "Not enough arguments to " "MessagePort.postMessage"); } + if (!args[1]->IsNullOrUndefined() && !args[1]->IsObject()) { + // Browsers ignore null or undefined, and otherwise accept an array or an + // options object. + // TODO(addaleax): Add support for an options object and generic sequence + // support. + // Refs: https://github.com/nodejs/node/pull/28033#discussion_r289964991 + return THROW_ERR_INVALID_ARG_TYPE(env, + "Optional transferList argument must be an array"); + } MessagePort* port = Unwrap(args.This()); // Even if the backing MessagePort object has already been deleted, we still -- cgit v1.2.3