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

Simplify "named intercept" #1585

Merged
merged 9 commits into from
Jan 30, 2024
Merged

Simplify "named intercept" #1585

merged 9 commits into from
Jan 30, 2024

Conversation

kentonv
Copy link
Member

@kentonv kentonv commented Jan 29, 2024

This implements the change we discussed previously, to allow the named property getter to return an arbitrary wrappable value.

I also came up with what I think is more intuitive name for this feature: "Wildcard property"

The fact that they are serialized is implied by the type, `JsValue`, which always contains a serialized value.
`setV8Serialized()` is a capnp data setter. It will always make a copy, it does not take ownership.

Also add a comment about avoiding the redundant copy in the future.
This functionality is not used by JS RPC as we have no way to know in advance what methods actually exist at the remote end. Moreover, methods of a class are normally not expected to be enumerable anyway, so even if it could know what methods exist, it'd still be returning an empty list here.

Since JS RPC is the only anticipated use case for named intercept at this time, I'd rather remove this unused functionality for now, to simplify further refactoring. We can bring it back in the future if a use case is found.
There's no longer any need to inherit this. JSG_NAMED_INTERCEPT works fine without it, since it always invokes `getNamed()` directly on the particular subclass via templates.
This makes the identifier `getNamed` no longer magic. Instead, the caller specifies whatever name they want.
The type is wrapped just like the return value of any function would be.
The named intercept callback is essentially the same as what `GetterCallback` handles, except with a name passed in. Aside from handling the name, there's no reason this code should be different from `GetterCallback`.
I think this is a much more intuitive name.
@kentonv kentonv requested a review from jasnell January 29, 2024 02:40
@kentonv kentonv requested review from a team as code owners January 29, 2024 02:40
@kentonv kentonv requested a review from fhanau January 29, 2024 02:40
// Configures the resource type to implement named property interception.
// @see the definition of jsg::NamedIntercept in resource.h for more information.
#define JSG_NAMED_INTERCEPT(method) \
// Declares a wildcart property getter. If a property is requested that isn't already present on
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: s/wildcart/wildcard/

Copy link
Member

@jasnell jasnell left a comment

Choose a reason for hiding this comment

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

Nice!

@kentonv kentonv merged commit 7987fb2 into main Jan 30, 2024
11 checks passed
@kentonv kentonv deleted the kenton/simplify-named-intercept branch January 30, 2024 00:39
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.

3 participants