From 3f8fee371b4f8f9ba115b73febd649d062125986 Mon Sep 17 00:00:00 2001 From: Jonas Jenwald Date: Thu, 26 Sep 2019 16:04:41 +0200 Subject: [PATCH] Forbid sending of `Dict`s and `Stream`s, 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. --- src/display/api.js | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/display/api.js b/src/display/api.js index 6c3487803..5dc140d66 100644 --- a/src/display/api.js +++ b/src/display/api.js @@ -1463,8 +1463,14 @@ class LoopbackPort { while (!(desc = Object.getOwnPropertyDescriptor(p, i))) { p = Object.getPrototypeOf(p); } - if (typeof desc.value === 'undefined' || - typeof desc.value === 'function') { + if (typeof desc.value === 'undefined') { + continue; + } + if (typeof desc.value === 'function') { + if (value.hasOwnProperty && value.hasOwnProperty(i)) { + throw new Error( + `LoopbackPort.postMessage - cannot clone: ${value[i]}`); + } continue; } result[i] = cloneValue(desc.value);