Repository navigation
fix: struct constructors on napi; boxed struct values on both engines - #28
Merged
Merged
Conversation
|
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 |
- napi namespaces resolve struct types to a constructor
(`new Rect({...})`, `new Rect(x, y, w, h)`, `new Rect()`), returning
the same plain object a struct return gives
- IPropertyValue holding Point/Size/Rect/TimeSpan/DateTime unboxes to
a struct value instead of an empty wrapper
- plain objects shaped like those five types box back when passed to
an Object parameter (PropertySet.Insert, settings values)
- missing struct fields serialize as zero instead of NaN
- napi struct String fields are written
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.
Stacked on #26 (base
perf/struct-values-namespaces). GitHub retargets it tomainwhen #26 merges.Summary
Three struct gaps, fixed on both engines where they applied.
1. Struct constructors on napi
napi namespaces returned
undefinedfor struct types (Windows.Foundation.Rect). They now resolve to a constructor:The result is the same plain object a struct return gives. It's built by serializing through the struct's byte layout and reading back, so values match exactly what native receives.
2. Boxed structs (
IReference<Point>etc.)An
IPropertyValueholding a Point, Size, Rect, TimeSpan or DateTime used to come back as an empty wrapper:{}on napi,{ handle }on classic. It now unboxes to a struct value, e.g.PropertyValue.CreatePoint({X:1.5,Y:2.5})gives{ X: 1.5, Y: 2.5 }, and so doesPropertySet.Lookupfor a stored Point.To keep the "create a value and store it in settings" pattern working, a plain object passed to an
Objectparameter is now boxed by its shape.{X,Y}becomes a Point,{Width,Height}a Size,{X,Y,Width,Height}a Rect,{Duration}a TimeSpan, and{UniversalTime}a DateTime. These are the only struct typesIPropertyValuesupports, and their field names don't overlap. SopropertySet.Insert('p', { X: 1, Y: 2 })now works directly.3. Serializer fixes (both engines)
NaNfor float fields (e.g.region.Padding = { Before: 1 }). They're now 0.Stringstruct fields are written instead of zeroed (classic got this in perf: plain struct values and cached namespace lookups (classic) #26).Also checked
new Windows.UI.Input.Inking.InkPoint({X:3,Y:4}, 0.5).Positionround-trips (Point, 8 bytes, passed in a register).TimedTextStyle.Padding, which doesn't exist (that class has noPadding), so it only round-tripped a JS property. It now usesTimedTextRegion.Paddingand asserts no own property was created.Testing
integration-tests/tests/boxed_structs.rs; all 18 integration test targets pass; runtime unit tests show the same 11 known failures asmain.npm testpasses 417/417, including 11 new checks instruct-test.js.