Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: NativeScript/ios
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: 73c99f9
Choose a base ref
...
head repository: NativeScript/ios
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 263bb84
Choose a head ref
  • 11 commits
  • 19 files changed
  • 2 contributors

Commits on Oct 15, 2026

  1. feat: support native ES classes with lazy registration, including sta…

    …tic usage before construction
    
    Plain ES classes extending native types (class JSClass extends NSObject {})
    now register their Objective-C subclass lazily on first native use, without
    requiring the @nativeclass decorator or ES5 downleveling. Registration is
    triggered not only by construction (new/new.target) but by any static touch:
    JSClass.alloc().init(), JSClass.new(), inherited static methods and
    properties, and passing JSClass directly to native APIs expecting Class or
    id arguments. A global no-op NativeClass keeps existing decorated code
    working unchanged.
    NathanWalker authored and edusperoni committed Oct 15, 2026
    Configuration menu
    Copy the full SHA
    8288ed4 View commit details
    Browse the repository at this point in the history
  2. Configuration menu
    Copy the full SHA
    90ba63c View commit details
    Browse the repository at this point in the history
  3. feat(es-classes): make NativeClass load-bearing and refuse the ambigu…

    …ous forms
    
    Registration stays lazy for a plain `class X extends NSObject {}`, but the
    NativeClass decorator now carries the declarations that need a deterministic
    home, and the two construction paths that silently disagreed now either work
    or fail loudly.
    
    NativeClass accepts `{ protocols, exposedMethods, name, eager }` and works in
    both decorator conventions plus the plain call form. A standard (TC39) class
    decorator runs before static field initializers, so eager registration defers
    through context.addInitializer when a decorator context is present.
    
    - `name` sets ObjCClassName, read as an own property so a subclass cannot
      inherit its base's name. Minifiers mangle the inferred constructor name and
      every name-based native lookup with it.
    - `eager` registers at definition time through the new __registerNativeClass
      global, so storyboards and NSClassFromString resolve the class before first
      use. No-op on workers, whose names are isolate-suffixed.
    - super(...) from an ES subclass now requires no arguments or a single
      initializer-token object. Positional arguments matched on JS value shape, so
      initWithInt: and initWithDouble: were indistinguishable and the winner
      depended on the call site; the token form is also the only form the generated
      .d.ts can express. Direct `new NSString('x')` is unaffected.
    - An ES class extending a legacy .extend() class now throws instead of falling
      back to the parent's registered class, which registered nothing and dispatched
      the subclass's overrides to the parent's implementations.
    - Registering a class on a path where Objective-C allocates it warns, in debug
      builds, when the class declares an explicit constructor or instance fields and
      does not override init. Those objects reach JS as a bare object with the
      prototype grafted on, so fields are absent and #private access throws.
    edusperoni committed Oct 15, 2026
    Configuration menu
    Copy the full SHA
    083aa71 View commit details
    Browse the repository at this point in the history
  4. feat(es-classes): mirror the JS class hierarchy in Objective-C

    `class B extends A extends UIView` registered B directly under UIView, as a
    sibling of A, and copied A's methods into it. JS saw `b instanceof A`, but
    Objective-C did not: [b isKindOfClass:A] was false, which breaks
    UIAppearance, class-keyed registration and KVO, and every inherited method
    was installed again at each level.
    
    The flattening existed because a native super call targeted the superclass
    of the receiver's runtime class. With a real hierarchy that is A's class,
    whose implementation of an overridden method calls back into A's JS method,
    so `super.foo()` from A on a B instance recursed. A JS super lookup only
    reaches a native method when no JS level above the caller defines it, so the
    correct target is the superclass of the rootmost JS-defined class in the
    chain (ClassBuilder::GetNativeSuperclass). Single-level classes, which is
    every legacy one, resolve to the same class as before.
    
    - EnsureExtendedClass registers a JS-defined parent first and subclasses it,
      exposing only the class's own prototype level. Statics are still read
      through the constructor, so an override of a method declared in an
      inherited ObjCExposedMethods/ObjCProtocols finds its signature.
    - An ES class may now extend a legacy .extend() class. The legacy `super`
      accessor resolves its prototype from the class that owns it rather than a
      fixed depth from the receiver, which pointed at the legacy implementation
      object itself once an ES subclass added a level.
    - .extend() of an already extended class is still refused.
    edusperoni committed Oct 15, 2026
    Configuration menu
    Copy the full SHA
    92c061b View commit details
    Browse the repository at this point in the history
  5. feat(es-classes): run the constructor for every instance, through int…

    …erop.initializer
    
    Objects Objective-C creates itself (alloc/init, cell reuse, storyboards,
    NSCoding) reached JS as a bare object with the class prototype grafted on:
    the constructor never ran, so class fields were undefined and #private
    access threw. And super(...) matched positional arguments against
    initializer signatures by JS value shape, conflating the class's own data
    with the choice of native initializer.
    
    A class extending a native type now constructs through one contract:
    
    - super(...) takes nothing or a single options object. The class's own
      keys are plain data; [interop.initializer.args] names the initializer by
      its constructor tokens, matched as a set ({ frame } -> initWithFrame:),
      and is `init` when absent.
    - The first ES class above a native or legacy base gets a hook for every
      metadata initializer the base implements. When Objective-C sends one,
      the hook runs the JS constructor with
      { [interop.initializer.native]: { selector, args },
        [interop.initializer.args]: <tokens of that call> }, and super(...)
      runs that initializer with the original arguments, exactly once. A
      constructor can force another initializer, like an ObjC -init calling
      [super initWithStyle:]; spread order decides default versus force.
    - `this` is bound to the object before the initializer runs, on both
      paths, so overrides the initializer calls see the instance.
    - An instance initialized through an initializer the metadata does not
      list is constructed the first time it reaches JS, with
      [interop.initializer.native].selector null and no initializer run.
    - A constructor failing inside an initializer Objective-C sent is
      reported through the uncaught-error path, and the initializer returns
      nil after releasing what the caller allocated.
    - An ES class defining a method that overrides an initializer is refused
      at registration: the constructor already runs for every initializer.
    
    - An NSException an initializer raises becomes a JS Error, as for any
      other native call (Interop::ThrowAsJSError, shared with
      CallFunctionInternal).
    
    Interop::GetResult now releases the surplus +1 when an owned result
    (alloc/new/copy, or an initializer sent to a receiver allocated for the
    call) is already wrapped. It returned the cached wrapper without balancing
    it, which every JS-side `X.alloc().init()` on an ES class now hits, since
    the hook binds the object before the initializer returns. An initializer
    sent to an already wrapped receiver still keeps its +1: that is the
    receiver's own reference passing through.
    
    The super(...) positional and bare-token forms throw with the spelling to
    use instead. The source-text debug warning about unreachable constructors
    is gone, along with the condition it warned about.
    edusperoni committed Oct 15, 2026
    Configuration menu
    Copy the full SHA
    360f29b View commit details
    Browse the repository at this point in the history

