Skip to content

Commit f09b7b5

Browse files
committed
wip
1 parent eec5790 commit f09b7b5

File tree

42 files changed

+3575
-114
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+3575
-114
lines changed

eng/testing/tests.browser.targets

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
<EMSDK_PATH Condition="'$(EMSDK_PATH)' == '' and '$(ContinuousIntegrationBuild)' == 'true' and '$(MonoProjectRoot)' != ''">$([MSBuild]::NormalizeDirectory($(BrowserProjectRoot), 'emsdk'))</EMSDK_PATH>
1313

1414
<WasmEmitSymbolMap Condition="'$(WasmEmitSymbolMap)' == ''">true</WasmEmitSymbolMap>
15+
<InvariantGlobalization Condition="'$(InvariantGlobalization)' == ''">false</InvariantGlobalization>
1516

1617
<_WasmMainJSFileName Condition="'$(WasmMainJSPath)' != ''">$([System.IO.Path]::GetFileName('$(WasmMainJSPath)'))</_WasmMainJSFileName>
1718
<_WasmStrictVersionMatch Condition="'$(ContinuousIntegrationBuild)' == 'true'">true</_WasmStrictVersionMatch>
@@ -34,6 +35,9 @@
3435
<UseSystemResourceKeys Condition="'$(UseSystemResourceKeys)' == ''">false</UseSystemResourceKeys>
3536
<EventSourceSupport Condition="'$(EventSourceSupport)' == ''">true</EventSourceSupport>
3637
<NullabilityInfoContextSupport Condition="'$(NullabilityInfoContextSupport)' == ''">true</NullabilityInfoContextSupport>
38+
39+
<!-- TODO-WASM https://github.com/dotnet/runtime/issues/120248 -->
40+
<WasmEnableWebcil Condition="'$(RuntimeFlavor)' == 'CoreCLR'">false</WasmEnableWebcil>
3741
</PropertyGroup>
3842

3943
<!-- We expect WASM users to indicate they would like to have bigger download size by adding WasmIncludeFullIcuData, -->

eng/testing/workloads-browser.targets

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
<Target Name="_GetWorkloadsToInstall" DependsOnTargets="_SetPackageVersionForWorkloadsTesting" Returns="@(WorkloadIdForTesting);@(WorkloadCombinationsToInstall)">
1010
<Error Condition="'$(RIDForWorkload)' == ''" Text="$(RIDForWorkload) is unset" />
11-
<ItemGroup>
11+
<ItemGroup Condition="'$(RuntimeFlavor)' == 'Mono'">
1212
<WorkloadIdForTesting Include="wasm-tools;wasm-experimental"
1313
ManifestName="Microsoft.NET.Workload.Mono.ToolChain.Current"
1414
Variant="latest"
@@ -67,11 +67,15 @@
6767
</_DefaultRuntimePackNuGetPath>
6868
</PropertyGroup>
6969

70-
<ItemGroup>
70+
<ItemGroup Condition="'$(RuntimeFlavor)' == 'Mono'">
7171
<_RuntimePackNugetAvailable Include="$(LibrariesShippingPackagesDir)Microsoft.NETCore.App.Runtime.Mono.$(RIDForWorkload).*$(PackageVersionForWorkloadManifests).nupkg" />
7272
<_RuntimePackNugetAvailable Include="$(LibrariesShippingPackagesDir)Microsoft.NETCore.App.Runtime.Mono.*.$(RIDForWorkload).*$(PackageVersionForWorkloadManifests).nupkg" />
7373
<_RuntimePackNugetAvailable Remove="@(_RuntimePackNugetAvailable)" Condition="$([System.String]::new('%(_RuntimePackNugetAvailable.FileName)').EndsWith('.symbols'))" />
7474
</ItemGroup>
75+
<ItemGroup Condition="'$(RuntimeFlavor)' == 'CoreCLR'">
76+
<_RuntimePackNugetAvailable Include="$(LibrariesShippingPackagesDir)Microsoft.NETCore.App.Runtime.$(RIDForWorkload).*$(PackageVersionForWorkloadManifests).nupkg" />
77+
<_RuntimePackNugetAvailable Remove="@(_RuntimePackNugetAvailable)" Condition="$([System.String]::new('%(_RuntimePackNugetAvailable.FileName)').EndsWith('.symbols'))" />
78+
</ItemGroup>
7579

7680
<Error Condition="@(_RuntimePackNugetAvailable -> Count()) != 2 and @(_RuntimePackNugetAvailable -> Count()) != 1"
7781
Text="Expected to find either one or two in $(LibrariesShippingPackagesDir): @(_RuntimePackNugetAvailable->'%(FileName)%(Extension)')" />
@@ -87,7 +91,7 @@
8791
</ItemGroup>
8892

