Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't attempt to structure clone unsupported types with workers disabled #13658

Merged
merged 1 commit into from
Jul 3, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 11 additions & 9 deletions src/display/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -1805,6 +1805,16 @@ class LoopbackPort {
function cloneValue(value) {
// Trying to perform a structured clone close to the spec, including
// 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) {
return value;
}
Expand Down Expand Up @@ -1843,9 +1853,6 @@ class LoopbackPort {
}
return result;
}
if (value instanceof URL) {
throw new Error(`LoopbackPort.postMessage - cannot clone: ${value}`);
}
result = Array.isArray(value) ? [] : Object.create(null);
cloned.set(value, result); // Adding to cache now for cyclic references.
// Cloning all value and object properties, however ignoring properties
Expand All @@ -1859,12 +1866,7 @@ class LoopbackPort {
if (typeof desc.value === "undefined") {
continue;
}
if (typeof desc.value === "function") {
if (value.hasOwnProperty?.(i)) {
throw new Error(
`LoopbackPort.postMessage - cannot clone: ${value[i]}`
);
}
if (typeof desc.value === "function" && !value.hasOwnProperty?.(i)) {
continue;
}
result[i] = cloneValue(desc.value);
Expand Down