From 958ebe41b684e9c93c37da811da138f8f45c7ec1 Mon Sep 17 00:00:00 2001 From: Denis Pushkarev Date: Thu, 23 Sep 2021 17:29:07 +0700 Subject: [PATCH] add `cause` to `AggregateError` constructor implementation (still without adding to the feature detection) --- CHANGELOG.md | 1 + packages/core-js/internals/install-error-cause.js | 11 +++++++++++ packages/core-js/modules/es.aggregate-error.js | 4 +++- 3 files changed, 15 insertions(+), 1 deletion(-) create mode 100644 packages/core-js/internals/install-error-cause.js diff --git a/CHANGELOG.md b/CHANGELOG.md index 25cda47f5c64..b1760f93be72 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,7 @@ ##### Unreleased - Fixed `String.prototype.substr` feature detection and compat data - Removed mistakenly added `.forEach` from prototypes of some DOM collections where it shouldn't be, [#988](https://github.com/zloirock/core-js/issues/988), [#987](https://github.com/zloirock/core-js/issues/987), thanks [@moorejs](https://github.com/moorejs) +- Added `cause` to `AggregateError` constructor implementation (still without adding to the feature detection) - Families of `.at` and `.findLast` methods marked as supported in Safari TP ##### 3.18.0 - 2021.09.20 diff --git a/packages/core-js/internals/install-error-cause.js b/packages/core-js/internals/install-error-cause.js new file mode 100644 index 000000000000..84bd2ab3a16d --- /dev/null +++ b/packages/core-js/internals/install-error-cause.js @@ -0,0 +1,11 @@ +var isObject = require('../internals/is-object'); +var has = require('../internals/has'); +var createNonEnumerableProperty = require('../internals/create-non-enumerable-property'); + +// `InstallErrorCause` abstract operation +// https://tc39.es/proposal-error-cause/#sec-errorobjects-install-error-cause +module.exports = function (O, options) { + if (isObject(options) && has(options, 'cause')) { + createNonEnumerableProperty(O, 'cause', O.cause); + } +}; diff --git a/packages/core-js/modules/es.aggregate-error.js b/packages/core-js/modules/es.aggregate-error.js index d6b1f9c40365..b06cacf3ae38 100644 --- a/packages/core-js/modules/es.aggregate-error.js +++ b/packages/core-js/modules/es.aggregate-error.js @@ -5,10 +5,11 @@ var setPrototypeOf = require('../internals/object-set-prototype-of'); var create = require('../internals/object-create'); var createNonEnumerableProperty = require('../internals/create-non-enumerable-property'); var createPropertyDescriptor = require('../internals/create-property-descriptor'); +var installErrorCause = require('../internals/install-error-cause'); var iterate = require('../internals/iterate'); var toString = require('../internals/to-string'); -var $AggregateError = function AggregateError(errors, message) { +var $AggregateError = function AggregateError(errors, message /* , options */) { var that = this; if (!(that instanceof $AggregateError)) return new $AggregateError(errors, message); if (setPrototypeOf) { @@ -16,6 +17,7 @@ var $AggregateError = function AggregateError(errors, message) { that = setPrototypeOf(new Error(undefined), getPrototypeOf(that)); } if (message !== undefined) createNonEnumerableProperty(that, 'message', toString(message)); + if (arguments.length > 2) installErrorCause(that, arguments[2]); var errorsArray = []; iterate(errors, errorsArray.push, { that: errorsArray }); createNonEnumerableProperty(that, 'errors', errorsArray);