Skip to content
New issue

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

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

Already on GitHub? # to your account

replace instanceof in brand checks with isPrototypeOf #3692

Merged

Conversation

KhafraDev
Copy link
Member

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.

const headersToBrandCheck = globalThis.Headers
? [Headers, globalThis.Headers]
: [Headers]
const brandChecks = webidl.brandCheckMultiple([Headers, globalThis.Headers].filter(Boolean))
Copy link
Contributor

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.

Copy link
Member Author

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

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah right

Copy link
Contributor

@Uzlopak Uzlopak left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See comment

Copy link
Member

@mcollina mcollina left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

@mcollina mcollina merged commit b173caa into nodejs:main Oct 7, 2024
33 checks passed
@mcollina mcollina added the semver-major Features or fixes that will be included in the next semver major release label Oct 7, 2024
@KhafraDev
Copy link
Member Author

@mcollina I don't think this is semver-major?

@KhafraDev KhafraDev deleted the symbol-hasinstance-object-isprototypeof branch October 7, 2024 14:02
flakey5 pushed a commit to flakey5/undici that referenced this pull request Oct 8, 2024
* replace instanceof in brand checks with isPrototypeOf

* fix types
@github-actions github-actions bot mentioned this pull request Dec 3, 2024
This was referenced Dec 16, 2024
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
semver-major Features or fixes that will be included in the next semver major release
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants