Skip to content

Commit 696feb8

Browse files
committed
add Error.isError
1 parent 97df970 commit 696feb8

File tree

8 files changed

+57
-0
lines changed

8 files changed

+57
-0
lines changed

packages/core-js-compat/src/data.mjs

+2
Original file line numberDiff line numberDiff line change
@@ -2241,6 +2241,8 @@ export const data = {
22412241
// reverted in https://issues.chromium.org/issues/42203506#comment25
22422242
// chrome: '133',
22432243
},
2244+
'esnext.error.is-error': {
2245+
},
22442246
'esnext.function.demethodize': {
22452247
},
22462248
'esnext.function.is-callable': {

packages/core-js-compat/src/modules-by-versions.mjs

+3
Original file line numberDiff line numberDiff line change
@@ -274,4 +274,7 @@ export default {
274274
'esnext.weak-map.get-or-insert',
275275
'esnext.weak-map.get-or-insert-computed',
276276
],
277+
'3.40': [
278+
'esnext.error.is-error',
279+
],
277280
};
+2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
'use strict';
22
var parent = require('../../stable/error');
3+
require('../../modules/es.object.create');
4+
require('../../modules/esnext.error.is-error');
35

46
module.exports = parent;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
'use strict';
2+
require('../../modules/es.object.create');
3+
require('../../modules/esnext.error.is-error');
4+
var path = require('../../internals/path');
5+
6+
module.exports = path.Error.isError;
+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
'use strict';
2+
var parent = require('../../actual/error/is-error');
3+
4+
module.exports = parent;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
'use strict';
2+
var $ = require('../internals/export');
3+
var getBuiltIn = require('../internals/get-built-in');
4+
var isObject = require('../internals/is-object');
5+
var classof = require('../internals/classof');
6+
var fails = require('../internals/fails');
7+
8+
var ERROR = 'Error';
9+
var DOM_EXCEPTION = 'DOMException';
10+
// eslint-disable-next-line es/no-object-setprototypeof, no-proto -- safe
11+
var PROTOTYPE_SETTING_AVAILABLE = Object.setPrototypeOf || ({}).__proto__;
12+
13+
var DOMException = getBuiltIn(DOM_EXCEPTION);
14+
var $Error = Error;
15+
var $isError = $Error.isError;
16+
17+
var FORCED = !$isError || !PROTOTYPE_SETTING_AVAILABLE || fails(function () {
18+
// Bun, isNativeError-based implementations, some buggy structuredClone-based implementations, etc.
19+
// https://github.com/oven-sh/bun/issues/15821
20+
return (DOMException && !$isError(new DOMException(DOM_EXCEPTION))) ||
21+
// structuredClone-based implementations
22+
// eslint-disable-next-line es/no-error-cause -- detection
23+
!$isError(new $Error(ERROR, { cause: function () { /* empty */ } })) ||
24+
// instanceof-based and FF Error#stack-based implementations
25+
$isError(getBuiltIn('Object', 'create')($Error.prototype));
26+
});
27+
28+
// `Error.isError` method
29+
// https://github.com/tc39/proposal-is-error
30+
$({ target: 'Error', stat: true, sham: true, forced: FORCED }, {
31+
isError: function isError(arg) {
32+
if (!isObject(arg)) return false;
33+
var tag = classof(arg);
34+
return tag === ERROR || tag === DOM_EXCEPTION;
35+
}
36+
});
+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
'use strict';
2+
// https://github.com/tc39/proposal-is-error
3+
require('../modules/esnext.error.is-error');

packages/core-js/stage/3.js

+1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ require('../proposals/array-from-async-stage-2');
66
require('../proposals/decorator-metadata-v2');
77
require('../proposals/explicit-resource-management');
88
require('../proposals/float16');
9+
require('../proposals/is-error');
910
require('../proposals/json-parse-with-source');
1011
require('../proposals/math-sum');
1112
require('../proposals/regexp-escaping');

0 commit comments

Comments
 (0)