Support Map
and Set
, with postMessage
, when workers are disabled
The `LoopbackPort` currently doesn't support `Map` and `Set`, which it should since the "structured clone algorithm" used in browsers does support both of them; please see https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers_API/Structured_clone_algorithm#supported_types
This commit is contained in:
parent
952bc08ec0
commit
73bf45e64b
@ -1656,8 +1656,24 @@ class LoopbackPort {
|
|||||||
cloned.set(value, result);
|
cloned.set(value, result);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
if (value instanceof Map) {
|
||||||
|
result = new Map();
|
||||||
|
cloned.set(value, result); // Adding to cache now for cyclic references.
|
||||||
|
for (const [key, val] of value) {
|
||||||
|
result.set(key, cloneValue(val));
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
if (value instanceof Set) {
|
||||||
|
result = new Set();
|
||||||
|
cloned.set(value, result); // Adding to cache now for cyclic references.
|
||||||
|
for (const val of value) {
|
||||||
|
result.add(cloneValue(val));
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
result = Array.isArray(value) ? [] : {};
|
result = Array.isArray(value) ? [] : {};
|
||||||
cloned.set(value, result); // adding to cache now for cyclic references
|
cloned.set(value, result); // Adding to cache now for cyclic references.
|
||||||
// Cloning all value and object properties, however ignoring properties
|
// Cloning all value and object properties, however ignoring properties
|
||||||
// defined via getter.
|
// defined via getter.
|
||||||
for (const i in value) {
|
for (const i in value) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user