| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent d7641d8 commit 79a8cd0
2 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -714,6 +714,15 @@ void MessagePort::PostMessage(const FunctionCallbackInfo<Value>& args) { | |||
| 714 | 714 | return THROW_ERR_MISSING_ARGS(env, "Not enough arguments to " | |
| 715 | 715 | "MessagePort.postMessage"); | |
| 716 | 716 | } | |
| 717 | + if (!args[1]->IsNullOrUndefined() && !args[1]->IsObject()) { | ||
| 718 | + // Browsers ignore null or undefined, and otherwise accept an array or an | ||
| 719 | + // options object. | ||
| 720 | + // TODO(addaleax): Add support for an options object and generic sequence | ||
| 721 | + // support. | ||
| 722 | + // Refs: https://github.com/nodejs/node/pull/28033#discussion_r289964991 | ||
| 723 | + return THROW_ERR_INVALID_ARG_TYPE(env, | ||
| 724 | + "Optional transferList argument must be an array"); | ||
| 725 | + } | ||
| 717 | 726 | ||
| 718 | 727 | MessagePort* port = Unwrap<MessagePort>(args.This()); | |
| 719 | 728 | // Even if the backing MessagePort object has already been deleted, we still | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -70,6 +70,27 @@ const { MessageChannel, MessagePort } = require('worker_threads'); | |||
| 70 | 70 | }); | |
| 71 | 71 | } | |
| 72 | 72 | ||
| 73 | + { | ||
| 74 | + const { port1, port2 } = new MessageChannel(); | ||
| 75 | + port2.on('message', common.mustCall(4)); | ||
| 76 | + port1.postMessage(1, null); | ||
| 77 | + port1.postMessage(2, undefined); | ||
| 78 | + port1.postMessage(3, []); | ||
| 79 | + port1.postMessage(4, {}); | ||
| 80 | + | ||
| 81 | + const err = { | ||
| 82 | + constructor: TypeError, | ||
| 83 | + code: 'ERR_INVALID_ARG_TYPE', | ||
| 84 | + message: 'Optional transferList argument must be an array' | ||
| 85 | + }; | ||
| 86 | + | ||
| 87 | + assert.throws(() => port1.postMessage(5, 0), err); | ||
| 88 | + assert.throws(() => port1.postMessage(5, false), err); | ||
| 89 | + assert.throws(() => port1.postMessage(5, 'X'), err); | ||
| 90 | + assert.throws(() => port1.postMessage(5, Symbol('X')), err); | ||
| 91 | + port1.close(); | ||
| 92 | + } | ||
| 93 | + | ||
| 73 | 94 | { | |
| 74 | 95 | assert.deepStrictEqual( | |
| 75 | 96 | Object.getOwnPropertyNames(MessagePort.prototype).sort(), | |
| Back | FazBrowse Home | New Git URL |
0 commit comments