Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 1 commit into from Jul 10, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/babel-helpers/src/helpers.js
Expand Up @@ -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;
}
Expand Down
Expand Up @@ -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);

//
Expand Down