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

Add cloudflare internal symbol to resourcetypes #2801

Merged

Conversation

jasnell
Copy link
Member

@jasnell jasnell commented Sep 25, 2024

Miniflare has been using the lack of Symbol.toStringTag to detect internal API objects. This is brittle and problematic because for compliance with standard web platform APIs we're supposed to be adding the Symbol.toStringTag to standard types and there are modules in the ecosystem that depend on it. We recently landed a change that adds the Symbol.toStringTag to types but that broke miniflare. This PR adds an alternative symbol to jsg::Objects that can identify themselves as internal.

Miniflare has been using the lack of `Symbol.toStringTag` to detect
internal API objects. This is brittle and problematic because for
compliance with standard web platform APIs we're supposed to be adding
the Symbol.toStringTag to standard types and there are modules in the
ecosystem that depend on it. We recently landed a change that adds the
Symbol.toStringTag to types but that broke miniflare. This PR adds an
alternative symbol to jsg::Objects that can identify themselves as
internal.
Copy link
Contributor

@petebacondarwin petebacondarwin left a comment

Choose a reason for hiding this comment

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

LGTM

@mrbbot
Copy link
Contributor

mrbbot commented Sep 25, 2024

Could you use the existing kResourceTypeInspect symbol for this?

auto symbol = v8::Symbol::ForApi(isolate, v8StrIntern(isolate, "kResourceTypeInspect"_kj));

internal.kResourceTypeInspect

@jasnell
Copy link
Member Author

jasnell commented Sep 25, 2024

Could you use the existing kResourceTypeInspect for this?

Possibly but I think for the sake of time since we need this to unblock something for release tomorrow this is better. Keep in mind that kResourceTypeInspect uses a private ForApi Symbol so the user (miniflare tests in this case) would need to have some way of importing that from somewhere and currently the only way to do that is with nodejs compat on, which complicates things a bit. This uses the global Symbol.for(...) registry to make importing it unnecessary. For now, let's keep it like this and if we can reconcile and simplify the two later then awesome.

@jasnell jasnell merged commit 49af69f into main Sep 25, 2024
14 checks passed
@jasnell jasnell deleted the jsnell/add-cloudflare-internal-symbol-to-resourcetypes branch September 25, 2024 16:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants