-
Notifications
You must be signed in to change notification settings - Fork 5.2k
[browser] avoid reflection on JSExport #122024
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
base: main
Are you sure you want to change the base?
Conversation
|
This is the new generated code (simplified) namespace System.Runtime.InteropServices.JavaScript
{
[global::System.Runtime.CompilerServices.CompilerGeneratedAttribute]
unsafe class __GeneratedInitializer
{
static void __Register_()
{
if (initialized || RuntimeInformation.OSArchitecture != Architecture.Wasm)
return;
initialized = true;
JSFunctionBinding.BindManagedFunction(Sample.Test.__Wrapper_PrintMeaning_451547442, "PrintMeaning",
451547442, [JSMarshalerType.Task(), JSMarshalerType.Task(JSMarshalerType.Int32)]);
}
}
}
namespace Sample
{
public unsafe partial class Test
{
[DebuggerNonUserCode]
public static unsafe void __Wrapper_PrintMeaning_451547442(global::System.IntPtr __arguments_ptr)
{
JSMarshalerArgument* __arguments_buffer = (JSMarshalerArgument*)__arguments_ptr;
__Stub(__arguments_buffer[2], __arguments_buffer, __arguments_buffer + 1);
[DebuggerNonUserCode]
void __Stub(JSMarshalerArgument __meaningPromise_native, JSMarshalerArgument* ____arg_exception_native__param, JSMarshalerArgument* __invokeRetValUnmanaged__param)
{
// cut for brevity
}
}
}
} |
This comment was marked as resolved.
This comment was marked as resolved.
Would the unsafe access help with it? |
- implement leagcy reflection in managed code
Alternatively, now that I moved the legacy reflection to managed code, that path still could be used for this scenario. We could keep generating reflection based code for But both ideas feel like overkill to me. So far, I think expecting it to be |
It does not need to be a public type if you use |
Thank you, I didn't know it existed! |
It is resolved when the UnsafeAccessor is JITed or AOT compiled. |
Motivation: make it more CoreCLR and NAOT friendly
This is just rough idea so far:
Action<IntPtr> wrapperduring registration and add that into dictionary on the managed sidevoid (void* args)- we can use single [UMCO] to dispatch the calls from JS side[DynamicDependency]attributes from the generated codeOpen problems so far
Action<IntPtr>public APIJSFunctionBinding.BindManagedFunction- will need API changeJSExports (in nugets) created by Roslyn in Net10 and below are not compatible (breaking change)privateclasses anymore, because the C# registration code can't touch the generated wrapper.internalclasses work just fine.invoke_async_jsexport2is bit of a hack, but consolidation would solve that eventually