-
Notifications
You must be signed in to change notification settings - Fork 529
This() deprecation branch #5942
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
Draft
erikcorry
wants to merge
5
commits into
main
Choose a base branch
from
erikcorry/this-deprecation
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+120
−8
Draft
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,84 @@ | ||
| # Case for PropertyCallbackInfo::This() | ||
|
|
||
| ## Summary | ||
|
|
||
| Unfortunately, Cloudflare Workers (workerd) genuinely needs `PropertyCallbackInfo::This()` and cannot follow Chromium's pattern. We tested moving interceptors from prototype to instance template (like Chromium does) and it breaks RPC functionality. | ||
|
|
||
| ## What We Tested | ||
|
|
||
| ### Attempt: Move Interceptors to Instance Template | ||
|
|
||
| Chromium puts interceptors on `instance_template`, while workerd puts them on `prototype`: | ||
|
|
||
| ```python | ||
| # Chromium (interface.py line 5815) | ||
| interceptor_template = "${instance_template}" | ||
| ``` | ||
|
|
||
| ```cpp | ||
| // Workerd (resource.h) | ||
| prototype->SetHandler(...) // On prototype, not instance | ||
| ``` | ||
|
|
||
| We tried changing workerd to match Chromium: | ||
|
|
||
| ```cpp | ||
| instance->SetHandler(...) // Changed to instance | ||
| ``` | ||
|
|
||
| Result: Our RPC tests fail: | ||
| ``` | ||
| TypeError: stub.foo is not a function | ||
| TypeError: stub.increment is not a function | ||
| ``` | ||
|
|
||
| ### Why It Fails | ||
|
|
||
| Workerd uses prototype-level interceptors for RPC stubs. These are wrapper objects that intercept any property access and forward it over RPC: | ||
|
|
||
| ```javascript | ||
| const stub = env.MY_DURABLE_OBJECT.get(id); | ||
| stub.anyMethodName(args); // Intercepted and sent over RPC | ||
| ``` | ||
|
|
||
| With interceptor on prototype: | ||
| - Works for any object inheriting from `JsRpcStub.prototype` | ||
| - Enables flexible RPC proxying | ||
|
|
||
| With interceptor on instance: | ||
| - Only works for objects created directly from the template | ||
| - Breaks RPC stub pattern | ||
|
|
||
| This is fundamentally different from Chromium's use of interceptors (HTMLCollection, Storage, etc.) where the interceptor is on the actual object being accessed. | ||
|
|
||
| ## Backwards compatibility issue | ||
|
|
||
| In addition to the RPC issue we also have a backwards compatibility issue. Workers take | ||
| backwards compatibility very seriously - we can't break already-deployed scripts when | ||
| we run them with a newer version of V8. | ||
|
|
||
| In 2022 we moved to setting accessors on the prototype instead of on the instance. | ||
| This solved some compatibility issues, eg. people could not subclass and get the | ||
| expected behaviour. It also aligns better with IDL. However we still have a | ||
| compatibility flag for this since it is trivially observable from JS. | ||
|
|
||
| ## What Workerd Needs | ||
|
|
||
| | Use Case | API Needed | Can Migrate? | | ||
| |----------|-----------|--------------| | ||
| | Prototype properties (new Workers) | `FunctionCallbackInfo::This()` | Already done (2022) | | ||
| | Named interceptors (RPC stubs) | `PropertyCallbackInfo::This()` | **No** - breaks RPC | | ||
| | Instance properties (legacy Workers) | `PropertyCallbackInfo::This()` | **No** - backwards compat | | ||
|
|
||
| ## Conclusion | ||
|
|
||
| `PropertyCallbackInfo::This()` is needed for workerd's legitimate use case of prototype-level interceptors. This is not a case of something that can be fixed by following Chromium's pattern - we tested that and it breaks functionality. | ||
|
|
||
| Options: | ||
| 1. Keep `This()` available for prototype-level interceptors | ||
| 2. Provide alternative API to get the receiver in `PropertyCallbackInfo` | ||
| 3. Clarify the migration path for embedders who need prototype-level interceptors | ||
|
|
||
| --- | ||
|
|
||
| *Erik Corry, Cloudflare* |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
(You're probably already aware, but just in case: eventually we'll also want to remove the instances of "-Wdeprecated-declarations" in resource.h)