diff options
author | Anna Henningsen <anna@addaleax.net> | 2019-06-02 20:24:22 +0200 |
---|---|---|
committer | Anna Henningsen <anna@addaleax.net> | 2019-06-10 15:41:09 +0200 |
commit | 269c1d69c957811d7f5054a524df8f151b5c5781 (patch) | |
tree | 70f792be244ef6e8d4bd98175cde2b3804cda7f1 /src/node_messaging.cc | |
parent | 7bd2a3fcb407970babc88650ff030526ccf79f9f (diff) | |
download | android-node-v8-269c1d69c957811d7f5054a524df8f151b5c5781.tar.gz android-node-v8-269c1d69c957811d7f5054a524df8f151b5c5781.tar.bz2 android-node-v8-269c1d69c957811d7f5054a524df8f151b5c5781.zip |
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 <rtrott@gmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
Diffstat (limited to 'src/node_messaging.cc')
-rw-r--r-- | src/node_messaging.cc | 9 |
1 files changed, 9 insertions, 0 deletions
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<Value>& 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<MessagePort>(args.This()); // Even if the backing MessagePort object has already been deleted, we still |