8993
<Message
90-
Condition="@(_RuntimePackNugetAvailable -> Count()) == 1"
94+
Condition="'$(RuntimeFlavor)' == 'Mono' and @(_RuntimePackNugetAvailable -> Count()) == 1"
9195
Importance="High"
9296
Text="
9397
********************

src/coreclr/vm/wasm/helpers.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -618,6 +618,10 @@ namespace
618618
if (!GetSignatureKey(sig, keyBuffer, keyBufferLen))
619619
return NULL;
620620

621+
void* thunk = LookupThunk(keyBuffer);
622+
if (thunk == NULL)
623+
printf("WASM Calli missing for Key: %s\n", keyBuffer);
624+
621625
return LookupThunk(keyBuffer);
622626
}
623627

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
// Licensed to the .NET Foundation under one or more agreements.
2+
// The .NET Foundation licenses this file to you under the MIT license.
3+
4+
using System;
5+
using System.Reflection;
6+
using System.Runtime.CompilerServices;
7+
using System.Runtime.InteropServices;
8+
9+
internal static partial class Interop
10+
{
11+
internal static unsafe partial class Runtime
12+
{
13+
[LibraryImport(Libraries.JavaScriptNative, EntryPoint = "SystemInteropJS_BindJSImportST")]
14+
public static unsafe partial nint BindJSImportST(void* signature);
15+
16+
[LibraryImport(Libraries.JavaScriptNative, EntryPoint = "SystemInteropJS_InvokeJSImportST")]
17+
public static partial void InvokeJSImportST(int importHandle, nint args);
18+
19+
[LibraryImport(Libraries.JavaScriptNative, EntryPoint = "SystemInteropJS_ReleaseCSOwnedObject")]
20+
internal static partial void ReleaseCSOwnedObject(nint jsHandle);
21+
22+
[LibraryImport(Libraries.JavaScriptNative, EntryPoint = "SystemInteropJS_InvokeJSFunction")]
23+
public static partial void InvokeJSFunction(nint functionHandle, nint data);
24+
25+
[LibraryImport(Libraries.JavaScriptNative, EntryPoint = "SystemInteropJS_ResolveOrRejectPromise")]
26+
public static partial void ResolveOrRejectPromise(nint data);
27+
28+
[LibraryImport(Libraries.JavaScriptNative, EntryPoint = "SystemInteropJS_RegisterGCRoot")]
29+
public static partial nint RegisterGCRoot(void* start, int bytesSize, IntPtr name);
30+
[LibraryImport(Libraries.JavaScriptNative, EntryPoint = "SystemInteropJS_DeregisterGCRoot")]
31+
public static partial void DeregisterGCRoot(nint handle);
32+
33+
[LibraryImport(Libraries.JavaScriptNative, EntryPoint = "SystemInteropJS_CancelPromise")]
34+
public static partial void CancelPromise(nint gcHandle);
35+
36+
[LibraryImport(Libraries.JavaScriptNative, EntryPoint = "SystemInteropJS_BindAssemblyExports")]
37+
public static partial void BindAssemblyExports(IntPtr assemblyNamePtr);
38+
[LibraryImport(Libraries.JavaScriptNative, EntryPoint = "SystemInteropJS_GetAssemblyExport")]
39+
public static partial void GetAssemblyExport(IntPtr assemblyNamePtr, IntPtr namespacePtr, IntPtr classnamePtr, IntPtr methodNamePtr, int signatureHash, IntPtr* methodHandlePtr);
40+
41+
// TODO-WASM: delete once we switch to CoreCLR only
42+
[LibraryImport(Libraries.JavaScriptNative, EntryPoint = "SystemInteropJS_AssemblyGetEntryPoint")]
43+
public static partial void AssemblyGetEntryPoint(IntPtr assemblyNamePtr, int auto_insert_breakpoint, void** monoMethodPtrPtr);
44+
}
45+
}

src/libraries/Common/src/Interop/Browser/Interop.Runtime.cs renamed to src/libraries/Common/src/Interop/Browser/Interop.Runtime.Mono.cs

File renamed without changes.

src/libraries/Common/src/Interop/Unix/Interop.Libraries.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ internal static partial class Libraries
1313
internal const string CryptoNative = "libSystem.Security.Cryptography.Native.OpenSsl";
1414
internal const string CompressionNative = "libSystem.IO.Compression.Native";
1515
internal const string GlobalizationNative = "libSystem.Globalization.Native";
16+
internal const string JavaScriptNative = "libSystem.Runtime.InteropServices.JavaScript.Native";
1617
internal const string IOPortsNative = "libSystem.IO.Ports.Native";
1718
internal const string HostPolicy = "libhostpolicy";
1819
}

