Skip to content

Commit

Permalink
a workaround for a weird behavior of converting primitives to objects…
Browse files Browse the repository at this point in the history
… in JavaScriptCore
  • Loading branch information
jgonera committed Nov 30, 2011
1 parent 7a2940f commit 88306eb
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions lib/should.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,14 @@ exports.not.exist = function(obj, msg){
Object.defineProperty(Object.prototype, 'should', {
set: function(){},
get: function(){
// this is needed in JavaScriptCore, if not applied, primitives are
// converted to objects which results in weird stuff, e.g.
// AssertionError: expected { '0': 't', '1': 'e', '2': 's', '3': 't' } to equal 'test'
if (this instanceof String || this instanceof Number) {
return new assert.Assertion(this.constructor(this));
} else if (this instanceof Boolean) {
return new assert.Assertion(this == true);
}
return new Assertion(this);
},
configurable: true
Expand Down

0 comments on commit 88306eb

Please sign in to comment.