Skip to content

Commit

Permalink
Use try/catch for a more reliable isBoolean check, even with ES6 @@to…
Browse files Browse the repository at this point in the history
…StringTag
  • Loading branch information
ljharb committed Jan 28, 2015
1 parent c0be34d commit 612bf6b
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,15 @@ if (!getPrototypeOf) {
}
}

var boolType = '[object Boolean]';
var booleanValue = Boolean.prototype.valueOf;
var isBoolean = function isBoolean(value) {
try {
booleanValue.call(value);
return true;
} catch (e) {
return false;
}
};
var stringType = '[object String]';
var arrayType = '[object Array]';
var funcType = '[object Function]';
Expand All @@ -49,7 +57,11 @@ module.exports = function isEqual(value, other) {
var type = toStr.call(value);
if (type !== toStr.call(other)) { return false; }

if (type === boolType) { return value.valueOf() === other.valueOf(); }
var valIsBool = isBoolean(value);
var otherIsBool = isBoolean(other);
if (valIsBool || otherIsBool) {
return valIsBool && otherIsBool && booleanValue.call(value) === booleanValue.call(other);
}

var valIsNumber = isNumber(value);
var otherIsNumber = isNumber(value);
Expand Down

0 comments on commit 612bf6b

Please sign in to comment.