src/libraries/System.Runtime.InteropServices.JavaScript/src/System.Runtime.InteropServices.JavaScript.csproj

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,12 @@
1212
<GeneratePlatformNotSupportedAssemblyMessage Condition="'$(TargetPlatformIdentifier)' != 'browser'">SR.SystemRuntimeInteropServicesJavaScript_PlatformNotSupported</GeneratePlatformNotSupportedAssemblyMessage>
1313
<FeatureWasmManagedThreads Condition="'$(TargetPlatformIdentifier)' == 'browser' and '$(WasmEnableThreads)' == 'true'">true</FeatureWasmManagedThreads>
1414
<WasmEnableJsInteropByValue Condition="'$(TargetPlatformIdentifier)' == 'browser' and '$(WasmEnableJsInteropByValue)' == '' and '$(FeatureWasmManagedThreads)' == 'true'">true</WasmEnableJsInteropByValue>
15+
<WasmEnableJsInteropByValue Condition="'$(TargetPlatformIdentifier)' == 'browser' and '$(WasmEnableJsInteropByValue)' == '' and '$(RuntimeFlavor)' == 'CoreCLR'">true</WasmEnableJsInteropByValue>
1516
<WasmEnableJsInteropByValue Condition="'$(TargetPlatformIdentifier)' == 'browser' and '$(WasmEnableJsInteropByValue)' == ''">false</WasmEnableJsInteropByValue>
1617
<DefineConstants Condition="'$(FeatureWasmManagedThreads)' == 'true'">$(DefineConstants);FEATURE_WASM_MANAGED_THREADS</DefineConstants>
1718
<DefineConstants Condition="'$(WasmEnableJsInteropByValue)' == 'true'">$(DefineConstants);ENABLE_JS_INTEROP_BY_VALUE</DefineConstants>
19+
<DefineConstants Condition="'$(RuntimeFlavor)' == 'Mono'">$(DefineConstants);MONO</DefineConstants>
20+
<DefineConstants Condition="'$(RuntimeFlavor)' == 'CoreCLR'">$(DefineConstants);CORECLR</DefineConstants>
1821
<EmitCompilerGeneratedFiles Condition="'$(Configuration)' == 'Debug' and '$(TargetPlatformIdentifier)' == 'browser'">true</EmitCompilerGeneratedFiles>
1922
</PropertyGroup>
2023

@@ -23,9 +26,12 @@
2326
</ItemGroup>
2427

2528
<ItemGroup Condition="'$(TargetPlatformIdentifier)' == 'browser'">
26-
<Compile Include="$(CommonPath)Interop\Browser\Interop.Runtime.cs" Link="System\Runtime\InteropServices\JavaScript\Interop\Interop.Runtime.cs" />
29+
<Compile Include="$(CommonPath)Interop\Browser\Interop.Runtime.Mono.cs" Link="System\Runtime\InteropServices\JavaScript\Interop\Interop.Runtime.Mono.cs" Condition="'$(RuntimeFlavor)' == 'Mono'" />
30+
<Compile Include="$(CommonPath)Interop\Browser\Interop.Runtime.CoreCLR.cs" Link="System\Runtime\InteropServices\JavaScript\Interop\Interop.Runtime.CoreCLR.cs" Condition="'$(RuntimeFlavor)' == 'CoreCLR'" />
31+
<Compile Include="$(CommonPath)Interop\Unix\Interop.Libraries.cs" Link="System\Runtime\InteropServices\JavaScript\Interop\Interop.Libraries.cs" Condition="'$(RuntimeFlavor)' == 'CoreCLR'" />
2732
<Compile Include="System\Runtime\InteropServices\JavaScript\Interop\JavaScriptImports.Generated.cs" />
28-
<Compile Include="System\Runtime\InteropServices\JavaScript\Interop\JavaScriptExports.cs" />
33+
<Compile Include="System\Runtime\InteropServices\JavaScript\Interop\JavaScriptExports.Mono.cs" Condition="'$(RuntimeFlavor)' == 'Mono'" />
34+
<Compile Include="System\Runtime\InteropServices\JavaScript\Interop\JavaScriptExports.CoreCLR.cs" Condition="'$(RuntimeFlavor)' == 'CoreCLR'" />
2935

