Repository navigation
feat(runtime): primitive arrays, interop.Array.create, delegates boxed for Object params - #41
Merged
Merged
Conversation
Arrays: every primitive WinRT array parameter (Int32[], Double[],
Char16[], Boolean[], ...) now marshals, both arrays the callee reads and
arrays it fills; only byte[] did before. A typed array of the element's
kind, an ArrayBuffer or DataView is passed in place; a plain JS array is
copied, and refused for a fill array since the callee's writes would be
lost. interop.Array.create(type, count) allocates the matching typed
array up front, e.g. reader.ReadBytes(interop.Array.create('UInt8', n)).
Delegates: a JS delegate passed where WinRT expects an Object now also
answers IInspectable and IReference<D>, the way a projected delegate is
boxed. UIElement.AddHandler unboxes its handler that way and failed with
E_INVALIDARG; AddHandler(..., handledEventsToo) and RemoveHandler work
on both engines.
Errors: an argument that can't be marshaled reports what was expected
("Expected an Int32Array, an ArrayBuffer, a plain array or null for
parameter type Int32[]") instead of "Unspecified error (HRESULT
0x80004005)".
|
Important Review skippedAuto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the
|
triniwiz
added a commit
to NativeScript/NativeScript
that referenced
this pull request
Nov 6, 2026
The modal Popup's Closed handler was attached with AddHandler(Popup.ClosedEvent, ...), but Popup.Closed is a plain event, not a routed one: Popup.ClosedEvent is undefined, the call threw and the empty catch hid it. Clicking outside a cancelable modal closed the Popup without running the modal's close logic, so the view kept its modal state and the close callback never fired. The handler is now assigned to popup.Closed and cleared with null on close. Also corrects the TextField comment: AddHandler(KeyDownEvent, handler, true) works with a runtime that boxes JS delegates for Object parameters (NativeScript/windows#41); the KeyDown event stays as the fallback for runtimes that can't.
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.
Arrays
Every primitive WinRT array parameter now marshals, on both engines. That covers
Int32[],UInt32[],Int16[],UInt16[],Int64[],UInt64[],Single[],Double[],Boolean[],Char16[]and the byte types, and it covers both arrays the callee reads and arrays it fills. Before, onlybyte[]worked, and a plain JS array forbyte[]failed withUnspecified error (HRESULT 0x80004005)(e.g.FileIO.WriteBytesAsync(file, [1, 2, 3])).The call passes
(count, pointer). The count is in elements, not bytes.A typed array of the element's kind, an
ArrayBufferor aDataViewis passed in place: the callee reads or writes JS memory directly. A typed array of the wrong kind is refused (Float64ArrayforInt32[]).A plain JS array is copied, converting each element the way the matching typed array would.
A plain array is refused for a fill array, since the callee's writes would be lost.
ParameterDeclaration::is_fill_array()reads the[out]param attribute:is_out()only means ByRef.interop.Array.create(type, count)returns the matching zero-filled typed array, so an array can be allocated up front:Typings added in
typings/nswinrt-helpers.d.ts.Still unsupported: received arrays (
out T[], e.g.IPropertyValue.GetInt32Array), array return values, and arrays of strings or objects.Delegates passed as
ObjectUIElement.AddHandler(routedEvent, handler, handledEventsToo)takes its handler asObjectand unboxes it withQueryInterface(IReference<TDelegate>). We passed the bare delegate, so it failed withE_INVALIDARG, and core falls back to instance events, which never see events a control has already handled.JS delegates (classic
JsDelegateand napiNapiDelegate) now embed a small tear-off (delegate_box.rs) that answersIInspectableandIReference<D>. Itsget_Valuereturns the delegate itself, and itsIUnknownmethods forward to the delegate, so COM identity is preserved.AddHandlerandRemoveHandlerwork.The IID comes from
GenericInstanceIdBuilder::ireference_of_delegate. A test checks it againstRoGetParameterizedTypeInstanceIID. Note that windows-rs signs delegates as a bare{guid}rather thandelegate({guid}), soIReference::<SomeDelegate>::IIDfrom the windows crate doesn't match what WinRT uses.Argument errors
When an argument can't be marshaled, the call now reports why instead of a bare
E_FAIL(thread-localerror::set_argument_error, picked up byformat_hresult_message; napi throws aTypeError). For example:Expected an Int32Array, an ArrayBuffer, a plain array or null for parameter type Int32[]. Two interop tests asserted that such errors containHRESULT; they now also accept these messages.Testing
npm test: 442/442.IReference<D>IID against the OS; the delegate box (QI,get_Valueidentity, refcounts); array element conversion, element counts and view checks.Array.createfor each type.ReadBytesfilling a pre-allocated array, and refusing a plain array.PropertyValue.Create*Arrayfor every element type.WriteBytesAsyncwith a plain array.TextBox.AddHandler(KeyDownEvent, h, true)andRemoveHandlerin a liveXamlWindow; onmainthis throws0x80070057.cargo test -p runtime --lib: same failures asmain(environment and network dependent), plusenum_type_arguments, whose 2 s wait times out under parallel load on some runs and passes alone.