fix: custom instOfHandler result should be cast to boolean (#10197)

This commit is contained in:
Huáng Jùnliàng 2019-07-10 17:38:46 -04:00 committed by Nicolò Ribaudo
parent 4eab157502
commit e88a569e83
2 changed files with 6 additions and 1 deletions

View File

@ -587,7 +587,7 @@ helpers.wrapNativeSuper = helper("7.0.0-beta.0")`
helpers.instanceof = helper("7.0.0-beta.0")`
export default function _instanceof(left, right) {
if (right != null && typeof Symbol !== "undefined" && right[Symbol.hasInstance]) {
return right[Symbol.hasInstance](left);
return !!right[Symbol.hasInstance](left);
} else {
return left instanceof right;
}

View File

@ -4,6 +4,11 @@ foo[Symbol.hasInstance]= function () { return true; };
var bar = {};
expect(bar instanceof foo).toBe(true);
var qux = {};
qux[Symbol.hasInstance]= function () { return NaN };
expect(bar instanceof qux).toBe(false);
expect(new String).toBeInstanceOf(String);
//