Skip to content

Commit

Permalink
add support of SuppressedError to structuredClone polyfill and si…
Browse files Browse the repository at this point in the history
…mplify it
  • Loading branch information
zloirock committed Oct 25, 2023
1 parent c6ea9f7 commit d6f71d1
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 29 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
## Changelog
##### Unreleased
- Simplified `structuredClone` polyfill, avoided second tree pass in cases of transferring
- Added support of `SuppressedError` to `structuredClone` polyfill
- Removed unspecified unnecessary `ArrayBuffer` and `DataView` dependencies of `structuredClone` lack of which could cause errors in some entries in IE10-
- Compat data improvements:
- Updated Opera Android 78 compat data mapping
Expand Down
39 changes: 10 additions & 29 deletions packages/core-js/modules/web.structured-clone.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
var IS_PURE = require('../internals/is-pure');
var $ = require('../internals/export');
var global = require('../internals/global');
var getBuiltin = require('../internals/get-built-in');
var getBuiltIn = require('../internals/get-built-in');
var uncurryThis = require('../internals/function-uncurry-this');
var fails = require('../internals/fails');
var uid = require('../internals/uid');
Expand Down Expand Up @@ -31,26 +31,17 @@ var Object = global.Object;
var Array = global.Array;
var Date = global.Date;
var Error = global.Error;
var EvalError = global.EvalError;
var RangeError = global.RangeError;
var ReferenceError = global.ReferenceError;
var SyntaxError = global.SyntaxError;
var TypeError = global.TypeError;
var URIError = global.URIError;
var PerformanceMark = global.PerformanceMark;
var WebAssembly = global.WebAssembly;
var CompileError = WebAssembly && WebAssembly.CompileError || Error;
var LinkError = WebAssembly && WebAssembly.LinkError || Error;
var RuntimeError = WebAssembly && WebAssembly.RuntimeError || Error;
var DOMException = getBuiltin('DOMException');
var DOMException = getBuiltIn('DOMException');
var Map = MapHelpers.Map;
var mapHas = MapHelpers.has;
var mapGet = MapHelpers.get;
var mapSet = MapHelpers.set;
var Set = SetHelpers.Set;
var setAdd = SetHelpers.add;
var setHas = SetHelpers.has;
var objectKeys = getBuiltin('Object', 'keys');
var objectKeys = getBuiltIn('Object', 'keys');
var push = uncurryThis([].push);
var thisBooleanValue = uncurryThis(true.valueOf);
var thisNumberValue = uncurryThis(1.0.valueOf);
Expand Down Expand Up @@ -227,34 +218,21 @@ var structuredCloneInternal = function (value, map) {
name = value.name;
switch (name) {
case 'AggregateError':
cloned = new (getBuiltin('AggregateError'))([]);
cloned = new (getBuiltIn(name))([]);
break;
case 'EvalError':
cloned = new EvalError();
break;
case 'RangeError':
cloned = new RangeError();
break;
case 'ReferenceError':
cloned = new ReferenceError();
break;
case 'SuppressedError':
case 'SyntaxError':
cloned = new SyntaxError();
break;
case 'TypeError':
cloned = new TypeError();
break;
case 'URIError':
cloned = new URIError();
cloned = new (getBuiltIn(name))();
break;
case 'CompileError':
cloned = new CompileError();
break;
case 'LinkError':
cloned = new LinkError();
break;
case 'RuntimeError':
cloned = new RuntimeError();
cloned = new (getBuiltIn('WebAssembly', name))();
break;
default:
cloned = new Error();
Expand Down Expand Up @@ -435,6 +413,9 @@ var structuredCloneInternal = function (value, map) {
}
if (name === 'AggregateError') {
cloned.errors = structuredCloneInternal(value.errors, map);
} else if (name === 'SuppressedError') {
cloned.error = structuredCloneInternal(value.error, map);
cloned.suppressed = structuredCloneInternal(value.suppressed, map);
} // break omitted
case 'DOMException':
if (ERROR_STACK_INSTALLABLE) {
Expand Down

0 comments on commit d6f71d1

Please sign in to comment.