| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 5b1fd10 commit 4a37180
9 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1561,6 +1561,17 @@ behavior. See the documentation for [policy][] manifests for more information. | |||
| 1561 | 1561 | An attempt was made to allocate memory (usually in the C++ layer) but it | |
| 1562 | 1562 | failed. | |
| 1563 | 1563 | ||
| 1564 | + <a id="ERR_MESSAGE_TARGET_CONTEXT_UNAVAILABLE"></a> | ||
| 1565 | + ### `ERR_MESSAGE_TARGET_CONTEXT_UNAVAILABLE` | ||
| 1566 | + <!-- YAML | ||
| 1567 | + added: REPLACEME | ||
| 1568 | + --> | ||
| 1569 | + | ||
| 1570 | + A message posted to a [`MessagePort`][] could not be deserialized in the target | ||
| 1571 | + [vm][] `Context`. Not all Node.js objects can be successfully instantiated in | ||
| 1572 | + any context at this time, and attempting to transfer them using `postMessage()` | ||
| 1573 | + can fail on the receiving side in that case. | ||
| 1574 | + | ||
| 1564 | 1575 | <a id="ERR_METHOD_NOT_IMPLEMENTED"></a> | |
| 1565 | 1576 | ### `ERR_METHOD_NOT_IMPLEMENTED` | |
| 1566 | 1577 | ||
@@ -2557,6 +2568,7 @@ such as `process.stdout.on('data')`. | |||
| 2557 | 2568 | [`Class: assert.AssertionError`]: assert.html#assert_class_assert_assertionerror | |
| 2558 | 2569 | [`ERR_INVALID_ARG_TYPE`]: #ERR_INVALID_ARG_TYPE | |
| 2559 | 2570 | [`EventEmitter`]: events.html#events_class_eventemitter | |
| 2571 | + [`MessagePort`]: worker_threads.html#worker_threads_class_messageport | ||
| 2560 | 2572 | [`Object.getPrototypeOf`]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/getPrototypeOf | |
| 2561 | 2573 | [`Object.setPrototypeOf`]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/setPrototypeOf | |
| 2562 | 2574 | [`REPL`]: repl.html | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -303,6 +303,15 @@ input of [`port.postMessage()`][]. | |||
| 303 | 303 | Listeners on this event will receive a clone of the `value` parameter as passed | |
| 304 | 304 | to `postMessage()` and no further arguments. | |
| 305 | 305 | ||
| 306 | + ### Event: `'messageerror'` | ||
| 307 | + <!-- YAML | ||
| 308 | + added: REPLACEME | ||
| 309 | + --> | ||
| 310 | + | ||
| 311 | + * `error` {Error} An Error object | ||
| 312 | + | ||
| 313 | + The `'messageerror'` event is emitted when deserializing a message failed. | ||
| 314 | + | ||
| 306 | 315 | ### `port.close()` | |
| 307 | 316 | <!-- YAML | |
| 308 | 317 | added: v10.5.0 | |
@@ -677,6 +686,15 @@ See the [`port.on('message')`][] event for more details. | |||
| 677 | 686 | All messages sent from the worker thread will be emitted before the | |
| 678 | 687 | [`'exit'` event][] is emitted on the `Worker` object. | |
| 679 | 688 | ||
| 689 | + ### Event: `'messageerror'` | ||
| 690 | + <!-- YAML | ||
| 691 | + added: REPLACEME | ||
| 692 | + --> | ||
| 693 | + | ||
| 694 | + * `error` {Error} An Error object | ||
| 695 | + | ||
| 696 | + The `'messageerror'` event is emitted when deserializing a message failed. | ||
| 697 | + | ||
| 680 | 698 | ### Event: `'online'` | |
| 681 | 699 | <!-- YAML | |
| 682 | 700 | added: v10.5.0 | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -190,7 +190,9 @@ class Worker extends EventEmitter { | |||
| 190 | 190 | transferList.push(...options.transferList); | |
| 191 | 191 | ||
| 192 | 192 | this[kPublicPort] = port1; | |
| 193 | - this[kPublicPort].on('message', (message) => this.emit('message', message)); | ||
| 193 | + for (const event of ['message', 'messageerror']) { | ||
| 194 | + this[kPublicPort].on(event, (message) => this.emit(event, message)); | ||
| 195 | + } | ||
| 194 | 196 | setupPortReferencing(this[kPublicPort], this, 'message'); | |
| 195 | 197 | this[kPort].postMessage({ | |
| 196 | 198 | argv, | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -223,6 +223,7 @@ constexpr size_t kFsStatsBufferLength = | |||
| 223 | 223 | V(done_string, "done") \ | |
| 224 | 224 | V(duration_string, "duration") \ | |
| 225 | 225 | V(ecdh_string, "ECDH") \ | |
| 226 | + V(emit_string, "emit") \ | ||
| 226 | 227 | V(emit_warning_string, "emitWarning") \ | |
| 227 | 228 | V(empty_object_string, "{}") \ | |
| 228 | 229 | V(encoding_string, "encoding") \ | |
@@ -279,6 +280,7 @@ constexpr size_t kFsStatsBufferLength = | |||
| 279 | 280 | V(message_port_constructor_string, "MessagePort") \ | |
| 280 | 281 | V(message_port_string, "messagePort") \ | |
| 281 | 282 | V(message_string, "message") \ | |
| 283 | + V(messageerror_string, "messageerror") \ | ||
| 282 | 284 | V(minttl_string, "minttl") \ | |
| 283 | 285 | V(module_string, "module") \ | |
| 284 | 286 | V(modulus_string, "modulus") \ | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -41,6 +41,7 @@ void OnFatalError(const char* location, const char* message); | |||
| 41 | 41 | V(ERR_INVALID_ARG_TYPE, TypeError) \ | |
| 42 | 42 | V(ERR_INVALID_TRANSFER_OBJECT, TypeError) \ | |
| 43 | 43 | V(ERR_MEMORY_ALLOCATION_FAILED, Error) \ | |
| 44 | + V(ERR_MESSAGE_TARGET_CONTEXT_UNAVAILABLE, Error) \ | ||
| 44 | 45 | V(ERR_MISSING_ARGS, TypeError) \ | |
| 45 | 46 | V(ERR_MISSING_MESSAGE_PORT_IN_TRANSFER_LIST, TypeError) \ | |
| 46 | 47 | V(ERR_MISSING_PASSPHRASE, TypeError) \ | |
@@ -92,6 +93,9 @@ void OnFatalError(const char* location, const char* message); | |||
| 92 | 93 | V(ERR_INVALID_TRANSFER_OBJECT, "Found invalid object in transferList") \ | |
| 93 | 94 | V(ERR_MEMORY_ALLOCATION_FAILED, "Failed to allocate memory") \ | |
| 94 | 95 | V(ERR_OSSL_EVP_INVALID_DIGEST, "Invalid digest used") \ | |
| 96 | + V(ERR_MESSAGE_TARGET_CONTEXT_UNAVAILABLE, \ | ||
| 97 | + "A message object could not be deserialized successfully in the target " \ | ||
| 98 | + "vm.Context") \ | ||
| 95 | 99 | V(ERR_MISSING_MESSAGE_PORT_IN_TRANSFER_LIST, \ | |
| 96 | 100 | "Object that needs transfer was found in message but not listed " \ | |
| 97 | 101 | "in transferList") \ | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -742,7 +742,17 @@ void MessagePort::OnMessage() { | |||
| 742 | 742 | Local<Function> emit_message = PersistentToLocal::Strong(emit_message_fn_); | |
| 743 | 743 | ||
| 744 | 744 | Local<Value> payload; | |
| 745 | - if (!ReceiveMessage(context, true).ToLocal(&payload)) goto reschedule; | ||
| 745 | + Local<Value> message_error; | ||
| 746 | + { | ||
| 747 | + // Catch any exceptions from parsing the message itself (not from | ||
| 748 | + // emitting it) as 'messageeror' events. | ||
| 749 | + TryCatchScope try_catch(env()); | ||
| 750 | + if (!ReceiveMessage(context, true).ToLocal(&payload)) { | ||
| 751 | + if (try_catch.HasCaught() && !try_catch.HasTerminated()) | ||
| 752 | + message_error = try_catch.Exception(); | ||
| 753 | + goto reschedule; | ||
| 754 | + } | ||
| 755 | + } | ||
| 746 | 756 | if (payload == env()->no_message_symbol()) break; | |
| 747 | 757 | ||
| 748 | 758 | if (!env()->can_call_into_js()) { | |
@@ -753,6 +763,16 @@ void MessagePort::OnMessage() { | |||
| 753 | 763 | ||
| 754 | 764 | if (MakeCallback(emit_message, 1, &payload).IsEmpty()) { | |
| 755 | 765 | reschedule: | |
| 766 | + if (!message_error.IsEmpty()) { | ||
| 767 | + // This should become a `messageerror` event in the sense of the | ||
| 768 | + // EventTarget API at some point. | ||
| 769 | + Local<Value> argv[] = { | ||
| 770 | + env()->messageerror_string(), | ||
| 771 | + message_error | ||
| 772 | + }; | ||
| 773 | + USE(MakeCallback(env()->emit_string(), arraysize(argv), argv)); | ||
| 774 | + } | ||
| 775 | + | ||
| 756 | 776 | // Re-schedule OnMessage() execution in case of failure. | |
| 757 | 777 | if (data_) | |
| 758 | 778 | TriggerAsync(); | |
@@ -1215,8 +1235,7 @@ BaseObjectPtr<BaseObject> JSTransferable::Data::Deserialize( | |||
| 1215 | 1235 | // the end of the stream, after the main message has been read. | |
| 1216 | 1236 | ||
| 1217 | 1237 | if (context != env->context()) { | |
| 1218 | - // It would be nice to throw some kind of exception here, but how do we | ||
| 1219 | - // pass that to end users? For now, just drop the message silently. | ||
| 1238 | + THROW_ERR_MESSAGE_TARGET_CONTEXT_UNAVAILABLE(env); | ||
| 1220 | 1239 | return {}; | |
| 1221 | 1240 | } | |
| 1222 | 1241 | HandleScope handle_scope(env->isolate()); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -26,7 +26,7 @@ const { once } = require('events'); | |||
| 26 | 26 | port1.postMessage(fh, [ fh ]); | |
| 27 | 27 | port2.on('message', common.mustNotCall()); | |
| 28 | 28 | ||
| 29 | - const [ exception ] = await once(process, 'uncaughtException'); | ||
| 29 | + const [ exception ] = await once(port2, 'messageerror'); | ||
| 30 | 30 | ||
| 31 | 31 | assert.strictEqual(exception.message, 'Unknown deserialize spec net:Socket'); | |
| 32 | 32 | port2.close(); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -30,7 +30,7 @@ module.exports = { | |||
| 30 | 30 | port1.postMessage(fh, [ fh ]); | |
| 31 | 31 | port2.on('message', common.mustNotCall()); | |
| 32 | 32 | ||
| 33 | - const [ exception ] = await once(process, 'uncaughtException'); | ||
| 33 | + const [ exception ] = await once(port2, 'messageerror'); | ||
| 34 | 34 | ||
| 35 | 35 | assert.match(exception.message, /Missing internal module/); | |
| 36 | 36 | port2.close(); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -55,6 +55,12 @@ const { once } = require('events'); | |||
| 55 | 55 | assert.strictEqual(msgEvent.data, 'second message'); | |
| 56 | 56 | port1.close(); | |
| 57 | 57 | }); | |
| 58 | + // TODO(addaleax): Switch this to a 'messageerror' event once MessagePort | ||
| 59 | + // implements EventTarget fully and in a cross-context manner. | ||
| 60 | + port2moved.emit = common.mustCall((name, err) => { | ||
| 61 | + assert.strictEqual(name, 'messageerror'); | ||
| 62 | + assert.strictEqual(err.code, 'ERR_MESSAGE_TARGET_CONTEXT_UNAVAILABLE'); | ||
| 63 | + }); | ||
| 58 | 64 | port2moved.start(); | |
| 59 | 65 | ||
| 60 | 66 | assert.notStrictEqual(fh.fd, -1); | |
| Back | FazBrowse Home | New Git URL |
0 commit comments