Skip to content

Commit

Permalink
add cause to AggregateError constructor implementation (still wit…
Browse files Browse the repository at this point in the history
…hout adding to the feature detection)
  • Loading branch information
zloirock committed Sep 23, 2021
1 parent e3a4f75 commit 958ebe4
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Expand Up @@ -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
Expand Down
11 changes: 11 additions & 0 deletions 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);
}
};
4 changes: 3 additions & 1 deletion packages/core-js/modules/es.aggregate-error.js
Expand Up @@ -5,17 +5,19 @@ 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) {
// eslint-disable-next-line unicorn/error-message -- expected
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);
Expand Down

0 comments on commit 958ebe4

Please sign in to comment.