Skip to content

Commit

Permalink
a little more correct workaround of File cloning bug
Browse files Browse the repository at this point in the history
  • Loading branch information
zloirock committed Apr 30, 2023
1 parent 5d18ee0 commit 0d0f205
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions packages/core-js/modules/web.structured-clone.js
Original file line number Diff line number Diff line change
Expand Up @@ -253,13 +253,17 @@ var structuredCloneInternal = function (value, map) {
cloned = tryNativeRestrictedStructuredClone(value, type);
}
break;
// NodeJS 20.0.0 bug, https://github.com/nodejs/node/issues/47612
case 'File':
try {
if (nativeRestrictedStructuredClone) try {
cloned = nativeRestrictedStructuredClone(value);
// NodeJS 20.0.0 bug, https://github.com/nodejs/node/issues/47612
if (classof(cloned) !== type) cloned = undefined;
} catch (error) { /* empty */ }
if (!cloned) try {
cloned = new File([value], value.name, value);
} catch (error) {
cloned = tryNativeRestrictedStructuredClone(value, type);
} break;
} catch (error) { /* empty */ }
if (!cloned) throwUnpolyfillable(type);
break;
case 'FileList':
dataTransfer = createDataTransfer();
if (dataTransfer) {
Expand Down

0 comments on commit 0d0f205

Please sign in to comment.