Skip to content

fix: struct values for IReference<T> parameters - #25

Merged
triniwiz merged 1 commit into
mainfrom
fix/struct-ireference
Oct 13, 2026
Merged

triniwiz merged 1 commit into
mainfrom
fix/struct-ireference

Conversation

@triniwiz

Copy link
Copy Markdown
Member

Lets JS set IReference<T> parameters whose T is a struct, such as AppWindowTitleBar's IReference<Windows.UI.Color> colors.

The bug

box_as_ireference only boxed values that PropertyValue can create (primitives, TimeSpan, DateTime, Guid):

  • A plain object (bar.BackgroundColor = { A: 255, R: 32, G: 32, B: 32 }) wasn't boxed, so the setter failed with E_FAIL.
  • A struct value (bar.BackgroundColor = Windows.UI.ColorHelper.FromArgb(...)) had its field buffer passed as a COM object, and the process crashed.

That meant NativeScript core couldn't color a window's title bar to follow the app's light or dark appearance on Windows App SDK 1.6, which has no PreferredTheme.

The fix

When T is a struct, the value (a plain object or a struct value) is laid out as for a struct parameter and held by a small agile IReference<T>. That object answers the parameter's IID (computed from its closed generic name) and copies the bytes out of get_Value. null/undefined still pass a null reference. TimeSpan and DateTime still go through PropertyValue, which also accepts a number for them. Both the classic and the Node-API engines handle it.

Testing

  • New interop_test::ireference_struct_parameters covers StorageProviderQuotaUI.QuotaUsedColor (IReference<Color>) set from a plain object, from ColorHelper.FromArgb, and cleared with null, plus ShareUIOptions.SelectionRect (IReference<Rect>). It passes, and so does the existing ireference_parameters_and_results.
  • cargo check -p runtime --no-default-features --features napi_engine builds.
  • Swapped a release devtools build of this branch into a WinUI app (the shadcn desktop starter): the title bar colors now apply on startup and on each light/dark switch, with no crash.

IReference<T> parameters of a struct type, such as AppWindowTitleBar's IReference<Windows.UI.Color> colors, couldn't be set. PropertyValue only boxes primitives, so a plain { A, R, G, B } object failed with E_FAIL, and a struct value such as ColorHelper.FromArgb's had its field buffer passed as a COM object and crashed.

A struct is now laid out as for a struct parameter and held by an agile IReference<T> that answers the parameter's IID and copies the bytes out of get_Value. TimeSpan and DateTime still go through PropertyValue, which also takes a number for them. Both the classic and the Node-API engines handle it.
@coderabbitai

coderabbitai Bot commented Oct 13, 2026

Copy link
Copy Markdown

Important

Review skipped

Auto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration
  • Configuration used: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 4f7f269d-7bb4-40ee-a067-dabc75aaf9e3

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@triniwiz
triniwiz merged commit 1b90aed into main Oct 13, 2026
3 checks passed
@triniwiz
triniwiz deleted the fix/struct-ireference branch October 13, 2026 15:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant