Skip to content

Commit 3f8fee3

Browse files
committed
Forbid sending of Dicts and Streams, with postMessage, when workers are disabled
By default, i.e. with workers enabled, it's *purposely* not possible to send `Dict`s and `Stream`s from the worker-thread. This is achieved by defining a `function` on every `Dict` instance, since that ensures that [the structured clone algoritm](https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers_API/Structured_clone_algorithm) will throw an Error on `postMessage`. However, with workers *disabled* we fall-back to the `LoopbackPort` implementation which just ignores any `function`s, thus incorrectly allowing sending of data which *should* be unclonable.
1 parent cd909c5 commit 3f8fee3

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

src/display/api.js

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1463,8 +1463,14 @@ class LoopbackPort {
14631463
while (!(desc = Object.getOwnPropertyDescriptor(p, i))) {
14641464
p = Object.getPrototypeOf(p);
14651465
}
1466-
if (typeof desc.value === 'undefined' ||
1467-
typeof desc.value === 'function') {
1466+
if (typeof desc.value === 'undefined') {
1467+
continue;
1468+
}
1469+
if (typeof desc.value === 'function') {
1470+
if (value.hasOwnProperty && value.hasOwnProperty(i)) {
1471+
throw new Error(
1472+
`LoopbackPort.postMessage - cannot clone: ${value[i]}`);
1473+
}
14681474
continue;
14691475
}
14701476
result[i] = cloneValue(desc.value);

0 commit comments

Comments
 (0)