diff --git a/CHANGELOG b/CHANGELOG index 53dcf55..4e35e60 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,3 +1,5 @@ +* Fix issue where Object#isString and Object#isNumber return false for String and Number "wrapper" objects. (atrepp, Samuel Lebeau, Andrew Dupont) + * Set document.loaded = true before firing dom:loaded custom event. (Andrew Dupont) * Allow Element#store to accept an object containing several key/value pairs. (ZenCocoon, Andrew Dupont) diff --git a/src/lang/object.js b/src/lang/object.js index 5bf0860..4d49c31 100644 --- a/src/lang/object.js +++ b/src/lang/object.js @@ -83,11 +83,11 @@ } function isString(object) { - return typeof object === "string"; + return typeof (object && object.valueOf()) === "string"; } function isNumber(object) { - return typeof object === "number"; + return typeof (object && object.valueOf()) === "number"; } function isUndefined(object) { diff --git a/test/unit/object_test.js b/test/unit/object_test.js index 46fa047..df340a5 100644 --- a/test/unit/object_test.js +++ b/test/unit/object_test.js @@ -129,6 +129,7 @@ new Test.Unit.Runner({ testObjectIsString: function() { this.assert(!Object.isString(function() { })); this.assert(Object.isString("a string")); + this.assert(Object.isString(new String("a string"))); this.assert(!Object.isString(0)); this.assert(!Object.isString([])); this.assert(!Object.isString({})); @@ -139,7 +140,10 @@ new Test.Unit.Runner({ testObjectIsNumber: function() { this.assert(Object.isNumber(0)); this.assert(Object.isNumber(1.0)); + this.assert(Object.isNumber(new Number(0))); + this.assert(Object.isNumber(new Number(1.0))); this.assert(!Object.isNumber(function() { })); + this.assert(!Object.isNumber({ test: function() { return 3 } })); this.assert(!Object.isNumber("a string")); this.assert(!Object.isNumber([])); this.assert(!Object.isNumber({}));