JS subclassing parity, background-thread callbacks, C# sources in apps - #21
Merged
Merged
Conversation
…in apps
Class extension (classic and napi engines)
- .NET and unsealed WinRT classes can be extended with ES2015 `class`,
`Class.extend()`, `@NativeClass`, TypeScript ES5 output and
`Object.extend({ interfaces })`. Native code calling an overridden member
reaches the JS override (including XAML's MeasureOverride/ArrangeOverride/
OnApplyTemplate on composed WinUI objects).
- Constructor arguments select and feed the base constructor; `super.X()` and
`this.super.X()` call the base implementation through emitted non-virtual
`__ns_base_X` methods; protected/abstract members, property accessors,
`instanceof` (subclass and native bases), JS fields and object identity
across native round-trips work; `new Interface({...})` and `@Interfaces`
implement interfaces.
- Instances are collectable: the dispatcher holds the JS object weakly, the
bridge unpins it when the managed object dies, and a JS object is revived
for instances only native code still holds. WinRT UI subclasses stay alive
while in a live XAML tree.
- sbg-generated proxies are no longer built or shipped: the bridge emits the
types at runtime.
Threading
- WinRT delegates, .NET delegates/events, overridden members and Task
continuations invoked on background threads run on the UI thread while the
caller waits (return values and exceptions flow back), in both engines.
- .NET methods returning Task return awaitables instead of blocking the UI
thread.
- Static WinRT events (CompositionTarget.Rendering) can be assigned on class
constructors, so tree mutation from Rendering/LayoutUpdated/SizeChanged is
covered by tests.
C# in apps and plugins
- Root namespaces of app, plugin and NuGet assemblies are globals: C# under
App_Resources/Windows (or a plugin's platforms/windows) is usable from JS by
namespace with no registration.
- JS functions passed for delegates, plain objects for structs, enums,
overloads by parameter type.
- `System` stays the .NET namespace when @nativescript/core assigns its
SystemJS shim.
- Classic engine pumps V8 platform tasks and clears kept objects, so
FinalizationRegistry/WeakRef work (proxied .NET handles are now released).
Template / tooling
- The template runs unpackaged (no ApplicationData without package identity)
and doesn't copy App_Resources C# sources to the output.
- Fix top-level require() of relative modules when the entry isn't a bundle.
Tests
- test-app/: Jasmine-style runtime test app (like the Android/iOS test-apps)
with C# fixtures in App_Resources/Windows/src and a plugin shipping C#
sources; `pwsh test-app/run.ps1` (optionally `-EngineDll` for napi engines).
- dotnet-bridge-tests: JsSubclassTests for the bridge side.
|
Important Review skippedAuto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the ⚙️ Run configuration
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 |
…alues - WinRT delegates and .NET callbacks created in a worker run on that worker's thread when invoked from another thread (the worker loop now waits on commands, messages and timers). - A callback whose worker has terminated is refused instead of running on a disposed isolate. - Messages a worker posts on its own reach the main thread without it polling. - The classic engine unboxes IPropertyValue results (Tag, PropertySet values) to JS primitives. - test-app: worker and boxing specs; hooks of fully skipped suites don't run.
triniwiz
force-pushed
the
feat/js-subclassing-threading-csharp-sources
branch
from
October 4, 2026 05:42
92c0e02 to
38d0a65
Compare
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.
Brings class extension, threading and native C# code on Windows in line with what the iOS and Android runtimes offer, and adds a runtime test app like theirs.
Class extension
JS can extend .NET classes and unsealed WinRT/WinUI classes with ES2015
class,Class.extend(),@NativeClass, TypeScript's ES5 output (__extends/_super.call(this)) andObject.extend({ interfaces }). When native code calls an overridden member, it reaches the JS override; for example, XAML callsMeasureOverrideon a JSPanelsubclass.Previously:
superand constructor arguments didn't work, and neither didinstanceof;thiswasn't the JS object;class X extends <WinUI class>produced a plain base object.What changed:
super.X()/this.super.X()call the base implementation through non-virtual__ns_base_Xmethods the bridge emits.super(...)arguments select the base constructor, including protected ones.instanceofworks for the subclass and its native bases. JS fields are visible to native calls. Native code handing an instance back returns the same JS object.new Interface({...})and@Interfacesimplement interfaces.markingMode: nonesemantics). WinRT UI subclasses stay alive while in a live XAML tree.template/build.ps1), because the bridge emits the types at runtime.Threading
JsExceptionfor callbacks that return a value).onmessage. Before, they were only picked up while the main thread was insideworker.postMessage.Tasknow return an awaitable instead of blocking the UI thread.CompositionTarget.Rendering = fn) now work on class constructors. Adding, removing and reparenting XAML elements fromRendering/LayoutUpdated/SizeChangedhandlers is covered by tests; the 0xC000027B crash couldn't be reproduced.C# in apps and plugins
App_Resources/Windows(e.g.src/) or in a plugin'splatforms/windowswork by namespace with noregisterNamespace.Objectvalues: the classic engine unboxes boxed primitives (element.Tag = 'a'reads back'a';PropertySetvalues), as the napi engines already did. Before, they read back as an opaque wrapper.Systemglobal:Systemstays the .NET namespace when@nativescript/coreassigns its SystemJS shim. Before,System.IOetc. were unreachable in core apps.Other fixes
FinalizationRegistrynever ran, so .NET handles of collected proxies were never released, andWeakReftargets never died.WindowsPackageType=None) instead of crashing onApplicationData.App_Resourcesaren't copied to the output.require: a top-level relativerequire()now works when the entry isn'tbundle.js(both engines).instanceof: class prototypes chain to their WinRT base class's prototype, soinstanceofworks for base classes.make_napi_void_delegate, so thewindows-napitest helper builds again.Tests
test-app/: a Jasmine-style suite inside a WinUI app built fromtemplate/framework(the wayns preparedoes), with C# fixtures inApp_Resources/Windows/srcand a local plugin that ships C# sources. Run it withpwsh test-app/run.ps1, or-EngineDll packages/windows-v8/target/release/windows_v8.dllfor a napi engine. It covers C# sources, .NET and WinRT extension, threading (including workers),Objectunboxing, layout mutation and lifetime.dotnet-bridge-tests/JsSubclassTests.cs: bridge-side tests; the existing tests are updated for the per-argument dispatch payload.gc(), worker specs needWorker)cargo test -p runtime --libmainI also checked end to end with the desktop starter template: the C# file in
App_Resources/Windows/srccompiled through the CLI, and a JS subclass override was called from C#.Behaviour changes
Taskresults are awaitables instead of synchronously awaited values.JsException. Void callbacks still only report them.super(...)arguments.Related: CLI NativeScript/nativescript-cli
feat/windows-csharp-sources, docs NativeScript/docsdocs/windows-extending-threading-csharp.