diff --git a/src/libraries/Common/src/Interop/Browser/Interop.Runtime.cs b/src/libraries/Common/src/Interop/Browser/Interop.Runtime.cs index 27762b7ac5d102..202afdf004e271 100644 --- a/src/libraries/Common/src/Interop/Browser/Interop.Runtime.cs +++ b/src/libraries/Common/src/Interop/Browser/Interop.Runtime.cs @@ -6,6 +6,9 @@ internal static partial class Interop { + // WARNING: until https://github.com/dotnet/runtime/issues/37955 is fixed + // make sure that the native side always sets the out parameters + // otherwise out parameters could stay un-initialized, when the method is used in inlined context internal static unsafe partial class Runtime { [MethodImplAttribute(MethodImplOptions.InternalCall)] diff --git a/src/libraries/System.Runtime.InteropServices.JavaScript/src/System/Runtime/InteropServices/JavaScript/Interop/JavaScriptExports.cs b/src/libraries/System.Runtime.InteropServices.JavaScript/src/System/Runtime/InteropServices/JavaScript/Interop/JavaScriptExports.cs index e98a845b758f29..3972c50c8fa62c 100644 --- a/src/libraries/System.Runtime.InteropServices.JavaScript/src/System/Runtime/InteropServices/JavaScript/Interop/JavaScriptExports.cs +++ b/src/libraries/System.Runtime.InteropServices.JavaScript/src/System/Runtime/InteropServices/JavaScript/Interop/JavaScriptExports.cs @@ -11,7 +11,6 @@ namespace System.Runtime.InteropServices.JavaScript // the public methods are protected from trimming by DynamicDependency on JSFunctionBinding.BindJSFunction internal static unsafe partial class JavaScriptExports { - [MethodImpl(MethodImplOptions.NoInlining)] // https://github.com/dotnet/runtime/issues/71425 // the marshaled signature is: // Task? CallEntrypoint(MonoMethod* entrypointPtr, string[] args) public static void CallEntrypoint(JSMarshalerArgument* arguments_buffer) @@ -95,7 +94,6 @@ public static void CallEntrypoint(JSMarshalerArgument* arguments_buffer) // The JS layer invokes this method when the JS wrapper for a JS owned object // has been collected by the JS garbage collector - [MethodImpl(MethodImplOptions.NoInlining)] // https://github.com/dotnet/runtime/issues/71425 // the marshaled signature is: // void ReleaseJSOwnedObjectByGCHandle(GCHandle gcHandle) public static void ReleaseJSOwnedObjectByGCHandle(JSMarshalerArgument* arguments_buffer) @@ -118,7 +116,6 @@ public static void ReleaseJSOwnedObjectByGCHandle(JSMarshalerArgument* arguments } } - [MethodImpl(MethodImplOptions.NoInlining)] // https://github.com/dotnet/runtime/issues/71425 // the marshaled signature is: // GCHandle CreateTaskCallback() public static void CreateTaskCallback(JSMarshalerArgument* arguments_buffer) @@ -137,7 +134,6 @@ public static void CreateTaskCallback(JSMarshalerArgument* arguments_buffer) } } - [MethodImpl(MethodImplOptions.NoInlining)] // https://github.com/dotnet/runtime/issues/71425 // the marshaled signature is: // TRes? CallDelegate(GCHandle callback, T1? arg1, T2? arg2, T3? arg3) public static void CallDelegate(JSMarshalerArgument* arguments_buffer) @@ -167,7 +163,6 @@ public static void CallDelegate(JSMarshalerArgument* arguments_buffer) } } - [MethodImpl(MethodImplOptions.NoInlining)] // https://github.com/dotnet/runtime/issues/71425 // the marshaled signature is: // void CompleteTask(GCHandle holder, Exception? exceptionResult, T? result) public static void CompleteTask(JSMarshalerArgument* arguments_buffer) @@ -195,7 +190,6 @@ public static void CompleteTask(JSMarshalerArgument* arguments_buffer) } } - [MethodImpl(MethodImplOptions.NoInlining)] // https://github.com/dotnet/runtime/issues/71425 // the marshaled signature is: // string GetManagedStackTrace(GCHandle exception) public static void GetManagedStackTrace(JSMarshalerArgument* arguments_buffer) @@ -223,7 +217,6 @@ public static void GetManagedStackTrace(JSMarshalerArgument* arguments_buffer) #if FEATURE_WASM_THREADS - [MethodImpl(MethodImplOptions.NoInlining)] // https://github.com/dotnet/runtime/issues/71425 // the marshaled signature is: // void InstallSynchronizationContext() public static void InstallSynchronizationContext (JSMarshalerArgument* arguments_buffer) { @@ -240,13 +233,13 @@ public static void InstallSynchronizationContext (JSMarshalerArgument* arguments #endif - [MethodImpl(MethodImplOptions.NoInlining)] // https://github.com/dotnet/runtime/issues/71425 + [MethodImpl(MethodImplOptions.NoInlining)] // profiler needs to find it executed under this name public static void StopProfile() { } // Called by the AOT profiler to save profile data into INTERNAL.aotProfileData - [MethodImpl(MethodImplOptions.NoInlining)] // https://github.com/dotnet/runtime/issues/71425 + [MethodImpl(MethodImplOptions.NoInlining)] // profiler needs to find it executed under this name public static unsafe void DumpAotProfileData(ref byte buf, int len, string extraArg) { if (len == 0) 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 4be89d68c844ab..35cf6106c0b873 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 @@ -7,7 +7,6 @@ namespace System.Runtime.InteropServices.JavaScript { internal static unsafe partial class JavaScriptImports { - [MethodImplAttribute(MethodImplOptions.NoInlining)] // https://github.com/dotnet/runtime/issues/71425 public static void MarshalPromise(Span arguments) { fixed (JSMarshalerArgument* ptr = arguments) @@ -23,7 +22,6 @@ public static void MarshalPromise(Span arguments) #region legacy - [MethodImpl(MethodImplOptions.NoInlining)] // https://github.com/dotnet/runtime/issues/71425 public static object GetGlobalObject(string? str = null) { int exception; @@ -36,7 +34,6 @@ public static object GetGlobalObject(string? str = null) return jsObj; } - [MethodImpl(MethodImplOptions.NoInlining)] // https://github.com/dotnet/runtime/issues/71425 public static IntPtr CreateCSOwnedObject(string typeName, object[] parms) { Interop.Runtime.CreateCSOwnedObjectRef(typeName, parms, out int exception, out object res); 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 6aa4a5acf2e577..aa1bf2468dbc1a 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 @@ -13,7 +13,6 @@ namespace System.Runtime.InteropServices.JavaScript // the public methods are protected from trimming by DynamicDependency on JSFunctionBinding.BindJSFunction internal static unsafe partial class LegacyExports { - [MethodImplAttribute(MethodImplOptions.NoInlining)] // https://github.com/dotnet/runtime/issues/71425 public static void GetCSOwnedObjectByJSHandleRef(nint jsHandle, int shouldAddInflight, out JSObject? result) { lock (JSHostImplementation.s_csOwnedObjects) @@ -32,7 +31,6 @@ public static void GetCSOwnedObjectByJSHandleRef(nint jsHandle, int shouldAddInf result = null; } - [MethodImplAttribute(MethodImplOptions.NoInlining)] // https://github.com/dotnet/runtime/issues/71425 public static IntPtr GetCSOwnedObjectJSHandleRef(in JSObject jsObject, int shouldAddInflight) { jsObject.AssertNotDisposed(); @@ -44,7 +42,6 @@ public static IntPtr GetCSOwnedObjectJSHandleRef(in JSObject jsObject, int shoul return jsObject.JSHandle; } - [MethodImplAttribute(MethodImplOptions.NoInlining)] // https://github.com/dotnet/runtime/issues/71425 public static IntPtr TryGetCSOwnedObjectJSHandleRef(in object rawObj, int shouldAddInflight) { JSObject? jsObject = rawObj as JSObject; @@ -55,7 +52,6 @@ public static IntPtr TryGetCSOwnedObjectJSHandleRef(in object rawObj, int should return jsObject?.JSHandle ?? IntPtr.Zero; } - [MethodImplAttribute(MethodImplOptions.NoInlining)] // https://github.com/dotnet/runtime/issues/71425 public static void CreateCSOwnedProxyRef(nint jsHandle, LegacyHostImplementation.MappedType mappedType, int shouldAddInflight, out JSObject jsObject) { JSObject? res = null; @@ -88,27 +84,23 @@ public static void CreateCSOwnedProxyRef(nint jsHandle, LegacyHostImplementation jsObject = res; } - [MethodImplAttribute(MethodImplOptions.NoInlining)] // https://github.com/dotnet/runtime/issues/71425 public static void GetJSOwnedObjectByGCHandleRef(int gcHandle, out object result) { GCHandle h = (GCHandle)(IntPtr)gcHandle; result = h.Target!; } - [MethodImplAttribute(MethodImplOptions.NoInlining)] // https://github.com/dotnet/runtime/issues/71425 public static IntPtr GetJSOwnedObjectGCHandleRef(in object obj) { return JSHostImplementation.GetJSOwnedObjectGCHandle(obj, GCHandleType.Normal); } - [MethodImplAttribute(MethodImplOptions.NoInlining)] // https://github.com/dotnet/runtime/issues/71425 public static IntPtr CreateTaskSource() { var tcs = new TaskCompletionSource(); return GetJSOwnedObjectGCHandleRef(tcs); } - [MethodImplAttribute(MethodImplOptions.NoInlining)] // https://github.com/dotnet/runtime/issues/71425 public static void SetTaskSourceResultRef(int tcsGCHandle, in object result) { GCHandle handle = (GCHandle)(IntPtr)tcsGCHandle; @@ -117,7 +109,6 @@ public static void SetTaskSourceResultRef(int tcsGCHandle, in object result) tcs.SetResult(result); } - [MethodImplAttribute(MethodImplOptions.NoInlining)] // https://github.com/dotnet/runtime/issues/71425 public static void SetTaskSourceFailure(int tcsGCHandle, string reason) { GCHandle handle = (GCHandle)(IntPtr)tcsGCHandle; @@ -126,7 +117,6 @@ public static void SetTaskSourceFailure(int tcsGCHandle, string reason) tcs.SetException(new JSException(reason)); } - [MethodImplAttribute(MethodImplOptions.NoInlining)] // https://github.com/dotnet/runtime/issues/71425 public static void GetTaskSourceTaskRef(int tcsGCHandle, out object result) { GCHandle handle = (GCHandle)(IntPtr)tcsGCHandle; @@ -135,7 +125,6 @@ public static void GetTaskSourceTaskRef(int tcsGCHandle, out object result) result = tcs.Task; } - [MethodImplAttribute(MethodImplOptions.NoInlining)] // https://github.com/dotnet/runtime/issues/71425 public static void SetupJSContinuationRef(in Task _task, JSObject continuationObj) { // HACK: Attempting to use the in-param will produce CS1628, so we make a temporary copy @@ -182,13 +171,11 @@ void Complete() } } - [MethodImplAttribute(MethodImplOptions.NoInlining)] // https://github.com/dotnet/runtime/issues/71425 public static string ObjectToStringRef(ref object o) { return o.ToString() ?? string.Empty; } - [MethodImplAttribute(MethodImplOptions.NoInlining)] // https://github.com/dotnet/runtime/issues/71425 public static double GetDateValueRef(ref object dtv) { ArgumentNullException.ThrowIfNull(dtv); @@ -204,7 +191,6 @@ public static double GetDateValueRef(ref object dtv) // HACK: We need to implicitly box by using an 'object' out-param. // Note that the return value would have been boxed on the C#->JS transition anyway. - [MethodImplAttribute(MethodImplOptions.NoInlining)] // https://github.com/dotnet/runtime/issues/71425 public static void CreateDateTimeRef(double ticks, out object result) { DateTimeOffset unixTime = DateTimeOffset.FromUnixTimeMilliseconds((long)ticks); @@ -218,7 +204,6 @@ public static void CreateDateTimeRef(double ticks, out object result) // System.Private.Uri is ~80KB large assembly so it's worth trimming private static Type? uriType; - [MethodImplAttribute(MethodImplOptions.NoInlining)] // https://github.com/dotnet/runtime/issues/71425 [Diagnostics.CodeAnalysis.UnconditionalSuppressMessage("Trimming", "IL2077", Justification = "Done on purpose, see comment above.")] [Diagnostics.CodeAnalysis.UnconditionalSuppressMessage("Trimming", "IL2057", Justification = "Done on purpose, see comment above.")] public static void CreateUriRef(string uri, out object? result) @@ -241,13 +226,11 @@ public static void CreateUriRef(string uri, out object? result) } } - [MethodImplAttribute(MethodImplOptions.NoInlining)] // https://github.com/dotnet/runtime/issues/71425 public static bool IsSimpleArrayRef(ref object a) { return a is System.Array arr && arr.Rank == 1 && arr.GetLowerBound(0) == 0; } - [MethodImplAttribute(MethodImplOptions.NoInlining)] // https://github.com/dotnet/runtime/issues/71425 public static string GetCallSignatureRef(IntPtr _methodHandle, in object objForRuntimeType) { var methodHandle = JSHostImplementation.GetMethodHandleFromIntPtr(_methodHandle); 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 0b8ce881ba57f8..a4a07ab5139bac 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 @@ -198,7 +198,6 @@ internal static unsafe void InvokeImportImpl(IntPtr fnHandle, Span signatures) { var signature = JSHostImplementation.GetMethodSignature(signatures); @@ -212,7 +211,6 @@ internal static unsafe JSFunctionBinding BindJSFunctionImpl(string functionName, return signature; } - [MethodImpl(MethodImplOptions.NoInlining)] internal static unsafe JSFunctionBinding BindManagedFunctionImpl(string fullyQualifiedName, int signatureHash, ReadOnlySpan signatures) { var signature = JSHostImplementation.GetMethodSignature(signatures); 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 47464304bcb0ed..00fa785a898468 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 @@ -83,7 +83,6 @@ internal Array(IntPtr jsHandle) : base(jsHandle) /// The index. public object this[int i] { - [MethodImpl(MethodImplOptions.NoInlining)] // https://github.com/dotnet/runtime/issues/71425 get { this.AssertNotDisposed(); @@ -95,7 +94,6 @@ public object this[int i] JSHostImplementation.ReleaseInFlight(indexValue); return indexValue; } - [MethodImpl(MethodImplOptions.NoInlining)] // https://github.com/dotnet/runtime/issues/71425 set { this.AssertNotDisposed(); 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 560469891f2910..75f5fa9a26be09 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 @@ -32,7 +32,6 @@ public static object GetGlobalObject(string str) /// valuews. /// /// - [MethodImpl(MethodImplOptions.NoInlining)] // https://github.com/dotnet/runtime/issues/71425 public static object Invoke(this JSObject self, string method, params object?[] args) { ArgumentNullException.ThrowIfNull(self); @@ -67,7 +66,6 @@ public static object Invoke(this JSObject self, string method, params object?[] /// valuews. /// /// - [MethodImpl(MethodImplOptions.NoInlining)] // https://github.com/dotnet/runtime/issues/71425 public static object GetObjectProperty(this JSObject self, string name) { ArgumentNullException.ThrowIfNull(self); @@ -92,7 +90,6 @@ public static object GetObjectProperty(this JSObject self, string name) /// float[], double[]) /// Defaults to and creates the property on the javascript object if not found, if set to it will not create the property if it does not exist. If the property exists, the value is updated with the provided value. /// - [MethodImpl(MethodImplOptions.NoInlining)] // https://github.com/dotnet/runtime/issues/71425 public static void SetObjectProperty(this JSObject self, string name, object? value, bool createIfNotExists = true, bool hasOwnProperty = false) { ArgumentNullException.ThrowIfNull(self); diff --git a/src/libraries/System.Runtime.InteropServices.JavaScript/src/System/Runtime/InteropServices/JavaScript/Legacy/Uint8Array.cs b/src/libraries/System.Runtime.InteropServices.JavaScript/src/System/Runtime/InteropServices/JavaScript/Legacy/Uint8Array.cs index e01202b2398343..a8f8cf2f84e32d 100644 --- a/src/libraries/System.Runtime.InteropServices.JavaScript/src/System/Runtime/InteropServices/JavaScript/Legacy/Uint8Array.cs +++ b/src/libraries/System.Runtime.InteropServices.JavaScript/src/System/Runtime/InteropServices/JavaScript/Legacy/Uint8Array.cs @@ -36,7 +36,6 @@ public int Length public static implicit operator Uint8Array(Span span) => From(span); - [MethodImpl(MethodImplOptions.NoInlining)] // https://github.com/dotnet/runtime/issues/71425 public byte[] ToArray() { this.AssertNotDisposed(); @@ -48,7 +47,6 @@ public byte[] ToArray() return (byte[])res; } - [MethodImpl(MethodImplOptions.NoInlining)] // https://github.com/dotnet/runtime/issues/71425 public static unsafe Uint8Array From(ReadOnlySpan span) { // source has to be instantiated. diff --git a/src/mono/wasm/runtime/corebindings.c b/src/mono/wasm/runtime/corebindings.c index d1b5a9e6842750..ffbb52020432eb 100644 --- a/src/mono/wasm/runtime/corebindings.c +++ b/src/mono/wasm/runtime/corebindings.c @@ -37,17 +37,7 @@ extern void mono_wasm_marshal_promise(void *data); void core_initialize_internals (void) { - mono_add_internal_call ("Interop/Runtime::InvokeJSWithArgsRef", mono_wasm_invoke_js_with_args_ref); - mono_add_internal_call ("Interop/Runtime::GetObjectPropertyRef", mono_wasm_get_object_property_ref); - mono_add_internal_call ("Interop/Runtime::GetByIndexRef", mono_wasm_get_by_index_ref); - mono_add_internal_call ("Interop/Runtime::SetObjectPropertyRef", mono_wasm_set_object_property_ref); - mono_add_internal_call ("Interop/Runtime::SetByIndexRef", mono_wasm_set_by_index_ref); - mono_add_internal_call ("Interop/Runtime::GetGlobalObjectRef", mono_wasm_get_global_object_ref); - mono_add_internal_call ("Interop/Runtime::CreateCSOwnedObjectRef", mono_wasm_create_cs_owned_object_ref); mono_add_internal_call ("Interop/Runtime::ReleaseCSOwnedObject", mono_wasm_release_cs_owned_object); - mono_add_internal_call ("Interop/Runtime::TypedArrayToArrayRef", mono_wasm_typed_array_to_array_ref); - mono_add_internal_call ("Interop/Runtime::TypedArrayFromRef", mono_wasm_typed_array_from_ref); - mono_add_internal_call ("Interop/Runtime::BindJSFunction", mono_wasm_bind_js_function); mono_add_internal_call ("Interop/Runtime::InvokeJSFunction", mono_wasm_invoke_bound_function); mono_add_internal_call ("Interop/Runtime::InvokeImport", mono_wasm_invoke_import); @@ -55,6 +45,17 @@ void core_initialize_internals (void) mono_add_internal_call ("Interop/Runtime::MarshalPromise", mono_wasm_marshal_promise); mono_add_internal_call ("Interop/Runtime::RegisterGCRoot", mono_wasm_register_root); mono_add_internal_call ("Interop/Runtime::DeregisterGCRoot", mono_wasm_deregister_root); + + // legacy + mono_add_internal_call ("Interop/Runtime::InvokeJSWithArgsRef", mono_wasm_invoke_js_with_args_ref); + mono_add_internal_call ("Interop/Runtime::GetObjectPropertyRef", mono_wasm_get_object_property_ref); + mono_add_internal_call ("Interop/Runtime::SetObjectPropertyRef", mono_wasm_set_object_property_ref); + mono_add_internal_call ("Interop/Runtime::GetByIndexRef", mono_wasm_get_by_index_ref); + mono_add_internal_call ("Interop/Runtime::SetByIndexRef", mono_wasm_set_by_index_ref); + mono_add_internal_call ("Interop/Runtime::GetGlobalObjectRef", mono_wasm_get_global_object_ref); + mono_add_internal_call ("Interop/Runtime::TypedArrayToArrayRef", mono_wasm_typed_array_to_array_ref); + mono_add_internal_call ("Interop/Runtime::CreateCSOwnedObjectRef", mono_wasm_create_cs_owned_object_ref); + mono_add_internal_call ("Interop/Runtime::TypedArrayFromRef", mono_wasm_typed_array_from_ref); } // Int8Array | int8_t | byte or SByte (signed byte) diff --git a/src/mono/wasm/runtime/invoke-cs.ts b/src/mono/wasm/runtime/invoke-cs.ts index 961e0a4e428068..5d419ce92defe1 100644 --- a/src/mono/wasm/runtime/invoke-cs.ts +++ b/src/mono/wasm/runtime/invoke-cs.ts @@ -14,7 +14,7 @@ import { mono_assert, MonoObjectRef, MonoStringRef, MonoString, MonoObject, Mono import { Int32Ptr } from "./types/emscripten"; import cwraps from "./cwraps"; import { assembly_load } from "./class-loader"; -import { wrap_error_root } from "./invoke-js"; +import { wrap_error_root, wrap_no_error_root } from "./invoke-js"; import { startMeasure, MeasuredBlock, endMeasure } from "./profiler"; export function mono_wasm_bind_cs_function(fully_qualified_name: MonoStringRef, signature_hash: number, signature: JSFunctionSignature, is_exception: Int32Ptr, result_address: MonoObjectRef): void { @@ -88,6 +88,7 @@ export function mono_wasm_bind_cs_function(fully_qualified_name: MonoStringRef, _walk_exports_to_set_function(assembly, namespace, classname, methodname, signature_hash, bound_fn); endMeasure(mark, MeasuredBlock.bindCsFunction, js_fqn); + wrap_no_error_root(is_exception, resultRoot); } catch (ex: any) { Module.printErr(ex.toString()); diff --git a/src/mono/wasm/runtime/invoke-js.ts b/src/mono/wasm/runtime/invoke-js.ts index 0cee2908032791..72941f70de827f 100644 --- a/src/mono/wasm/runtime/invoke-js.ts +++ b/src/mono/wasm/runtime/invoke-js.ts @@ -3,7 +3,7 @@ import { marshal_exception_to_cs, bind_arg_marshal_to_cs } from "./marshal-to-cs"; import { get_signature_argument_count, bound_js_function_symbol, get_sig, get_signature_version, MarshalerType, get_signature_type, imported_js_function_symbol } from "./marshal"; -import { setI32 } from "./memory"; +import { setI32_unchecked } from "./memory"; import { conv_string_root, js_string_to_mono_string_root } from "./strings"; import { mono_assert, MonoObject, MonoObjectRef, MonoString, MonoStringRef, JSFunctionSignature, JSMarshalerArguments, WasmRoot, BoundMarshalerToJs, JSFnHandle, BoundMarshalerToCs, JSHandle } from "./types"; import { Int32Ptr } from "./types/emscripten"; @@ -84,9 +84,11 @@ export function mono_wasm_bind_js_function(function_name: MonoStringRef, module_ (bound_fn)[imported_js_function_symbol] = true; const fn_handle = fn_wrapper_by_fn_handle.length; fn_wrapper_by_fn_handle.push(bound_fn); - setI32(function_js_handle, fn_handle); + setI32_unchecked(function_js_handle, fn_handle); + wrap_no_error_root(is_exception, resultRoot); endMeasure(mark, MeasuredBlock.bindJsFunction, js_function_name); } catch (ex: any) { + setI32_unchecked(function_js_handle, 0); Module.printErr(ex.toString()); wrap_error_root(is_exception, ex, resultRoot); } finally { @@ -354,7 +356,7 @@ function _wrap_error_flag(is_exception: Int32Ptr | null, ex: any): string { res = mono_wasm_symbolicate_string(res); } if (is_exception) { - Module.setValue(is_exception, 1, "i32"); + setI32_unchecked(is_exception, 1); } return res; } @@ -364,3 +366,13 @@ export function wrap_error_root(is_exception: Int32Ptr | null, ex: any, result: const res = _wrap_error_flag(is_exception, ex); js_string_to_mono_string_root(res, result); } + +// to set out parameters of icalls +export function wrap_no_error_root(is_exception: Int32Ptr | null, result?: WasmRoot): void { + if (is_exception) { + setI32_unchecked(is_exception, 0); + } + if (result) { + result.clear(); + } +} diff --git a/src/mono/wasm/runtime/net6-legacy/buffers.ts b/src/mono/wasm/runtime/net6-legacy/buffers.ts index 37566a4089f678..b82e36a5b69ff4 100644 --- a/src/mono/wasm/runtime/net6-legacy/buffers.ts +++ b/src/mono/wasm/runtime/net6-legacy/buffers.ts @@ -2,7 +2,7 @@ // The .NET Foundation licenses this file to you under the MIT license. import { Module } from "../imports"; -import { wrap_error_root } from "../invoke-js"; +import { wrap_error_root, wrap_no_error_root } from "../invoke-js"; import { mono_wasm_new_external_root } from "../roots"; import { MonoArray, MonoObjectRef, MonoObject } from "../types"; import { Int32Ptr, TypedArray } from "../types/emscripten"; @@ -15,6 +15,7 @@ export function mono_wasm_typed_array_from_ref(pinned_array: MonoArray, begin: n const res = typed_array_from(pinned_array, begin, end, bytes_per_element, type); // returns JS typed array like Int8Array, to be wraped with JSObject proxy js_to_mono_obj_root(res, resultRoot, true); + wrap_no_error_root(is_exception); } catch (exc) { wrap_error_root(is_exception, String(exc), resultRoot); } finally { diff --git a/src/mono/wasm/runtime/net6-legacy/cs-to-js.ts b/src/mono/wasm/runtime/net6-legacy/cs-to-js.ts index 9eb1f1e655d83c..515c261445cd62 100644 --- a/src/mono/wasm/runtime/net6-legacy/cs-to-js.ts +++ b/src/mono/wasm/runtime/net6-legacy/cs-to-js.ts @@ -4,7 +4,7 @@ import { _are_promises_supported } from "../cancelable-promise"; import cwraps from "../cwraps"; import { mono_wasm_get_jsobj_from_js_handle, _lookup_js_owned_object, setup_managed_proxy, mono_wasm_get_js_handle, teardown_managed_proxy, assert_not_disposed } from "../gc-handles"; -import { wrap_error_root } from "../invoke-js"; +import { wrap_error_root, wrap_no_error_root } from "../invoke-js"; import { ManagedObject } from "../marshal"; import { getU32, getI32, getF32, getF64, setI32_unchecked } from "../memory"; import { createPromiseController } from "../promise-controller"; @@ -260,6 +260,7 @@ export function mono_wasm_create_cs_owned_object_ref(core_name: MonoStringRef, a // returns boxed js_handle int, because on exception we need to return String on same method signature // here we don't have anything to in-flight reference, as the JSObject doesn't exist yet js_to_mono_obj_root(js_handle, resultRoot, false); + wrap_no_error_root(is_exception); } catch (ex) { wrap_error_root(is_exception, ex, resultRoot); return; diff --git a/src/mono/wasm/runtime/net6-legacy/js-to-cs.ts b/src/mono/wasm/runtime/net6-legacy/js-to-cs.ts index b555076c900cba..48b9125eb1bf6b 100644 --- a/src/mono/wasm/runtime/net6-legacy/js-to-cs.ts +++ b/src/mono/wasm/runtime/net6-legacy/js-to-cs.ts @@ -5,7 +5,7 @@ import { isThenable } from "../cancelable-promise"; import cwraps from "../cwraps"; import { js_owned_gc_handle_symbol, assert_not_disposed, cs_owned_js_handle_symbol, mono_wasm_get_js_handle, setup_managed_proxy, mono_wasm_release_cs_owned_object, teardown_managed_proxy, mono_wasm_get_jsobj_from_js_handle } from "../gc-handles"; import { Module } from "../imports"; -import { wrap_error_root } from "../invoke-js"; +import { wrap_error_root, wrap_no_error_root } from "../invoke-js"; import { setI32_unchecked, setU32_unchecked, setF64, setB32 } from "../memory"; import { mono_wasm_new_root, mono_wasm_release_roots, mono_wasm_new_external_root } from "../roots"; import { js_string_to_mono_string_root, js_string_to_mono_string_interned_root } from "../strings"; @@ -274,6 +274,7 @@ export function mono_wasm_typed_array_to_array_ref(js_handle: JSHandle, is_excep // returns pointer to C# array js_typed_array_to_array_root(js_obj, resultRoot); + wrap_no_error_root(is_exception); } catch (exc) { wrap_error_root(is_exception, String(exc), resultRoot); } finally { diff --git a/src/mono/wasm/runtime/net6-legacy/method-calls.ts b/src/mono/wasm/runtime/net6-legacy/method-calls.ts index 37790b769be2e4..09fef9c18b3067 100644 --- a/src/mono/wasm/runtime/net6-legacy/method-calls.ts +++ b/src/mono/wasm/runtime/net6-legacy/method-calls.ts @@ -3,7 +3,7 @@ import { get_js_obj, mono_wasm_get_jsobj_from_js_handle } from "../gc-handles"; import { Module, runtimeHelpers, INTERNAL } from "../imports"; -import { wrap_error_root } from "../invoke-js"; +import { wrap_error_root, wrap_no_error_root } from "../invoke-js"; import { _release_temp_frame } from "../memory"; import { mono_wasm_new_external_root, mono_wasm_new_root } from "../roots"; import { find_entry_point } from "../run"; @@ -115,6 +115,7 @@ export function mono_wasm_invoke_js_with_args_ref(js_handle: JSHandle, method_na const res = m.apply(obj, js_args); js_to_mono_obj_root(res, resultRoot, true); + wrap_no_error_root(is_exception); } catch (ex) { wrap_error_root(is_exception, ex, resultRoot); } @@ -143,6 +144,7 @@ export function mono_wasm_get_object_property_ref(js_handle: JSHandle, property_ const m = obj[js_name]; js_to_mono_obj_root(m, resultRoot, true); + wrap_no_error_root(is_exception); } catch (ex) { wrap_error_root(is_exception, ex, resultRoot); } finally { @@ -169,34 +171,27 @@ export function mono_wasm_set_object_property_ref(js_handle: JSHandle, property_ return; } - let result = false; - const js_value = unbox_mono_obj_root(valueRoot); if (createIfNotExist) { js_obj[property] = js_value; - result = true; } else { - result = false; if (!createIfNotExist) { if (!Object.prototype.hasOwnProperty.call(js_obj, property)) { - js_to_mono_obj_root(false, resultRoot, false); return; } } if (hasOwnProperty === true) { if (Object.prototype.hasOwnProperty.call(js_obj, property)) { js_obj[property] = js_value; - result = true; } } else { js_obj[property] = js_value; - result = true; } } - js_to_mono_obj_root(result, resultRoot, false); + wrap_no_error_root(is_exception, resultRoot); } catch (ex) { wrap_error_root(is_exception, ex, resultRoot); } finally { @@ -217,6 +212,7 @@ export function mono_wasm_get_by_index_ref(js_handle: JSHandle, property_index: const m = obj[property_index]; js_to_mono_obj_root(m, resultRoot, true); + wrap_no_error_root(is_exception); } catch (ex) { wrap_error_root(is_exception, ex, resultRoot); } finally { @@ -236,7 +232,7 @@ export function mono_wasm_set_by_index_ref(js_handle: JSHandle, property_index: const js_value = unbox_mono_obj_root(valueRoot); obj[property_index] = js_value; - resultRoot.clear(); + wrap_no_error_root(is_exception, resultRoot); } catch (ex) { wrap_error_root(is_exception, ex, resultRoot); } finally { @@ -273,6 +269,7 @@ export function mono_wasm_get_global_object_ref(global_name: MonoStringRef, is_e } js_to_mono_obj_root(globalObj, resultRoot, true); + wrap_no_error_root(is_exception); } catch (ex) { wrap_error_root(is_exception, ex, resultRoot); } finally {