Skip to content

Commit

Permalink
refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
zloirock committed Oct 18, 2021
1 parent 36ab3ca commit 36e927d
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 9 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
'use strict';
var getBuiltIn = require('../internals/get-built-in');
var global = require('../internals/global');
var apply = require('../internals/function-apply');
var hasOwn = require('../internals/has-own-property');
var setPrototypeOf = require('../internals/object-set-prototype-of');
var copyConstructorProperties = require('../internals/copy-constructor-properties');
Expand All @@ -24,7 +25,7 @@ module.exports = function (ERROR_NAME, wrapper, FORCED, IS_AGGREGATE_ERROR) {
var BaseError = getBuiltIn('Error');

var WrappedError = wrapper(function () {
var result = OriginalError.apply(this, arguments);
var result = apply(OriginalError, this, arguments);
if (this && this !== global) inheritIfRequired(result, this, WrappedError);
if (arguments.length > OPTIONS_POSITION) installErrorCause(result, arguments[OPTIONS_POSITION]);
return result;
Expand Down
3 changes: 2 additions & 1 deletion packages/core-js/modules/esnext.aggregate-error.cause.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
var $ = require('../internals/export');
var getBuiltIn = require('../internals/get-built-in');
var apply = require('../internals/function-apply');
var wrapErrorConstructorWithCause = require('../internals/wrap-error-constructor-with-cause');

var AGGREGATE_ERROR = 'AggregateError';
Expand All @@ -9,6 +10,6 @@ var FORCED = $AggregateError && $AggregateError([1], 'e', { cause: 7 }).cause !=
$({ global: true, forced: FORCED }, {
AggregateError: wrapErrorConstructorWithCause(AGGREGATE_ERROR, function (init) {
// eslint-disable-next-line no-unused-vars -- required for functions `.length`
return function AggregateError(errors, message) { return init.apply(this, arguments); };
return function AggregateError(errors, message) { return apply(init, this, arguments); };
}, FORCED, true)
});
15 changes: 8 additions & 7 deletions packages/core-js/modules/esnext.error.cause.js
Original file line number Diff line number Diff line change
@@ -1,32 +1,33 @@
/* eslint-disable no-unused-vars -- required for functions `.length` */
var $ = require('../internals/export');
var apply = require('../internals/function-apply');
var wrapErrorConstructorWithCause = require('../internals/wrap-error-constructor-with-cause');

var FORCED = Error('e', { cause: 7 }).cause !== 7;

$({ global: true, forced: FORCED }, {
Error: wrapErrorConstructorWithCause('Error', function (init) {
return function Error(message) { return init.apply(this, arguments); };
return function Error(message) { return apply(init, this, arguments); };
}, FORCED)
});

$({ global: true, forced: FORCED }, {
EvalError: wrapErrorConstructorWithCause('EvalError', function (init) {
return function EvalError(message) { return init.apply(this, arguments); };
return function EvalError(message) { return apply(init, this, arguments); };
}, FORCED),
RangeError: wrapErrorConstructorWithCause('RangeError', function (init) {
return function RangeError(message) { return init.apply(this, arguments); };
return function RangeError(message) { return apply(init, this, arguments); };
}, FORCED),
ReferenceError: wrapErrorConstructorWithCause('ReferenceError', function (init) {
return function ReferenceError(message) { return init.apply(this, arguments); };
return function ReferenceError(message) { return apply(init, this, arguments); };
}, FORCED),
SyntaxError: wrapErrorConstructorWithCause('SyntaxError', function (init) {
return function SyntaxError(message) { return init.apply(this, arguments); };
return function SyntaxError(message) { return apply(init, this, arguments); };
}, FORCED),
TypeError: wrapErrorConstructorWithCause('TypeError', function (init) {
return function TypeError(message) { return init.apply(this, arguments); };
return function TypeError(message) { return apply(init, this, arguments); };
}, FORCED),
URIError: wrapErrorConstructorWithCause('URIError', function (init) {
return function URIError(message) { return init.apply(this, arguments); };
return function URIError(message) { return apply(init, this, arguments); };
}, FORCED)
});

0 comments on commit 36e927d

Please sign in to comment.