diff --git a/CHANGELOG.md b/CHANGELOG.md index dacf21bfd6be..1405d1269733 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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) diff --git a/packages/core-js/modules/es.aggregate-error.js b/packages/core-js/modules/es.aggregate-error.js index ea8dfefc6287..db20e13da535 100644 --- a/packages/core-js/modules/es.aggregate-error.js +++ b/packages/core-js/modules/es.aggregate-error.js @@ -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); diff --git a/tests/pure/es.aggregate-error.js b/tests/pure/es.aggregate-error.js index 0a3018ec7fbf..5cd4dd83aa0f 100644 --- a/tests/pure/es.aggregate-error.js +++ b/tests/pure/es.aggregate-error.js @@ -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); @@ -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'); }); diff --git a/tests/tests/es.aggregate-error.js b/tests/tests/es.aggregate-error.js index f4eee804a01d..430d0840ef56 100644 --- a/tests/tests/es.aggregate-error.js +++ b/tests/tests/es.aggregate-error.js @@ -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'); });