Repository navigation
Dispatch Mono [JSExport] by handle #134507
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
pavelsavara
merged 6 commits into
dotnet:main
from
pavelsavara:jsexport-dispatch-unification
Sep 29, 2026
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
b148884
Dispatch Mono [JSExport] by handle and drop unsafe from JSImport
pavelsavara 0cae942
fix MT
pavelsavara 4e5922b
fix reflection
pavelsavara f706474
Address review: bind-context fallback and dead SYSLIB1074
pavelsavara abf7562
Synchronize the JSExport handle table
pavelsavara a47fdf4
Revert the AllowUnsafeBlocks removal from JSImport
pavelsavara File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
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
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
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
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
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
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
55 changes: 55 additions & 0 deletions
55
....JavaScript/src/System/Runtime/InteropServices/JavaScript/JSHostImplementation.Exports.cs
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,55 @@ | ||
| // Licensed to the .NET Foundation under one or more agreements. | ||
| // The .NET Foundation licenses this file to you under the MIT license. | ||
|
|
||
| using System.Diagnostics.CodeAnalysis; | ||
| using System.Reflection; | ||
|
|
||
| namespace System.Runtime.InteropServices.JavaScript | ||
| { | ||
| internal static partial class JSHostImplementation | ||
| { | ||
| [UnconditionalSuppressMessage("Trimming", "IL2026", Justification = "It's kept from trimming by DynamicDependencyAttribute in the generated code.")] | ||
| [UnconditionalSuppressMessage("Trimming", "IL2075", Justification = "It's kept from trimming by DynamicDependencyAttribute in the generated code.")] | ||
| public static unsafe JSFunctionBinding BindManagedFunction(string fullyQualifiedName, int signatureHash, ReadOnlySpan<JSMarshalerType> signatures) | ||
| { | ||
| var ctx = JSProxyContext.BindingContextOrMain(); | ||
| var (assemblyName, nameSpace, shortClassName, methodName) = ParseFQN(fullyQualifiedName); | ||
| var wrapperName = $"__Wrapper_{methodName}_{signatureHash}"; | ||
| // reflection wants '+' between nested types, but the JS side walks the export tree on '/', so keep shortClassName as parsed | ||
| var reflectionClassName = shortClassName.Replace('/', '+'); | ||
|
|
||
| // get MethodInfo from the fully qualified name | ||
| var assembly = Assembly.Load(new AssemblyName(assemblyName)); | ||
| var clazz = string.IsNullOrEmpty(nameSpace) | ||
| ? assembly.GetType(reflectionClassName) | ||
| : assembly.GetType(nameSpace + "." + reflectionClassName); | ||
| if (clazz == null) | ||
| { | ||
| Environment.FailFast($"Can't find {nameSpace}{shortClassName} in {assemblyName} assembly"); | ||
| } | ||
| var wrapperInfo = clazz.GetMethod(wrapperName, BindingFlags.Static | BindingFlags.NonPublic); | ||
| if (wrapperInfo == null) | ||
| { | ||
| Environment.FailFast($"Can't find method wrapper {wrapperName} in {nameSpace}.{shortClassName} in {assemblyName} assembly"); | ||
| } | ||
|
|
||
| Action<IntPtr> wrapper = (IntPtr args) => | ||
| { | ||
| object boxedLegacyArgs = Pointer.Box((void*)args, typeof(JSMarshalerArgument*)); | ||
| // real signature is void (JSMarshalerArgument* args) | ||
| wrapperInfo.Invoke(null, new object?[] { boxedLegacyArgs }); | ||
| }; | ||
|
|
||
| int methodHandle = ctx.AllocJSExportHandle(wrapper); | ||
|
|
||
| var signature = GetMethodSignature(signatures, null, null); | ||
|
|
||
| // this will hit JS side possibly on another thread, depending on JSProxyContext.CurrentThreadContext | ||
| JavaScriptImports.BindCSFunction(methodHandle, assemblyName, nameSpace, shortClassName, methodName, signatureHash, (IntPtr)signature.Header); | ||
|
|
||
| FreeMethodSignatureBuffer(signature); | ||
|
|
||
| return signature; | ||
| } | ||
| } | ||
| } | ||
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
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
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
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
Oops, something went wrong.
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.