diff --git a/CHANGELOG b/CHANGELOG index 066785e..889f9b0 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,3 +1,5 @@ +* Further fix to ensure Object#is(String|Number) do not throw exceptions on host objects in IE. (grepmaster, kangax, Tobie Langel, Andrew Dupont) + * Ensure Enumerable#grep can handle strings with RegExp metacharacters. (Marton Kiss-Albert, kangax) * Switch to the "doScroll approach" for the dom:loaded custom event. (javier, Diego Perini, Nick Stakenburg, Andrew Dupont) diff --git a/src/lang/object.js b/src/lang/object.js index 4d49c31..19be092 100644 --- a/src/lang/object.js +++ b/src/lang/object.js @@ -83,11 +83,19 @@ } function isString(object) { - return typeof (object && object.valueOf()) === "string"; + try { + return typeof (object && object.valueOf()) === "string"; + } catch(e) { + return false; + } } function isNumber(object) { - return typeof (object && object.valueOf()) === "number"; + try { + return typeof (object && object.valueOf()) === "number"; + } catch(e) { + return false; + } } function isUndefined(object) { diff --git a/test/unit/object_test.js b/test/unit/object_test.js index df340a5..37d62ab 100644 --- a/test/unit/object_test.js +++ b/test/unit/object_test.js @@ -135,6 +135,7 @@ new Test.Unit.Runner({ this.assert(!Object.isString({})); this.assert(!Object.isString(false)); this.assert(!Object.isString(undefined)); + this.assert(!Object.isString(document), 'host objects should return false rather than throw exceptions'); }, testObjectIsNumber: function() { @@ -149,6 +150,7 @@ new Test.Unit.Runner({ this.assert(!Object.isNumber({})); this.assert(!Object.isNumber(false)); this.assert(!Object.isNumber(undefined)); + this.assert(!Object.isNumber(document), 'host objects should return false rather than throw exceptions'); }, testObjectIsUndefined: function() {