3036
<Compile Include="System\Runtime\InteropServices\JavaScript\JSHost.cs" />
3137
<Compile Include="System\Runtime\InteropServices\JavaScript\JSMarshalerType.cs" />
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,155 @@
1+
// Licensed to the .NET Foundation under one or more agreements.
2+
// The .NET Foundation licenses this file to you under the MIT license.
3+
4+
using System.Collections.Generic;
5+
using System.Diagnostics;
6+
using System.Diagnostics.CodeAnalysis;
7+
using System.Reflection;
8+
using System.Runtime.CompilerServices;
9+
using System.Threading;
10+
using System.Threading.Tasks;
11+
12+
namespace System.Runtime.InteropServices.JavaScript
13+
{
14+
// this maps to src\native\libs\System.Runtime.InteropServices.JavaScript.Native\interop\managed-exports.ts
15+
// the public methods are protected from trimming by DynamicDependency on JSFunctionBinding.BindJSFunction
16+
internal static unsafe partial class JavaScriptExports
17+
{
18+
[UnmanagedCallersOnly(EntryPoint = "SystemInteropJS_ReleaseJSOwnedObjectByGCHandle")]
19+
// The JS layer invokes this method when the JS wrapper for a JS owned object has been collected by the JS garbage collector
20+
// the marshaled signature is: void ReleaseJSOwnedObjectByGCHandle(GCHandle gcHandle)
21+
public static void ReleaseJSOwnedObjectByGCHandle(JSMarshalerArgument* arguments_buffer)
22+
{
23+
ref JSMarshalerArgument arg_exc = ref arguments_buffer[0]; // initialized by caller in alloc_stack_frame()
24+
ref JSMarshalerArgument arg_1 = ref arguments_buffer[2]; // initialized and set by caller
25+
26+
try
27+
{
28+
// when we arrive here, we are on the thread which owns the proxies or on IO thread
29+
var ctx = arg_exc.ToManagedContext;
30+
ctx.ReleaseJSOwnedObjectByGCHandle(arg_1.slot.GCHandle);
31+
}
32+
catch (Exception ex)
33+
{
34+
Environment.FailFast($"ReleaseJSOwnedObjectByGCHandle: Unexpected synchronous failure (ManagedThreadId {Environment.CurrentManagedThreadId}): " + ex);
35+
}
36+
}
37+
38+
[UnmanagedCallersOnly(EntryPoint = "SystemInteropJS_CallDelegate")]
39+
// the marshaled signature is: TRes? CallDelegate<T1,T2,T3TRes>(GCHandle callback, T1? arg1, T2? arg2, T3? arg3)
40+
public static void CallDelegate(JSMarshalerArgument* arguments_buffer)
41+
{
42+
ref JSMarshalerArgument arg_exc = ref arguments_buffer[0]; // initialized by JS caller in alloc_stack_frame()
43+
// arg_res is initialized by JS caller
44+
ref JSMarshalerArgument arg_1 = ref arguments_buffer[2];// initialized and set by JS caller
45+
// arg_2 set by JS caller when there are arguments
46+
// arg_3 set by JS caller when there are arguments
47+
// arg_4 set by JS caller when there are arguments
48+
try
49+
{
50+
GCHandle callback_gc_handle = (GCHandle)arg_1.slot.GCHandle;
51+
if (callback_gc_handle.Target is JSHostImplementation.ToManagedCallback callback)
52+
{
53+
// arg_2, arg_3, arg_4, arg_res are processed by the callback
54+
callback(arguments_buffer);
55+
}
56+
else
57+
{
58+
throw new InvalidOperationException(SR.NullToManagedCallback);
59+
}
60+
}
61+
catch (Exception ex)
62+
{
63+
arg_exc.ToJS(ex);
64+
}
65+
}
66+
67+
[UnmanagedCallersOnly(EntryPoint = "SystemInteropJS_CompleteTask")]
68+
// the marshaled signature is: void CompleteTask<T>(GCHandle holder, Exception? exceptionResult, T? result)
69+
public static void CompleteTask(JSMarshalerArgument* arguments_buffer)
70+
{
71+
ref JSMarshalerArgument arg_exc = ref arguments_buffer[0]; // initialized by caller in alloc_stack_frame()
72+
ref JSMarshalerArgument arg_res = ref arguments_buffer[1]; // initialized by caller in alloc_stack_frame()
73+
ref JSMarshalerArgument arg_1 = ref arguments_buffer[2];// initialized and set by caller
74+
// arg_2 set by caller when this is SetException call
75+
// arg_3 set by caller when this is SetResult call
76+
77+
try
78+
{
79+
// when we arrive here, we are on the thread which owns the proxies or on IO thread
80+
var ctx = arg_exc.ToManagedContext;
81+
var holder = ctx.GetPromiseHolder(arg_1.slot.GCHandle);
82+
JSHostImplementation.ToManagedCallback callback;
83+
84+
callback = holder.Callback!;
85+
ctx.ReleasePromiseHolder(arg_1.slot.GCHandle);
86+
87+
// arg_2, arg_3 are processed by the callback
88+
// JSProxyContext.PopOperation() is called by the callback
89+
callback!(arguments_buffer);
90+
}
91+
catch (Exception ex)
92+
{
93+
Environment.FailFast($"CompleteTask: Unexpected synchronous failure (ManagedThreadId {Environment.CurrentManagedThreadId}): " + ex);
94+
}
95+
}
96+
97+
[UnmanagedCallersOnly(EntryPoint = "SystemInteropJS_GetManagedStackTrace")]
98+
// the marshaled signature is: string GetManagedStackTrace(GCHandle exception)
99+
public static void GetManagedStackTrace(JSMarshalerArgument* arguments_buffer)
100+
{
101+
ref JSMarshalerArgument arg_exc = ref arguments_buffer[0]; // initialized by caller in alloc_stack_frame()
102+
ref JSMarshalerArgument arg_res = ref arguments_buffer[1]; // used as return value
103+
ref JSMarshalerArgument arg_1 = ref arguments_buffer[2];// initialized and set by caller
104+
try
105+
{
106+
// when we arrive here, we are on the thread which owns the proxies
107+
arg_exc.AssertCurrentThreadContext();
108+
109+
GCHandle exception_gc_handle = (GCHandle)arg_1.slot.GCHandle;
110+
if (exception_gc_handle.Target is Exception exception)
111+
{
112+
arg_res.ToJS(exception.StackTrace);
113+
}
114+
else
115+
{
116+
throw new InvalidOperationException(SR.UnableToResolveHandleAsException);
117+
}
118+
}
119+
catch (Exception ex)
120+
{
121+
arg_exc.ToJS(ex);
122+
}
123+
}
124+
125+
[UnmanagedCallersOnly(EntryPoint = "SystemInteropJS_BindAssemblyExports")]
126+
// the marshaled signature is: Task BindAssemblyExports(string assemblyName)
127+
public static void BindAssemblyExports(JSMarshalerArgument* arguments_buffer)
128+
{
129+
ref JSMarshalerArgument arg_exc = ref arguments_buffer[0]; // initialized by caller in alloc_stack_frame()
130+
ref JSMarshalerArgument arg_res = ref arguments_buffer[1]; // used as return value
131+
ref JSMarshalerArgument arg_1 = ref arguments_buffer[2];// initialized and set by caller
132+
try
133+
{
134+
string? assemblyName;
135+
// when we arrive here, we are on the thread which owns the proxies
136+
arg_exc.AssertCurrentThreadContext();
137+
arg_1.ToManaged(out assemblyName);
138+
139+
var result = JSHostImplementation.BindAssemblyExports(assemblyName);
140+
141+
arg_res.ToJS(result);
142+
}
143+
catch (Exception ex)
144+
{
145+
Environment.FailFast($"BindAssemblyExports: Unexpected synchronous failure (ManagedThreadId {Environment.CurrentManagedThreadId}): " + ex);
146+
}
147+
}
148+
149+
[UnmanagedCallersOnly(EntryPoint = "SystemInteropJS_InvokeJSExport")]
150+
// the marshaled signature is: Task BindAssemblyExports(string assemblyName)
151+
public static void InvokeJSExport(JSMarshalerArgument* arguments_buffer)
152+
{
153+
}
154+
}
155+
}

src/libraries/System.Runtime.InteropServices.JavaScript/src/System/Runtime/InteropServices/JavaScript/Interop/JavaScriptExports.cs renamed to src/libraries/System.Runtime.InteropServices.JavaScript/src/System/Runtime/InteropServices/JavaScript/Interop/JavaScriptExports.Mono.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -229,6 +229,9 @@ public static void CompleteTask(JSMarshalerArgument* arguments_buffer)
229229
}
230230
}
231231

232+
#if CORECLR
233+
[UnmanagedCallersOnly(EntryPoint = "SystemInteropJS_GetManagedStackTrace")]
234+
#endif
232235
// the marshaled signature is: string GetManagedStackTrace(GCHandle exception)
233236
public static void GetManagedStackTrace(JSMarshalerArgument* arguments_buffer)
234237
{

0 commit comments

Comments
 (0)