diff --git a/CHANGELOG b/CHANGELOG index 94d3094..c76abce 100644 --- a/CHANGELOG +++ b/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) diff --git a/src/base.js b/src/base.js index df1b97e..c2a1443 100644 --- a/src/base.js +++ b/src/base.js @@ -129,7 +129,7 @@ Object.extend(Object, { }, isElement: function(object) { - return object && object.nodeType == 1; + return !!(object && object.nodeType == 1); }, isArray: function(object) { diff --git a/test/unit/base_test.js b/test/unit/base_test.js index 9b13849..25e163a 100644 --- a/test/unit/base_test.js +++ b/test/unit/base_test.js @@ -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() {