-
Notifications
You must be signed in to change notification settings - Fork 550
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
replace instanceof in brand checks with isPrototypeOf #3692
replace instanceof in brand checks with isPrototypeOf #3692
Conversation
const headersToBrandCheck = globalThis.Headers | ||
? [Headers, globalThis.Headers] | ||
: [Headers] | ||
const brandChecks = webidl.brandCheckMultiple([Headers, globalThis.Headers].filter(Boolean)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What if you run node with --no-experimental-fetch? Then globalThis.Headers will be undefined. Thus breaking the code.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
that's what the .filter(Boolean) is for
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah right
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm
@mcollina I don't think this is semver-major? |
* replace instanceof in brand checks with isPrototypeOf * fix types
As a side note, but not majorly important: isPrototypeOf is also resilient against Symbol.hasInstance shenanigans. The real benefit is needing less imports to perform brand checks now that it is unified.