Ensure Object.isElement handles "falsy" values properly.

This commit is contained in:
Andrew Dupont 2008-05-30 10:32:28 -05:00 committed by Tobie Langel
parent c01d1a26f7
commit d88c25fd47
3 changed files with 10 additions and 1 deletions

View File

@ -1,3 +1,5 @@
* Ensure Object.isElement handles "falsy" values properly. (kangax)
* Fix exiting test task on INT signal. (Samuel Lebeau)
* Fix unit test freeze in IE. (Tobie Langel)

View File

@ -129,7 +129,7 @@ Object.extend(Object, {
},
isElement: function(object) {
return object && object.nodeType == 1;
return !!(object && object.nodeType == 1);
},
isArray: function(object) {

View File

@ -207,6 +207,13 @@ new Test.Unit.Runner({
this.assert(Object.isElement(new Element('div')));
this.assert(Object.isElement($('testlog')));
this.assert(!Object.isElement(document.createTextNode('bla')));
// falsy variables should not mess up return value type
this.assertIdentical(false, Object.isElement(0));
this.assertIdentical(false, Object.isElement(''));
this.assertIdentical(false, Object.isElement(NaN));
this.assertIdentical(false, Object.isElement(null));
this.assertIdentical(false, Object.isElement(undefined));
},
testObjectIsFunction: function() {