Skip to content

Commit

Permalink
Further fix to ensure Object#is(String|Number) do not throw exception…
Browse files Browse the repository at this point in the history
…s on host objects in IE. [#510 state:resolved]
  • Loading branch information
savetheclocktower committed Jan 5, 2009
1 parent 9f5c40c commit 31d1c6f
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 2 deletions.
2 changes: 2 additions & 0 deletions 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)
Expand Down
12 changes: 10 additions & 2 deletions src/lang/object.js
Expand Up @@ -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) {
Expand Down
2 changes: 2 additions & 0 deletions test/unit/object_test.js
Expand Up @@ -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() {
Expand All @@ -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() {
Expand Down

0 comments on commit 31d1c6f

Please sign in to comment.