Skip to content

Conversation

@jasnell
Copy link
Collaborator

@jasnell jasnell commented Oct 21, 2025

Provides a mechanism to obtain const TypeHandler& references without needing to inject them via jsg argument injection.

tests were implemented by claude with a bit of manual intervention.

This approach is imperfect, of course... specifically because it requires individual types to be registered. It won't automatically work for things like const TypeHandler<jsg::Promise<T>> since it can't know about all possible jsg::Promise<T>'s we might use, but it's good enough to investigate the utility.

** THIS IS CURRENTLY JUST AN EXPLORATION OF OPTIONS **

Draft since this is still WIP/being investigate.

Internal build will fail until the same v8 patch is landed there.

Provides a mechanism to obtain const TypeHandler<T>& references
without needing to inject them via jsg argument injection.
@jasnell jasnell requested review from a team, erikcorry, harrishancock and kentonv October 21, 2025 00:22
@jasnell jasnell requested review from a team as code owners October 21, 2025 00:22
@jasnell jasnell marked this pull request as draft October 21, 2025 02:25
@github-actions
Copy link

github-actions bot commented Oct 21, 2025

The generated output of @cloudflare/workers-types matches the snapshot in types/generated-snapshot 🎉

@kentonv
Copy link
Member

kentonv commented Oct 27, 2025

Awkward thing here is how do you specify what types you need to be registered, so that they are in the registry when you look them up? The parameter injection approach nicely solves that because the JSG "linker" (stuff that happens in the giant template instantiation in workerd-api.c++) sees every injected parameter and can make sure the associated types get instantianted.

But we could reasonably support a registry of all wrapped types, at least. In fact I think we already sort of have one -- resourceTypeMap.

I think we could use resourceTypeMap to support two new methods on jsg::Lock that specifically operate on JSG_RESOURCE_TYPE types:

template <typename T>
JsObject Lock::wrapApiType(Ref<T> ref);

template <typename T>
kj::Maybe<Ref<T>> Lock::tryUnwrapApiType(JsValue val);

Those could replace a lot of TypeHandler usage.

@jasnell
Copy link
Collaborator Author

jasnell commented Oct 29, 2025

Closing... experiment done. Yes, this helps a few things but it's rather cumbersome.

@jasnell jasnell closed this Oct 29, 2025
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.

2 participants