feat: JS delegates with value-type parameters and return values - #16
Merged
Merged
Conversation
JS delegates shared one vtable whose Invoke takes up to three pointer-sized arguments and returns nothing. That covers event handlers, but a delegate such as Int64 F(Single, Single, Single, Single) got garbage arguments (floats travel in vector registers on x64 and ARM64) and its result was never written back. Delegates whose Invoke takes floating-point values or returns a value now get their own vtable, whose Invoke is a libffi closure with the exact signature from metadata. The JS function's result is converted to the declared return type, and a JS exception is reported as E_FAIL. Other delegates keep the shared Invoke. Both the classic and the Node-API engines use it.
|
Important Review skippedAuto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Advanced Run ID: 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 |
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.
JS functions passed as WinRT delegates (
NSWinRT.asDelegateand delegate constructors) now work when the delegate'sInvoketakes floating-point values or returns a value.Problem
Every JS delegate shared one vtable whose
Invoketakes up to three pointer-sized arguments and returns nothing. That covers event handlers ((sender, args)), but not a delegate such asInt64 F(Single, Single, Single, Single):Invokenever reads, so the JS function received garbage.Change
Invokeneeds it get their own vtable. ItsInvokeis a libffi closure built from the exact signature in metadata (runtime/src/delegate_invoke.rs). libffi reads each argument from wherever the ABI put it.E_FAIL.Invoke.No API changes:
asDelegatepicks the rightInvokefrom the delegate's metadata.Tests
cargo test -p runtime --lib --release:Int64 F(Single, Single, Single, Single)and a check that plain event-handler delegates keep the sharedInvoke. All pass.main(therun_on_ui_thread,ui_dispatcherand a few XAML interop tests).