From 3afdb87d42311ac45514e515ff5b9dec2cb1b13f Mon Sep 17 00:00:00 2001 From: pavelsavara Date: Fri, 3 Mar 2023 20:35:10 +0100 Subject: [PATCH 1/5] WasmEnableLegacyJsInterop --- eng/testing/tests.wasm.targets | 6 ++++ .../Directory.Build.props | 1 + ....Runtime.InteropServices.JavaScript.csproj | 29 ++++++++++++------- .../JavaScript/Interop/JavaScriptImports.cs | 4 ++- .../JavaScript/Interop/LegacyExports.cs | 3 +- .../JavaScript/JSFunctionBinding.cs | 2 -- .../JavaScript/JSHostImplementation.cs | 7 ----- .../JavaScript/JSObject.References.cs | 6 ++-- .../JavaScript/Legacy/Array.cs | 2 +- .../Legacy/LegacyHostImplementation.cs | 7 +++++ .../JavaScript/Legacy/Runtime.cs | 4 +-- ...ervices.JavaScript.Legacy.UnitTests.csproj | 10 +++++-- ...me.InteropServices.JavaScript.Tests.csproj | 2 ++ .../JavaScript/JSImportExportTest.cs | 2 ++ ...rosoft.NET.Runtime.WebAssembly.Sdk.pkgproj | 1 + .../ILLink.Descriptors.LegacyJsInterop.xml | 24 +++++++++++++++ src/mono/wasm/build/WasmApp.targets | 4 +++ .../wasm/runtime/net6-legacy/corebindings.ts | 2 +- src/mono/wasm/wasm.proj | 1 + 19 files changed, 86 insertions(+), 31 deletions(-) create mode 100644 src/mono/wasm/build/ILLink.Descriptors.LegacyJsInterop.xml diff --git a/eng/testing/tests.wasm.targets b/eng/testing/tests.wasm.targets index dab07a052796a0..62f0868a2405d5 100644 --- a/eng/testing/tests.wasm.targets +++ b/eng/testing/tests.wasm.targets @@ -33,6 +33,7 @@ helix helix local + true @@ -49,6 +50,11 @@ <_ExtraTrimmerArgs Condition="'$(WasmEnableSIMD)' == 'true' and '$(RunAOTCompilation)' == 'true'">$(_ExtraTrimmerArgs) --substitutions "$(MonoProjectRoot)\wasm\build\ILLink.Substitutions.WasmIntrinsics.xml" <_ExtraTrimmerArgs Condition="'$(WasmEnableSIMD)' != 'true' or '$(RunAOTCompilation)' != 'true'">$(_ExtraTrimmerArgs) --substitutions "$(MonoProjectRoot)\wasm\build\ILLink.Substitutions.NoWasmIntrinsics.xml" + + + <_AOT_InternalForceInterpretAssemblies Include="@(HighAotMemoryUsageAssembly)" /> diff --git a/src/installer/pkg/sfx/Microsoft.NETCore.App/Directory.Build.props b/src/installer/pkg/sfx/Microsoft.NETCore.App/Directory.Build.props index 848f426f9667c2..34cbaab41709a4 100644 --- a/src/installer/pkg/sfx/Microsoft.NETCore.App/Directory.Build.props +++ b/src/installer/pkg/sfx/Microsoft.NETCore.App/Directory.Build.props @@ -252,6 +252,7 @@ + diff --git a/src/libraries/System.Runtime.InteropServices.JavaScript/src/System.Runtime.InteropServices.JavaScript.csproj b/src/libraries/System.Runtime.InteropServices.JavaScript/src/System.Runtime.InteropServices.JavaScript.csproj index 606ce13a347b5e..63943ca27389fa 100644 --- a/src/libraries/System.Runtime.InteropServices.JavaScript/src/System.Runtime.InteropServices.JavaScript.csproj +++ b/src/libraries/System.Runtime.InteropServices.JavaScript/src/System.Runtime.InteropServices.JavaScript.csproj @@ -2,8 +2,6 @@ $(NetCoreAppCurrent)-browser;$(NetCoreAppCurrent) true - true - $(DefineConstants);FEATURE_WASM_THREADS false @@ -11,6 +9,12 @@ $([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) SR.SystemRuntimeInteropServicesJavaScript_PlatformNotSupported + true + $(DefineConstants);FEATURE_WASM_THREADS + $(DefineConstants);ENABLE_LEGACY_JS_INTEROP + $(MonoProjectRoot)wasm\build\ILLink.Descriptors.LegacyJsInterop.xml @@ -22,15 +26,6 @@ - - - - - - - - - @@ -69,6 +64,18 @@ + + + + + + + + + + + + diff --git a/src/libraries/System.Runtime.InteropServices.JavaScript/src/System/Runtime/InteropServices/JavaScript/Interop/JavaScriptImports.cs b/src/libraries/System.Runtime.InteropServices.JavaScript/src/System/Runtime/InteropServices/JavaScript/Interop/JavaScriptImports.cs index 36ea076bd4c5e1..fd7a9f6c6bde85 100644 --- a/src/libraries/System.Runtime.InteropServices.JavaScript/src/System/Runtime/InteropServices/JavaScript/Interop/JavaScriptImports.cs +++ b/src/libraries/System.Runtime.InteropServices.JavaScript/src/System/Runtime/InteropServices/JavaScript/Interop/JavaScriptImports.cs @@ -20,6 +20,7 @@ public static void MarshalPromise(Span arguments) } } +#if ENABLE_LEGACY_JS_INTEROP #region legacy public static object GetGlobalObject(string? str = null) @@ -30,7 +31,7 @@ public static object GetGlobalObject(string? str = null) if (exception != 0) throw new JSException(SR.Format(SR.ErrorResolvingFromGlobalThis, str)); - JSHostImplementation.ReleaseInFlight(jsObj); + LegacyHostImplementation.ReleaseInFlight(jsObj); return jsObj; } @@ -44,5 +45,6 @@ public static IntPtr CreateCSOwnedObject(string typeName, object[] parms) } #endregion +#endif } } diff --git a/src/libraries/System.Runtime.InteropServices.JavaScript/src/System/Runtime/InteropServices/JavaScript/Interop/LegacyExports.cs b/src/libraries/System.Runtime.InteropServices.JavaScript/src/System/Runtime/InteropServices/JavaScript/Interop/LegacyExports.cs index a73cca5fd482e2..431f83e9fff874 100644 --- a/src/libraries/System.Runtime.InteropServices.JavaScript/src/System/Runtime/InteropServices/JavaScript/Interop/LegacyExports.cs +++ b/src/libraries/System.Runtime.InteropServices.JavaScript/src/System/Runtime/InteropServices/JavaScript/Interop/LegacyExports.cs @@ -9,8 +9,7 @@ namespace System.Runtime.InteropServices.JavaScript { - // this maps to src\mono\wasm\runtime\legacy\corebindings.ts - // the public methods are protected from trimming by DynamicDependency on JSFunctionBinding.BindJSFunction + // the public methods are protected from trimming by ILLink.Descriptors.LegacyJsInterop.xml internal static unsafe partial class LegacyExports { public static void GetCSOwnedObjectByJSHandleRef(nint jsHandle, int shouldAddInflight, out JSObject? result) diff --git a/src/libraries/System.Runtime.InteropServices.JavaScript/src/System/Runtime/InteropServices/JavaScript/JSFunctionBinding.cs b/src/libraries/System.Runtime.InteropServices.JavaScript/src/System/Runtime/InteropServices/JavaScript/JSFunctionBinding.cs index a4a07ab5139bac..6b2518472d9c48 100644 --- a/src/libraries/System.Runtime.InteropServices.JavaScript/src/System/Runtime/InteropServices/JavaScript/JSFunctionBinding.cs +++ b/src/libraries/System.Runtime.InteropServices.JavaScript/src/System/Runtime/InteropServices/JavaScript/JSFunctionBinding.cs @@ -142,8 +142,6 @@ public static void InvokeJS(JSFunctionBinding signature, SpanThe method is executed on an architecture other than WebAssembly. // JavaScriptExports need to be protected from trimming because they are used from C/JS code which IL linker can't see [DynamicDependency(DynamicallyAccessedMemberTypes.PublicMethods, "System.Runtime.InteropServices.JavaScript.JavaScriptExports", "System.Runtime.InteropServices.JavaScript")] - // TODO make this DynamicDependency conditional - [DynamicDependency(DynamicallyAccessedMemberTypes.PublicMethods, "System.Runtime.InteropServices.JavaScript.LegacyExports", "System.Runtime.InteropServices.JavaScript")] public static JSFunctionBinding BindJSFunction(string functionName, string moduleName, ReadOnlySpan signatures) { if (RuntimeInformation.OSArchitecture != Architecture.Wasm) diff --git a/src/libraries/System.Runtime.InteropServices.JavaScript/src/System/Runtime/InteropServices/JavaScript/JSHostImplementation.cs b/src/libraries/System.Runtime.InteropServices.JavaScript/src/System/Runtime/InteropServices/JavaScript/JSHostImplementation.cs index c573311897eab3..cdb3c3ad3f4698 100644 --- a/src/libraries/System.Runtime.InteropServices.JavaScript/src/System/Runtime/InteropServices/JavaScript/JSHostImplementation.cs +++ b/src/libraries/System.Runtime.InteropServices.JavaScript/src/System/Runtime/InteropServices/JavaScript/JSHostImplementation.cs @@ -42,13 +42,6 @@ public static void ReleaseCSOwnedObject(nint jsHandle) throw new InvalidOperationException(); } - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static void ReleaseInFlight(object obj) - { - JSObject? jsObj = obj as JSObject; - jsObj?.ReleaseInFlight(); - } - // A JSOwnedObject is a managed object with its lifetime controlled by javascript. // The managed side maintains a strong reference to the object, while the JS side // maintains a weak reference and notifies the managed side if the JS wrapper object diff --git a/src/libraries/System.Runtime.InteropServices.JavaScript/src/System/Runtime/InteropServices/JavaScript/JSObject.References.cs b/src/libraries/System.Runtime.InteropServices.JavaScript/src/System/Runtime/InteropServices/JavaScript/JSObject.References.cs index 17622520a01a1d..0544ab4e2e8805 100644 --- a/src/libraries/System.Runtime.InteropServices.JavaScript/src/System/Runtime/InteropServices/JavaScript/JSObject.References.cs +++ b/src/libraries/System.Runtime.InteropServices.JavaScript/src/System/Runtime/InteropServices/JavaScript/JSObject.References.cs @@ -10,17 +10,18 @@ public partial class JSObject { internal nint JSHandle; +#if ENABLE_LEGACY_JS_INTEROP internal GCHandle? InFlight; internal int InFlightCounter; +#endif private bool _isDisposed; internal JSObject(IntPtr jsHandle) { JSHandle = jsHandle; - InFlight = null; - InFlightCounter = 0; } +#if ENABLE_LEGACY_JS_INTEROP internal void AddInFlight() { ObjectDisposedException.ThrowIf(IsDisposed, this); @@ -53,6 +54,7 @@ internal void ReleaseInFlight() } } } +#endif /// public override bool Equals([NotNullWhen(true)] object? obj) => obj is JSObject other && JSHandle == other.JSHandle; diff --git a/src/libraries/System.Runtime.InteropServices.JavaScript/src/System/Runtime/InteropServices/JavaScript/Legacy/Array.cs b/src/libraries/System.Runtime.InteropServices.JavaScript/src/System/Runtime/InteropServices/JavaScript/Legacy/Array.cs index 00fa785a898468..987a2d2fd8bf0c 100644 --- a/src/libraries/System.Runtime.InteropServices.JavaScript/src/System/Runtime/InteropServices/JavaScript/Legacy/Array.cs +++ b/src/libraries/System.Runtime.InteropServices.JavaScript/src/System/Runtime/InteropServices/JavaScript/Legacy/Array.cs @@ -91,7 +91,7 @@ public object this[int i] if (exception != 0) throw new JSException((string)indexValue); - JSHostImplementation.ReleaseInFlight(indexValue); + LegacyHostImplementation.ReleaseInFlight(indexValue); return indexValue; } set diff --git a/src/libraries/System.Runtime.InteropServices.JavaScript/src/System/Runtime/InteropServices/JavaScript/Legacy/LegacyHostImplementation.cs b/src/libraries/System.Runtime.InteropServices.JavaScript/src/System/Runtime/InteropServices/JavaScript/Legacy/LegacyHostImplementation.cs index 840d25acf5edce..d24a1decdff638 100644 --- a/src/libraries/System.Runtime.InteropServices.JavaScript/src/System/Runtime/InteropServices/JavaScript/Legacy/LegacyHostImplementation.cs +++ b/src/libraries/System.Runtime.InteropServices.JavaScript/src/System/Runtime/InteropServices/JavaScript/Legacy/LegacyHostImplementation.cs @@ -10,6 +10,13 @@ namespace System.Runtime.InteropServices.JavaScript [SupportedOSPlatform("browser")] internal static class LegacyHostImplementation { + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static void ReleaseInFlight(object obj) + { + JSObject? jsObj = obj as JSObject; + jsObj?.ReleaseInFlight(); + } + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static void RegisterCSOwnedObject(JSObject proxy) { diff --git a/src/libraries/System.Runtime.InteropServices.JavaScript/src/System/Runtime/InteropServices/JavaScript/Legacy/Runtime.cs b/src/libraries/System.Runtime.InteropServices.JavaScript/src/System/Runtime/InteropServices/JavaScript/Legacy/Runtime.cs index aba7806ff60f8e..13147c81020525 100644 --- a/src/libraries/System.Runtime.InteropServices.JavaScript/src/System/Runtime/InteropServices/JavaScript/Legacy/Runtime.cs +++ b/src/libraries/System.Runtime.InteropServices.JavaScript/src/System/Runtime/InteropServices/JavaScript/Legacy/Runtime.cs @@ -39,7 +39,7 @@ public static object Invoke(this JSObject self, string method, params object?[] Interop.Runtime.InvokeJSWithArgsRef(self.JSHandle, method, args, out int exception, out object res); if (exception != 0) throw new JSException((string)res); - JSHostImplementation.ReleaseInFlight(res); + LegacyHostImplementation.ReleaseInFlight(res); return res; } @@ -74,7 +74,7 @@ public static object GetObjectProperty(this JSObject self, string name) Interop.Runtime.GetObjectPropertyRef(self.JSHandle, name, out int exception, out object propertyValue); if (exception != 0) throw new JSException((string)propertyValue); - JSHostImplementation.ReleaseInFlight(propertyValue); + LegacyHostImplementation.ReleaseInFlight(propertyValue); return propertyValue; } diff --git a/src/libraries/System.Runtime.InteropServices.JavaScript/tests/System.Runtime.InteropServices.JavaScript.Legacy.UnitTests/System.Runtime.InteropServices.JavaScript.Legacy.UnitTests.csproj b/src/libraries/System.Runtime.InteropServices.JavaScript/tests/System.Runtime.InteropServices.JavaScript.Legacy.UnitTests/System.Runtime.InteropServices.JavaScript.Legacy.UnitTests.csproj index b310c819c66749..eae66e4e4a9c9a 100644 --- a/src/libraries/System.Runtime.InteropServices.JavaScript/tests/System.Runtime.InteropServices.JavaScript.Legacy.UnitTests/System.Runtime.InteropServices.JavaScript.Legacy.UnitTests.csproj +++ b/src/libraries/System.Runtime.InteropServices.JavaScript/tests/System.Runtime.InteropServices.JavaScript.Legacy.UnitTests/System.Runtime.InteropServices.JavaScript.Legacy.UnitTests.csproj @@ -5,8 +5,11 @@ true $(WasmXHarnessArgs) --engine-arg=--expose-gc --web-server-use-cop 0612 + true + $(DefineConstants);ENABLE_LEGACY_JS_INTEROP - + + @@ -16,9 +19,12 @@ + + + + - diff --git a/src/libraries/System.Runtime.InteropServices.JavaScript/tests/System.Runtime.InteropServices.JavaScript.UnitTests/System.Runtime.InteropServices.JavaScript.Tests.csproj b/src/libraries/System.Runtime.InteropServices.JavaScript/tests/System.Runtime.InteropServices.JavaScript.UnitTests/System.Runtime.InteropServices.JavaScript.Tests.csproj index 2db86ee5eb768e..f34edc44b25721 100644 --- a/src/libraries/System.Runtime.InteropServices.JavaScript/tests/System.Runtime.InteropServices.JavaScript.UnitTests/System.Runtime.InteropServices.JavaScript.Tests.csproj +++ b/src/libraries/System.Runtime.InteropServices.JavaScript/tests/System.Runtime.InteropServices.JavaScript.UnitTests/System.Runtime.InteropServices.JavaScript.Tests.csproj @@ -4,6 +4,8 @@ $(NetCoreAppCurrent)-browser true $(WasmXHarnessArgs) --engine-arg=--expose-gc --web-server-use-cop + true + $(DefineConstants);ENABLE_LEGACY_JS_INTEROP true diff --git a/src/libraries/System.Runtime.InteropServices.JavaScript/tests/System.Runtime.InteropServices.JavaScript.UnitTests/System/Runtime/InteropServices/JavaScript/JSImportExportTest.cs b/src/libraries/System.Runtime.InteropServices.JavaScript/tests/System.Runtime.InteropServices.JavaScript.UnitTests/System/Runtime/InteropServices/JavaScript/JSImportExportTest.cs index 49063ad5e76e67..30e97fe180a192 100644 --- a/src/libraries/System.Runtime.InteropServices.JavaScript/tests/System.Runtime.InteropServices.JavaScript.UnitTests/System/Runtime/InteropServices/JavaScript/JSImportExportTest.cs +++ b/src/libraries/System.Runtime.InteropServices.JavaScript/tests/System.Runtime.InteropServices.JavaScript.UnitTests/System/Runtime/InteropServices/JavaScript/JSImportExportTest.cs @@ -58,8 +58,10 @@ public unsafe void GlobalThis() [Fact] public unsafe void DotnetInstance() { +#if ENABLE_LEGACY_JS_INTEROP Assert.True(JSHost.DotnetInstance.HasProperty("MONO")); Assert.Equal("object", JSHost.DotnetInstance.GetTypeOfProperty("MONO")); +#endif JSHost.DotnetInstance.SetProperty("testBool", true); Assert.Equal("boolean", JSHost.DotnetInstance.GetTypeOfProperty("testBool")); diff --git a/src/mono/nuget/Microsoft.NET.Runtime.WebAssembly.Sdk/Microsoft.NET.Runtime.WebAssembly.Sdk.pkgproj b/src/mono/nuget/Microsoft.NET.Runtime.WebAssembly.Sdk/Microsoft.NET.Runtime.WebAssembly.Sdk.pkgproj index f99071471c0ee9..55c5c211b895e7 100644 --- a/src/mono/nuget/Microsoft.NET.Runtime.WebAssembly.Sdk/Microsoft.NET.Runtime.WebAssembly.Sdk.pkgproj +++ b/src/mono/nuget/Microsoft.NET.Runtime.WebAssembly.Sdk/Microsoft.NET.Runtime.WebAssembly.Sdk.pkgproj @@ -13,6 +13,7 @@ + diff --git a/src/mono/wasm/build/ILLink.Descriptors.LegacyJsInterop.xml b/src/mono/wasm/build/ILLink.Descriptors.LegacyJsInterop.xml new file mode 100644 index 00000000000000..eaa9ab362f1311 --- /dev/null +++ b/src/mono/wasm/build/ILLink.Descriptors.LegacyJsInterop.xml @@ -0,0 +1,24 @@ + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/mono/wasm/build/WasmApp.targets b/src/mono/wasm/build/WasmApp.targets index 8eaecaf217364b..6cf8f68324760c 100644 --- a/src/mono/wasm/build/WasmApp.targets +++ b/src/mono/wasm/build/WasmApp.targets @@ -135,6 +135,10 @@ + + diff --git a/src/mono/wasm/runtime/net6-legacy/corebindings.ts b/src/mono/wasm/runtime/net6-legacy/corebindings.ts index 1850aeaa611a5d..97f660910a5c23 100644 --- a/src/mono/wasm/runtime/net6-legacy/corebindings.ts +++ b/src/mono/wasm/runtime/net6-legacy/corebindings.ts @@ -88,7 +88,7 @@ export function init_legacy_exports(): void { legacyHelpers.runtime_legacy_exports_classname = "LegacyExports"; legacyHelpers.runtime_legacy_exports_class = cwraps.mono_wasm_assembly_find_class(runtimeHelpers.runtime_interop_module, runtimeHelpers.runtime_interop_namespace, legacyHelpers.runtime_legacy_exports_classname); if (!legacyHelpers.runtime_legacy_exports_class) - throw "Can't find " + runtimeHelpers.runtime_interop_namespace + "." + runtimeHelpers.runtime_interop_exports_classname + " class"; + throw "Can't find " + runtimeHelpers.runtime_interop_namespace + "." + legacyHelpers.runtime_legacy_exports_classname + " class"; for (const sig of fn_signatures) { const wf: any = legacyManagedExports; diff --git a/src/mono/wasm/wasm.proj b/src/mono/wasm/wasm.proj index 06f877690ff76e..09bb566ef1bdd3 100644 --- a/src/mono/wasm/wasm.proj +++ b/src/mono/wasm/wasm.proj @@ -27,6 +27,7 @@ $([MSBuild]::NormalizeDirectory('$(PkgMicrosoft_NETCore_Runtime_ICU_Transport)', 'runtimes', 'browser-wasm', 'native', 'lib')) $([MSBuild]::NormalizeDirectory('$(PkgMicrosoft_NETCore_Runtime_ICU_Transport)', 'runtimes', 'browser-wasm-threads', 'native', 'lib')) false + true false emcc $(ArtifactsObjDir)wasm From 8f727acbae0afcfd249d4fb20a08e57552daa20c Mon Sep 17 00:00:00 2001 From: pavelsavara Date: Fri, 3 Mar 2023 21:06:44 +0100 Subject: [PATCH 2/5] wip --- src/mono/wasm/wasm.proj | 1 - 1 file changed, 1 deletion(-) diff --git a/src/mono/wasm/wasm.proj b/src/mono/wasm/wasm.proj index 09bb566ef1bdd3..e8978cb24c7fcd 100644 --- a/src/mono/wasm/wasm.proj +++ b/src/mono/wasm/wasm.proj @@ -20,7 +20,6 @@ true false true - true From 2ec51f3725c8473198cdce32e2179f21cc3cce7e Mon Sep 17 00:00:00 2001 From: pavelsavara Date: Sat, 4 Mar 2023 00:24:51 +0100 Subject: [PATCH 3/5] feedback --- eng/testing/tests.browser.targets | 6 ++++++ eng/testing/tests.wasm.targets | 6 ------ 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/eng/testing/tests.browser.targets b/eng/testing/tests.browser.targets index 203183c4dfdc3e..77c702193ad49c 100644 --- a/eng/testing/tests.browser.targets +++ b/eng/testing/tests.browser.targets @@ -30,6 +30,7 @@ _GetRuntimePackNuGetsToBuild;_GetNugetsForAOT;$(GetNuGetsToBuildForWorkloadTestingDependsOn) <_BundleAOTTestWasmAppForHelixDependsOn>$(_BundleAOTTestWasmAppForHelixDependsOn);PrepareForWasmBuildApp;_PrepareForAOTOnHelix + true @@ -126,6 +127,11 @@ + + + true diff --git a/eng/testing/tests.wasm.targets b/eng/testing/tests.wasm.targets index 62f0868a2405d5..dab07a052796a0 100644 --- a/eng/testing/tests.wasm.targets +++ b/eng/testing/tests.wasm.targets @@ -33,7 +33,6 @@ helix helix local - true @@ -50,11 +49,6 @@ <_ExtraTrimmerArgs Condition="'$(WasmEnableSIMD)' == 'true' and '$(RunAOTCompilation)' == 'true'">$(_ExtraTrimmerArgs) --substitutions "$(MonoProjectRoot)\wasm\build\ILLink.Substitutions.WasmIntrinsics.xml" <_ExtraTrimmerArgs Condition="'$(WasmEnableSIMD)' != 'true' or '$(RunAOTCompilation)' != 'true'">$(_ExtraTrimmerArgs) --substitutions "$(MonoProjectRoot)\wasm\build\ILLink.Substitutions.NoWasmIntrinsics.xml" - - - <_AOT_InternalForceInterpretAssemblies Include="@(HighAotMemoryUsageAssembly)" /> From bce0f38e6b32c97143dd4176d601a2b665171cdf Mon Sep 17 00:00:00 2001 From: pavelsavara Date: Tue, 7 Mar 2023 13:59:44 +0100 Subject: [PATCH 4/5] revert back to USE_PTHREADS symbol --- src/mono/wasm/build/WasmApp.Native.targets | 1 - src/mono/wasm/runtime/es6/dotnet.es6.lib.js | 14 +++++++++++--- src/mono/wasm/wasm.proj | 2 +- 3 files changed, 12 insertions(+), 5 deletions(-) diff --git a/src/mono/wasm/build/WasmApp.Native.targets b/src/mono/wasm/build/WasmApp.Native.targets index f0f20741ae15c6..a89540b1627a48 100644 --- a/src/mono/wasm/build/WasmApp.Native.targets +++ b/src/mono/wasm/build/WasmApp.Native.targets @@ -258,7 +258,6 @@ - diff --git a/src/mono/wasm/runtime/es6/dotnet.es6.lib.js b/src/mono/wasm/runtime/es6/dotnet.es6.lib.js index 3669e0349d2d86..6c511fe49347f2 100644 --- a/src/mono/wasm/runtime/es6/dotnet.es6.lib.js +++ b/src/mono/wasm/runtime/es6/dotnet.es6.lib.js @@ -4,9 +4,17 @@ "use strict"; -const monoWasmThreads = process.env.MonoWasmThreads == "true"; -const WasmEnableLegacyJsInterop = process.env.WasmEnableLegacyJsInterop === "true"; -const isPThread = monoWasmThreads ? "ENVIRONMENT_IS_PTHREAD" : "false"; +// USE_PTHREADS is emscripten's define symbol, which is passed to acorn optimizer, so we could use it here +#if USE_PTHREADS +const monoWasmThreads = true; +const isPThread = `ENVIRONMENT_IS_PTHREAD`; +#else +const monoWasmThreads = false; +const isPThread = "false"; +#endif + +// because we can't pass custom define symbols to acorn optimizer, we use environment variables to pass other build options +const WasmEnableLegacyJsInterop = process.env.WasmEnableLegacyJsInterop !== "false"; const DotnetSupportLib = { $DOTNET: {}, diff --git a/src/mono/wasm/wasm.proj b/src/mono/wasm/wasm.proj index e8978cb24c7fcd..348f2c1ca98c8d 100644 --- a/src/mono/wasm/wasm.proj +++ b/src/mono/wasm/wasm.proj @@ -400,7 +400,7 @@ + EnvironmentVariables="WasmEnableLegacyJsInterop=$(WasmEnableLegacyJsInterop)" /> From 0a9fbb00812f5b15ea5fd37580b1924ed992712d Mon Sep 17 00:00:00 2001 From: pavelsavara Date: Wed, 8 Mar 2023 07:29:58 +0100 Subject: [PATCH 5/5] feedback --- .../src/System.Runtime.InteropServices.JavaScript.csproj | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/libraries/System.Runtime.InteropServices.JavaScript/src/System.Runtime.InteropServices.JavaScript.csproj b/src/libraries/System.Runtime.InteropServices.JavaScript/src/System.Runtime.InteropServices.JavaScript.csproj index 63943ca27389fa..4e4ac9c91394e8 100644 --- a/src/libraries/System.Runtime.InteropServices.JavaScript/src/System.Runtime.InteropServices.JavaScript.csproj +++ b/src/libraries/System.Runtime.InteropServices.JavaScript/src/System.Runtime.InteropServices.JavaScript.csproj @@ -9,7 +9,8 @@ $([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) SR.SystemRuntimeInteropServicesJavaScript_PlatformNotSupported - true + true + true $(DefineConstants);FEATURE_WASM_THREADS $(DefineConstants);ENABLE_LEGACY_JS_INTEROP