Merge pull request #13658 from Snuffleupagus/cloneValue
Don't attempt to structure clone unsupported types with workers disabled
This commit is contained in:
commit
f9d506cf50
@ -1805,6 +1805,16 @@ class LoopbackPort {
|
|||||||
function cloneValue(value) {
|
function cloneValue(value) {
|
||||||
// Trying to perform a structured clone close to the spec, including
|
// Trying to perform a structured clone close to the spec, including
|
||||||
// transfers.
|
// transfers.
|
||||||
|
if (
|
||||||
|
typeof value === "function" ||
|
||||||
|
typeof value === "symbol" ||
|
||||||
|
value instanceof URL
|
||||||
|
) {
|
||||||
|
throw new Error(
|
||||||
|
`LoopbackPort.postMessage - cannot clone: ${value?.toString()}`
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
if (typeof value !== "object" || value === null) {
|
if (typeof value !== "object" || value === null) {
|
||||||
return value;
|
return value;
|
||||||
}
|
}
|
||||||
@ -1843,9 +1853,6 @@ class LoopbackPort {
|
|||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
if (value instanceof URL) {
|
|
||||||
throw new Error(`LoopbackPort.postMessage - cannot clone: ${value}`);
|
|
||||||
}
|
|
||||||
result = Array.isArray(value) ? [] : Object.create(null);
|
result = Array.isArray(value) ? [] : Object.create(null);
|
||||||
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
|
||||||
@ -1859,12 +1866,7 @@ class LoopbackPort {
|
|||||||
if (typeof desc.value === "undefined") {
|
if (typeof desc.value === "undefined") {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (typeof desc.value === "function") {
|
if (typeof desc.value === "function" && !value.hasOwnProperty?.(i)) {
|
||||||
if (value.hasOwnProperty?.(i)) {
|
|
||||||
throw new Error(
|
|
||||||
`LoopbackPort.postMessage - cannot clone: ${value[i]}`
|
|
||||||
);
|
|
||||||
}
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
result[i] = cloneValue(desc.value);
|
result[i] = cloneValue(desc.value);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user