Commits on Oct 21, 2026

  1. perf(es-classes): memoize the per-call class and initializer lookups

    Three lookups the ES-class work added ran on hot paths:
    
    - GetNativeSuperclass walked the receiver's whole class chain, checking
      each level's protocol list, on every native call on an extended
      instance (`super.foo()`, but also `this.frame` and every other
      metadata call, legacy `.extend()` classes included). A class's chain
      never changes once registered, so the result is now memoized per
      class, thread-locally so the call path takes no lock.
    - Matching super(...) options rebuilt and sorted every initializer's
      tokens on each construction, including the check that rejects the old
      `super({ frame })` spelling on a plain `new X({ owner })`. Each class's
      initializers are now indexed once by their sorted token set. The
      options-object test compares the prototype with Object.prototype
      instead of asking V8 for the constructor name.
    - First-sight adoption walked the class chain of every object's first
      wrap. The ES class each class belongs to (or none) is now memoized, so
      that is one lookup per first wrap however many ES classes exist.
    
    The per-isolate state moves into Caches::StateFor slots owned by
    ClassBuilder.mm and ArgConverter.mm, including the ES class set the
    construction commit had added to Caches.h.
    edusperoni committed Oct 21, 2026
    Configuration menu
    Copy the full SHA
    0e1c41d View commit details
    Browse the repository at this point in the history
  2. perf(es-classes): skip the wrapper lookup for template-built construc…

    …tors
    
    Every `new` of a native class looked new.target's wrapper up twice (once to
    resolve the class, once to check for an ES class), and every static
    property read looked its receiver up once. A constructor function has no
    internal field, so each lookup is a private-symbol read: a V8 string, an
    API-registry lookup and a Locker. Release A/B on a simulator:
    `new NSObject()` 235 -> 414 ns, `NSProcessInfo.processInfo` 121 -> 201 ns.
    
    Constructors the runtime builds from templates (native classes,
    `.extend()`) have no script, so they can never be ES classes:
    ClassBuilder::MayBeESClass checks Function::ScriptId() and those paths
    return main's answer without a lookup. ResolveConstructedClass now reports
    whether new.target is an ES class, so ConstructObject no longer looks it up
    a second time. Both rows are back to main's numbers.
    edusperoni committed Oct 21, 2026
    Configuration menu
    Copy the full SHA
    60357b3 View commit details
    Browse the repository at this point in the history
  3. perf(runtime): read the wrapper of a function or plain object in one …

    …GetPrivate
    
    Objects without an internal field (constructor functions, plain objects)
    keep their wrapper under a private key. Every lookup built the key's
    string, looked the private up in the API registry, checked HasPrivate,
    took a v8::Locker and only then read it. Every static call, alloc(),
    class passed as an argument and ES construction pays for one.
    
    The private is now cached in a per-isolate StateFor slot, and GetValue,
    SetValue and DeleteValue read it with a single GetPrivate (absent reads
    as undefined). Callers already hold the isolate, so the Locker was
    redundant. Release A/B on a simulator, 5 launches each:
    obj.isKindOfClass(NSObject) 198 -> 137 ns, NSNumber.numberWithInt 189 ->
    139 ns, NSNumber.numberWithDouble 247 -> 192 ns, ES `new` 407 -> 353 ns.
    edusperoni committed Oct 21, 2026
    Configuration menu
    Copy the full SHA
    eeb26c7 View commit details
    Browse the repository at this point in the history
  4. perf(es-classes): build the initializer hook's objects from cached ha…

    …ndles
    
    Sampling an Objective-C-started construction showed most of the hook's own
    time in work every construction repeated:
    
    - the two interop.initializer symbols looked up in the API registry by
      name, now cached per isolate;
    - the info object's key strings, selector names and each initializer's
      token keys created afresh, now cached, and the objects built with
      CreateDataProperty instead of Set;
    - the options check reading the wrapper of a plain object, now an
      internal-field count, which is how native wrappers are recognized;
    - the constructor found by class name, now by class;
    - the initializer sent through objc_msgSend only to land in the hook
      again, now sent straight to the implementation the hook passes
      through to (a super send on the JS path).
    
    Release A/B on a simulator, 5 launches each, on top of the previous
    commit: ES alloc().init() 1653 -> 1238 ns, ES new() 1292 -> 939 ns,
    ES new({ owner }) 669 -> 515 ns, ES UIView alloc().initWithFrame()
    3961 -> 3294 ns.
    edusperoni committed Oct 21, 2026
    Configuration menu
    Copy the full SHA
    8d26922 View commit details
    Browse the repository at this point in the history
  5. perf(runtime): GC-protect extended instances without the Locker when …

    …inside the isolate
    
    The retain/release swizzle that keeps an extended instance's JS object
    alive while native code holds it checked the isolate's liveness on every
    retain and release, and on the 1 -> 2 and 2 -> 1 transitions took a
    v8::Locker and an isolate scope after a run-loop check. UIKit methods
    that retain and release self (`-[UIView tag]` among them) pay all of it
    on every call when JS holds the only other reference.
    
    The retain count is now checked first, so other counts skip the isolate
    entirely, and a transition on a thread already inside the isolate and
    holding its lock flips the flag directly. Everything else takes the
    existing path. This applies to @nativeclass (`__extends`) classes as well
    as ES classes. Release A/B on a simulator, 5 launches each:
    view.tag on an ES or @nativeclass view 164 -> 137 ns, ES alloc().init()
    1238 -> 1112 ns.
    edusperoni committed Oct 21, 2026
    Configuration menu
    Copy the full SHA
    01e4d77 View commit details
    Browse the repository at this point in the history

Commits on Oct 23, 2026

  1. feat(metadata-generator): type every initializer a class answers to, …

    …and interop.Args
    
    A generated class declared only the constructors of its own initializers
    and those of its protocols, and in TypeScript a class that declares any
    constructor hides all of its base class's. So against the generated
    UIKit typings `new UITableViewController()`, `{ coder }` and
    `{ nibName, bundle }` were type errors, as was `super({ coder })` from a
    subclass, though the runtime accepts all of them.
    
    Each class now also declares the initializers it inherits, except one
    the class's nearest declaration marks unavailable (NS_UNAVAILABLE drops
    it from the subclass's metadata, e.g. -[UIScene init]). Initializers
    whose tokens coincide are written once.
    
    For ES subclasses, each class also gets
    `constructor(args: interop.Args<{}, X.Initializers>)` and a merged
    `declare namespace X { type Initializers = ... }`, the union of its
    initializer token objects, carrying the class's type parameters for
    generic classes. An initializer without tokens is
    `Record<string, never>`, not `{}`: a union holding `{}` skips
    excess-property checks, so a misspelled token would type-check.
    
    interop.Args and interop.initializer are declared by
    @nativescript/types-ios (NativeScript/rfcs#56); until that lands, output
    from this generator needs skipLibCheck or a local declaration of them.
    edusperoni committed Oct 23, 2026
    Configuration menu
    Copy the full SHA
    263bb84 View commit details
    Browse the repository at this point in the history
Loading