Skip to content

Commit

Permalink
implement Error cloning
Browse files Browse the repository at this point in the history
I'm not 100% sure stack cloning would work everywhere, but it seems to
work on Firefox and Chrome and Node.js.
  • Loading branch information
BasixKOR committed Sep 15, 2021
1 parent 1b01d70 commit 4b3b21e
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions packages/core-js/internals/structured-clone.js
@@ -1,7 +1,5 @@
/* eslint-disable es/no-map -- safe */
/* eslint-disable es/no-set -- safe */
/* eslint-disable no-new-wrappers -- safe */
/* eslint-disable es/no-bigint -- safe */
'use const';
var isSymbol = require('./is-symbol');
var toObject = require('./to-object');
Expand Down Expand Up @@ -50,6 +48,16 @@ module.exports = function structuredCloneInternal(weakmap, value) {
cloned = new Set();
deep = true;
break;
case 'Error':
case 'EvalError':
case 'RangeError':
case 'ReferenceError':
case 'SyntaxError':
case 'TypeError':
case 'URIError':
cloned = value.constructor(value.message.toString());
// Note: `error.stack` will point structuredClone, since there are no reliable way to modify it.
break;
case 'Array':
cloned = [];
deep = true;
Expand Down

0 comments on commit 4b3b21e

Please sign in to comment.