Skip to content

Commit fe3346f

Browse files
committed
Implement _.isError
1 parent 813d392 commit fe3346f

File tree

2 files changed

+17
-2
lines changed

2 files changed

+17
-2
lines changed

test/objects.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -437,6 +437,7 @@
437437
parent.iBoolean = new Boolean(false);\
438438
parent.iUndefined = undefined;\
439439
parent.iObject = {};\
440+
parent.iError = new Error();\
440441
</script>'
441442
);
442443
iDoc.close();
@@ -577,6 +578,20 @@
577578
ok(_.isUndefined(iUndefined), 'even from another frame');
578579
});
579580

581+
test('isError', function() {
582+
ok(!_.isError(1), 'numbers are not Errors');
583+
ok(!_.isError(null), 'null is not an Error');
584+
ok(!_.isError(Error), 'functions are not Errors');
585+
ok(_.isError(new Error()), 'Errors are Errors');
586+
ok(_.isError(iError), 'even from another frame');
587+
ok(_.isError(new EvalError()), 'EvalErrors are Errors');
588+
ok(_.isError(new RangeError()), 'RangeErrors are Errors');
589+
ok(_.isError(new ReferenceError()), 'ReferenceErrors are Errors');
590+
ok(_.isError(new SyntaxError()), 'SyntaxErrors are Errors');
591+
ok(_.isError(new TypeError()), 'TypeErrors are Errors');
592+
ok(_.isError(new URIError()), 'URIErrors are Errors');
593+
});
594+
580595
if (window.ActiveXObject) {
581596
test('IE host objects', function() {
582597
var xml = new ActiveXObject('Msxml2.DOMDocument.3.0');

underscore.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1029,8 +1029,8 @@
10291029
return obj === Object(obj);
10301030
};
10311031

1032-
// Add some isType methods: isArguments, isFunction, isString, isNumber, isDate, isRegExp.
1033-
_.each(['Arguments', 'Function', 'String', 'Number', 'Date', 'RegExp'], function(name) {
1032+
// Add some isType methods: isArguments, isFunction, isString, isNumber, isDate, isRegExp, isError.
1033+
_.each(['Arguments', 'Function', 'String', 'Number', 'Date', 'RegExp', 'Error'], function(name) {
10341034
_['is' + name] = function(obj) {
10351035
return toString.call(obj) == '[object ' + name + ']';
10361036
};

0 commit comments

Comments
 (0)