Skip to content

Commit

Permalink
[Fix] in IE 8, TypeError does not inherit from Error
Browse files Browse the repository at this point in the history
  • Loading branch information
ljharb committed Feb 14, 2024
1 parent 82e7d71 commit 93c1d12
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion lib/test.js
Expand Up @@ -35,6 +35,20 @@ var nextTick = typeof setImmediate !== 'undefined'
var safeSetTimeout = setTimeout;
var safeClearTimeout = clearTimeout;

var isErrorConstructor = isProto(Error, TypeError) // IE 8 is `false` here
? function isErrorConstructor(C) {
return isProto(Error, C);
}
: function isErrorConstructor(C) {
return isProto(Error, C)
|| isProto(TypeError, C)
|| isProto(RangeError, C)
|| isProto(SyntaxError, C)
|| isProto(ReferenceError, C)
|| isProto(EvalError, C)
|| isProto(URIError, C);
};

// eslint-disable-next-line no-unused-vars
function getTestArgs(name_, opts_, cb_) {
var name = '(anonymous)';
Expand Down Expand Up @@ -829,7 +843,7 @@ Test.prototype['throws'] = function (fn, expected, msg, extra) {
if (typeof expected === 'function') {
if (typeof expected.prototype !== 'undefined' && caught.error instanceof expected) {
passed = true;
} else if (isProto(Error, expected)) {
} else if (isErrorConstructor(expected)) {
passed = false;
} else {
passed = expected.call({}, caught.error) === true;
Expand Down

0 comments on commit 93c1d12

Please sign in to comment.