Skip to content
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

[wasm] reduce MethodImplOptions.NoInlining #79457

Merged
merged 4 commits into from
Dec 12, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/libraries/Common/src/Interop/Browser/Interop.Runtime.cs
Original file line number Diff line number Diff line change
@@ -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)]
Original file line number Diff line number Diff line change
@@ -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<int>? 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<T1,T2,T3TRes>(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<T>(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)
Original file line number Diff line number Diff line change
@@ -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<JSMarshalerArgument> arguments)
{
fixed (JSMarshalerArgument* ptr = arguments)
@@ -23,7 +22,6 @@ public static void MarshalPromise(Span<JSMarshalerArgument> 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);
Original file line number Diff line number Diff line change
@@ -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<object>();
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);
Original file line number Diff line number Diff line change
@@ -198,7 +198,6 @@ internal static unsafe void InvokeImportImpl(IntPtr fnHandle, Span<JSMarshalerAr
}
}

[MethodImpl(MethodImplOptions.NoInlining)]
internal static unsafe JSFunctionBinding BindJSFunctionImpl(string functionName, string moduleName, ReadOnlySpan<JSMarshalerType> 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<JSMarshalerType> signatures)
{
var signature = JSHostImplementation.GetMethodSignature(signatures);
Original file line number Diff line number Diff line change
@@ -83,7 +83,6 @@ internal Array(IntPtr jsHandle) : base(jsHandle)
/// <param name="i">The index.</param>
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();
Original file line number Diff line number Diff line change
@@ -32,7 +32,6 @@ public static object GetGlobalObject(string str)
/// valuews.
/// </para>
/// </returns>
[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.
/// </para>
/// </returns>
[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[]) </param>
/// <param name="createIfNotExists">Defaults to <see langword="true"/> and creates the property on the javascript object if not found, if set to <see langword="false"/> it will not create the property if it does not exist. If the property exists, the value is updated with the provided value.</param>
/// <param name="hasOwnProperty"></param>
[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);
Original file line number Diff line number Diff line change
@@ -36,7 +36,6 @@ public int Length

public static implicit operator Uint8Array(Span<byte> 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<byte> span)
{
// source has to be instantiated.
21 changes: 11 additions & 10 deletions src/mono/wasm/runtime/corebindings.c
Original file line number Diff line number Diff line change
@@ -37,24 +37,25 @@ 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);
mono_add_internal_call ("Interop/Runtime::BindCSFunction", mono_wasm_bind_cs_function);
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)
3 changes: 2 additions & 1 deletion src/mono/wasm/runtime/invoke-cs.ts
Original file line number Diff line number Diff line change
@@ -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());
18 changes: 15 additions & 3 deletions src/mono/wasm/runtime/invoke-js.ts
Original file line number Diff line number Diff line change
@@ -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_
(<any>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, <any>fn_handle);
setI32_unchecked(function_js_handle, <any>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, <any>result);
}

// to set out parameters of icalls
export function wrap_no_error_root(is_exception: Int32Ptr | null, result?: WasmRoot<MonoObject>): void {
if (is_exception) {
setI32_unchecked(is_exception, 0);
}
if (result) {
result.clear();
}
}
3 changes: 2 additions & 1 deletion src/mono/wasm/runtime/net6-legacy/buffers.ts
Original file line number Diff line number Diff line change
@@ -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 {
3 changes: 2 additions & 1 deletion src/mono/wasm/runtime/net6-legacy/cs-to-js.ts
Original file line number Diff line number Diff line change
@@ -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;
3 changes: 2 additions & 1 deletion src/mono/wasm/runtime/net6-legacy/js-to-cs.ts
Original file line number Diff line number Diff line change
@@ -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 {
17 changes: 7 additions & 10 deletions src/mono/wasm/runtime/net6-legacy/method-calls.ts
Original file line number Diff line number Diff line change
@@ -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 {