Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit d7641d8

Browse filesBrowse files
addaleaxBridgeAR
authored andcommitted
worker: use DataCloneError for unknown native objects
This aligns the behaviour better with the web. PR-URL: #28025 Reviewed-By: Michaël Zasso <targos@protonmail.com> Reviewed-By: Rich Trott <rtrott@gmail.com> Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Tiancheng "Timothy" Gu <timothygu99@gmail.com>
1 parent 5fc4e48 commit d7641d8
Copy full SHA for d7641d8

File tree

Expand file treeCollapse file tree

5 files changed

+49
-9
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

5 files changed

+49
-9
lines changed
Open diff view settings
Collapse file

‎doc/api/errors.md‎

Copy file name to clipboardExpand all lines: doc/api/errors.md
+10-6Lines changed: 10 additions & 6 deletions
  • Display the source diff
  • Display the rich diff
Original file line numberDiff line numberDiff line change
@@ -671,12 +671,6 @@ An operation outside the bounds of a `Buffer` was attempted.
671671
An attempt has been made to create a `Buffer` larger than the maximum allowed
672672
size.
673673

674-
<a id="ERR_CANNOT_TRANSFER_OBJECT"></a>
675-
### ERR_CANNOT_TRANSFER_OBJECT
676-
677-
The value passed to `postMessage()` contained an object that is not supported
678-
for transferring.
679-
680674
<a id="ERR_CANNOT_WATCH_SIGINT"></a>
681675
### ERR_CANNOT_WATCH_SIGINT
682676

@@ -2013,6 +2007,16 @@ A module file could not be resolved while attempting a [`require()`][] or
20132007
> Stability: 0 - Deprecated. These error codes are either inconsistent, or have
20142008
> been removed.
20152009
2010+
<a id="ERR_CANNOT_TRANSFER_OBJECT"></a>
2011+
### ERR_CANNOT_TRANSFER_OBJECT
2012+
<!--
2013+
added: v10.5.0
2014+
removed: REPLACEME
2015+
-->
2016+
2017+
The value passed to `postMessage()` contained an object that is not supported
2018+
for transferring.
2019+
20162020
<a id="ERR_CLOSED_MESSAGE_PORT"></a>
20172021
### ERR_CLOSED_MESSAGE_PORT
20182022
<!-- YAML
Collapse file

‎src/env.h‎

Copy file name to clipboardExpand all lines: src/env.h
+1Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,7 @@ constexpr size_t kFsStatsBufferLength = kFsStatsFieldsNumber * 2;
158158
V(change_string, "change") \
159159
V(channel_string, "channel") \
160160
V(chunks_sent_since_last_write_string, "chunksSentSinceLastWrite") \
161+
V(clone_unsupported_type_str, "Cannot transfer object of unsupported type.") \
161162
V(code_string, "code") \
162163
V(commonjs_string, "commonjs") \
163164
V(config_string, "config") \
Collapse file

‎src/node_errors.h‎

Copy file name to clipboardExpand all lines: src/node_errors.h
-2Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,6 @@ void FatalException(v8::Isolate* isolate,
5454
V(ERR_BUFFER_CONTEXT_NOT_AVAILABLE, Error) \
5555
V(ERR_BUFFER_OUT_OF_BOUNDS, RangeError) \
5656
V(ERR_BUFFER_TOO_LARGE, Error) \
57-
V(ERR_CANNOT_TRANSFER_OBJECT, TypeError) \
5857
V(ERR_CONSTRUCT_CALL_REQUIRED, Error) \
5958
V(ERR_INVALID_ARG_VALUE, TypeError) \
6059
V(ERR_INVALID_ARG_TYPE, TypeError) \
@@ -100,7 +99,6 @@ void FatalException(v8::Isolate* isolate,
10099
#define PREDEFINED_ERROR_MESSAGES(V) \
101100
V(ERR_BUFFER_CONTEXT_NOT_AVAILABLE, \
102101
"Buffer is not available for the current Context") \
103-
V(ERR_CANNOT_TRANSFER_OBJECT, "Cannot transfer object of unsupported type")\
104102
V(ERR_CONSTRUCT_CALL_REQUIRED, "Cannot call constructor without `new`") \
105103
V(ERR_INVALID_TRANSFER_OBJECT, "Found invalid object in transferList") \
106104
V(ERR_MEMORY_ALLOCATION_FAILED, "Failed to allocate memory") \
Collapse file

‎src/node_messaging.cc‎

Copy file name to clipboardExpand all lines: src/node_messaging.cc
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -232,7 +232,7 @@ class SerializerDelegate : public ValueSerializer::Delegate {
232232
return WriteMessagePort(Unwrap<MessagePort>(object));
233233
}
234234

235-
THROW_ERR_CANNOT_TRANSFER_OBJECT(env_);
235+
ThrowDataCloneError(env_->clone_unsupported_type_str());
236236
return Nothing<bool>();
237237
}
238238

Collapse file
+37Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
// Flags: --expose-internals
2+
'use strict';
3+
const common = require('../common');
4+
const assert = require('assert');
5+
const { MessageChannel } = require('worker_threads');
6+
const { internalBinding } = require('internal/test/binding');
7+
8+
// Test that passing native objects and functions to .postMessage() throws
9+
// DataCloneError exceptions.
10+
11+
{
12+
const { port1, port2 } = new MessageChannel();
13+
port2.once('message', common.mustNotCall());
14+
15+
assert.throws(() => {
16+
port1.postMessage(function foo() {});
17+
}, {
18+
name: 'DataCloneError',
19+
message: /function foo\(\) \{\} could not be cloned\.$/
20+
});
21+
port1.close();
22+
}
23+
24+
{
25+
const { port1, port2 } = new MessageChannel();
26+
port2.once('message', common.mustNotCall());
27+
28+
const nativeObject = new (internalBinding('js_stream').JSStream)();
29+
30+
assert.throws(() => {
31+
port1.postMessage(nativeObject);
32+
}, {
33+
name: 'DataCloneError',
34+
message: /Cannot transfer object of unsupported type\.$/
35+
});
36+
port1.close();
37+
}

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.