fix(ffi): answer instanceof for TypeScript-derived classes against the derived class - #65
Merged
Merged
Conversation
…e derived class A @nativeclass constructor inherits the base wrapper's Symbol.hasInstance through the wrapper prototype chain until its Objective-C class materializes, so `x instanceof Derived` ran the BASE class's membership check: any UIViewController subclass instance tested true for instanceof UILayoutViewController. @nativescript/core's setViewControllerView gates on exactly that check for root views, so a root Frame's iOSFrame helper object was marshalled (as NSDictionary) into addSubview: and UIKit threw NSInvalidArgumentException at boot. Detect the inherited invocation via hasInstance's `this` (the spec passes the constructor instanceof was invoked on): delegate to the materialized derived wrapper when one exists, and report false before materialization — no instance of an unmaterialized class can exist. After materialization the constructor's prototype is already the derived wrapper, whose own hasInstance answers directly. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
|
Important Review skippedAuto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Plus Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
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. Comment |
NathanWalker
marked this pull request as ready for review
August 9, 2026 22:05
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.
What
On the QuickJS (jsi/ffi) runtime flavor,
x instanceof Derivedfor a@NativeClass-derived class ran the base class's membership check until the derived Objective-C class materialized. A TypeScript-derived constructor inherits the base wrapper'sSymbol.hasInstancethrough the wrapper prototype chain; the closure captures the base native class, so any instance of the base kind tested true (UINavigationControllerImpl instanceof IOSHelper.UILayoutViewController→true).Impact
@nativescript/core'ssetViewControllerViewgates root-view mounting on exactly that check. For an app whose root view is an imperativeFrame(Application.run({ create: () => new Frame() })), the misfire sent core down the layout-controller branch, marshalled theiOSFrameJS helper object intoaddSubview:(as__NSDictionaryM), and UIKit threwNSInvalidArgumentException: -[__NSDictionaryM superview]: unrecognized selectorat boot — a hard crash before first render.Fix
Symbol.hasInstanceis called with the constructorinstanceofwas invoked on asthis(spec:Call(instOfHandler, target, «V»)). In the base wrapper's implementation, detect the inherited invocation (thisis neither this constructable nor its proxy and carries__nativeApiTypeScriptState):hasInstance(correctisKindOfClass:against the derived class)false: no instance of an unmaterialized class can existAfter materialization the TS constructor's prototype is already reset to the derived wrapper, whose own
hasInstanceanswers directly, so the new branch only governs the pre-materialization window.Validation
Reproduced deterministically with a root-
FrameNativeScript app on the iOS 26.5 simulator (ios-quickjs build): crash at boot before the fix; app boots, renders, and runs its display-link loop after. A dominative/document-rooted app (no root Frame) was unaffected before and after.Sibling of #63: that fix marshalled the real Class for the wrapper's own check; this one covers constructors that inherit the check.
🤖 Generated with Claude Code