Skip to content

Commit 407c317

Browse files
committed
merge iserror
2 parents 9ae4ad4 + fe3346f commit 407c317

File tree

2 files changed

+32
-17
lines changed

2 files changed

+32
-17
lines changed

test/objects.js

Lines changed: 30 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -483,21 +483,22 @@
483483
document.body.appendChild(iframe);
484484
var iDoc = (iDoc = iframe.contentDocument || iframe.contentWindow).document || iDoc;
485485
iDoc.write(
486-
'<script>' +
487-
' parent.iElement = document.createElement("div");' +
488-
' parent.iArguments = (function(){ return arguments; })(1, 2, 3);' +
489-
' parent.iArray = [1, 2, 3];' +
490-
' parent.iString = new String("hello");' +
491-
' parent.iNumber = new Number(100);' +
492-
' parent.iFunction = (function(){});' +
493-
' parent.iDate = new Date();' +
494-
' parent.iRegExp = /hi/;' +
495-
' parent.iNaN = NaN;' +
496-
' parent.iNull = null;' +
497-
' parent.iBoolean = new Boolean(false);' +
498-
' parent.iUndefined = undefined;' +
499-
' parent.iObject = {};' +
500-
'</script>'
486+
'<script>\
487+
parent.iElement = document.createElement("div");\
488+
parent.iArguments = (function(){ return arguments; })(1, 2, 3);\
489+
parent.iArray = [1, 2, 3];\
490+
parent.iString = new String("hello");\
491+
parent.iNumber = new Number(100);\
492+
parent.iFunction = (function(){});\
493+
parent.iDate = new Date();\
494+
parent.iRegExp = /hi/;\
495+
parent.iNaN = NaN;\
496+
parent.iNull = null;\
497+
parent.iBoolean = new Boolean(false);\
498+
parent.iUndefined = undefined;\
499+
parent.iObject = {};\
500+
parent.iError = new Error();\
501+
</script>'
501502
);
502503
iDoc.close();
503504

@@ -638,6 +639,20 @@
638639
ok(_.isUndefined(iUndefined), 'even from another frame');
639640
});
640641

642+
test('isError', function() {
643+
ok(!_.isError(1), 'numbers are not Errors');
644+
ok(!_.isError(null), 'null is not an Error');
645+
ok(!_.isError(Error), 'functions are not Errors');
646+
ok(_.isError(new Error()), 'Errors are Errors');
647+
ok(_.isError(iError), 'even from another frame');
648+
ok(_.isError(new EvalError()), 'EvalErrors are Errors');
649+
ok(_.isError(new RangeError()), 'RangeErrors are Errors');
650+
ok(_.isError(new ReferenceError()), 'ReferenceErrors are Errors');
651+
ok(_.isError(new SyntaxError()), 'SyntaxErrors are Errors');
652+
ok(_.isError(new TypeError()), 'TypeErrors are Errors');
653+
ok(_.isError(new URIError()), 'URIErrors are Errors');
654+
});
655+
641656
if (window.ActiveXObject) {
642657
test('IE host objects', function() {
643658
var xml = new ActiveXObject('Msxml2.DOMDocument.3.0');

underscore.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1111,8 +1111,8 @@
11111111
return type === 'function' || type === 'object' && !!obj;
11121112
};
11131113

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

0 commit comments

Comments
 (0)