Skip to content

Commit

Permalink
fix Object#toString on AggregateError in IE10-
Browse files Browse the repository at this point in the history
  • Loading branch information
zloirock committed Nov 1, 2021
1 parent 9dae65f commit 50da74b
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 3 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
## Changelog
##### Unreleased
- Fixed `Object#toString` on `AggregateError` in IE10-
- `.findLast` methods family marked as supported [from Chrome 97](https://chromestatus.com/features#milestone%3D97)
- Fixed inheritance of Electron compat data `web.` modules
- Fixed Safari 15.1 compat data (some features were not added)
Expand Down
12 changes: 9 additions & 3 deletions packages/core-js/modules/es.aggregate-error.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,23 @@ var clearErrorStack = require('../internals/clear-error-stack');
var installErrorCause = require('../internals/install-error-cause');
var iterate = require('../internals/iterate');
var normalizeStringArgument = require('../internals/normalize-string-argument');
var wellKnownSymbol = require('../internals/well-known-symbol');
var ERROR_STACK_INSTALLABLE = require('../internals/error-stack-installable');

var TO_STRING_TAG = wellKnownSymbol('toStringTag');
var Error = global.Error;
var push = [].push;

var $AggregateError = function AggregateError(errors, message /* , options */) {
var options = arguments.length > 2 ? arguments[2] : undefined;
var isInstance = isPrototypeOf(AggregateErrorPrototype, this);
var that = setPrototypeOf
? setPrototypeOf(new Error(undefined), isInstance ? getPrototypeOf(this) : AggregateErrorPrototype)
: isInstance ? this : create(AggregateErrorPrototype);
var that;
if (setPrototypeOf) {
that = setPrototypeOf(new Error(undefined), isInstance ? getPrototypeOf(this) : AggregateErrorPrototype);
} else {
that = isInstance ? this : create(AggregateErrorPrototype);
createNonEnumerableProperty(that, TO_STRING_TAG, 'Error');
}
createNonEnumerableProperty(that, 'message', normalizeStringArgument(message, ''));
if (ERROR_STACK_INSTALLABLE) createNonEnumerableProperty(that, 'stack', clearErrorStack(that.stack, 1));
installErrorCause(that, options);
Expand Down
2 changes: 2 additions & 0 deletions tests/pure/es.aggregate-error.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import AggregateError from 'core-js-pure/es/aggregate-error';
import Symbol from 'core-js-pure/es/symbol';
import toString from 'core-js-pure/es/object/to-string';

QUnit.test('AggregateError', assert => {
assert.isFunction(AggregateError);
Expand All @@ -14,4 +15,5 @@ QUnit.test('AggregateError', assert => {
assert.same(AggregateError([1]).message, '');
assert.deepEqual(AggregateError([1, 2, 3]).errors, [1, 2, 3]);
assert.throws(() => AggregateError([1], Symbol()), 'throws on symbol as a message');
assert.same(toString(AggregateError([1])), '[object Error]', 'Object#toString');
});
1 change: 1 addition & 0 deletions tests/tests/es.aggregate-error.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,5 @@ QUnit.test('AggregateError', assert => {
assert.same(AggregateError([1]).message, '');
assert.deepEqual(AggregateError([1, 2, 3]).errors, [1, 2, 3]);
assert.throws(() => AggregateError([1], Symbol()), 'throws on symbol as a message');
assert.same(({}).toString.call(AggregateError([1])), '[object Error]', 'Object#toString');
});

0 comments on commit 50da74b

Please sign in to comment.