Skip to content

Commit

Permalink
Ensure Object.isElement handles "falsy" values properly.
Browse files Browse the repository at this point in the history
  • Loading branch information
savetheclocktower authored and tobie committed Sep 8, 2008
1 parent c01d1a2 commit d88c25f
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 1 deletion.
2 changes: 2 additions & 0 deletions CHANGELOG
@@ -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)
Expand Down
2 changes: 1 addition & 1 deletion src/base.js
Expand Up @@ -129,7 +129,7 @@ Object.extend(Object, {
},

isElement: function(object) {
return object && object.nodeType == 1;
return !!(object && object.nodeType == 1);
},

isArray: function(object) {
Expand Down
7 changes: 7 additions & 0 deletions test/unit/base_test.js
Expand Up @@ -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() {
Expand Down

0 comments on commit d88c25f

Please sign in to comment.