Repository navigation
refactor(runtime): canary wrapper templates by kind - #594
Draft
edusperoni wants to merge 1 commit into
Draft
edusperoni wants to merge 1 commit into
edusperoni wants to merge 1 commit into
Conversation
|
Important Draft PR not reviewedDraft PRs are not automatically reviewed by default.
To automatically review draft PRs, update your CodeRabbit configuration: reviews:
auto_review:
drafts: true
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. |
Canary handlers are now configured per CanaryKind: kPlain for objects outside JS-extended classes (native class constructors under scope "all", empty instances of such objects) and kExtended for instances of JS-extended classes. Wrappers take the kind of their object (WrapperLifetimeCanary:: KindOf), computed once per wrap; whether a class is JS-extended is cached per class and thread, since the superclass walk costs tens of nanoseconds a class. Adopt checks the kind it is given in debug builds only. ArgConverter::ConstructObject now gives a result whose kind differs from its constructor's template a new object of the result's kind, returned in place of `this`. Before, it did so only for a canary built from a template without handlers. The new cases are a plain template with a JS-extended result and the reverse, which constructing from a pointer (`new NativeClass(handle)`) or an initializer that returns another object reaches. `new` of a JS-extended subclass through a native base does not: ClassConstructorCallback takes the class from the native constructor's metadata, not from new.target. Both kinds install the same masking handlers at this commit, so the replacement object behaves as `this` would have; a later change gives plain canaries different handlers.
edusperoni
force-pushed
the
refactor/canary-template-kinds
branch
from
November 21, 2026 23:31
0cf7d71 to
21a009d
Compare
This branch has not been deployed
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Stacked on #593. Groundwork for #595 (plain canaries forward their JS properties); the handlers are the same for every kind at this commit.
What changes
CanaryKind:kPlain: objects outside JS-extended classes (native class constructors under scope"all", and empty instances of such objects);kExtended: instances of JS-extended classes.WrapperLifetimeCanary::KindOf), computed once per wrap.NSObjectand 410 ns for a five-deep class.WrapperLifetime::Adoptchecks the kind it's given in debug builds only.ArgConverterkeeps one empty-instance and one constructed-instance constructor per kind.Behaviour delta
ArgConverter::ConstructObjectnow swapsthiswhenever the result's kind differs from the constructor template's kind. Before, it swapped only when a canary was built from a template without handlers. The new cases are:Both are reached by constructing from a pointer (
new NativeClass(handle)) or by an initializer that returns another object.newof a JS-extended subclass through a native base doesn't reach it:ClassConstructorCallbacktakes the class from the native constructor's metadata, not fromnew.target.Both kinds install the same masking handlers here, so the replacement object behaves as
thiswould have. The originalthisis untouched before the swap (no wrapper, registration orInstancesentry), so nothing is built twice.Testing
Full suite, 0 failures in
canary/all,canary/extendedandresurrecting/extended. The whole stack, with the next PR on top, also passes inrooted/all, withallowShadowingNativeMembers, and under ASan.