|
|
@@ -1,6 +1,7 @@
|
|
|
// Copyright (c) .NET Foundation. All rights reserved.
|
|
|
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
|
|
|
|
|
+using System;
|
|
|
using System.Text.Json;
|
|
|
using Microsoft.JSInterop.Infrastructure;
|
|
|
using WebAssembly.JSInterop;
|
|
|
@@ -60,32 +61,50 @@ namespace Microsoft.JSInterop.WebAssembly
|
|
|
BeginInvokeJS(0, "DotNet.jsCallDispatcher.endInvokeDotNetFromJS", args, JSCallResultType.Default, 0);
|
|
|
}
|
|
|
|
|
|
- /// <inheritdoc />
|
|
|
- TResult IJSUnmarshalledRuntime.InvokeUnmarshalled<TResult>(string identifier)
|
|
|
- => ((IJSUnmarshalledRuntime)this).InvokeUnmarshalled<object, object, object, TResult>(identifier, null, null, null);
|
|
|
-
|
|
|
- /// <inheritdoc />
|
|
|
- TResult IJSUnmarshalledRuntime.InvokeUnmarshalled<T0, TResult>(string identifier, T0 arg0)
|
|
|
- => ((IJSUnmarshalledRuntime)this).InvokeUnmarshalled<T0, object, object, TResult>(identifier, arg0, null, null);
|
|
|
-
|
|
|
- /// <inheritdoc />
|
|
|
- TResult IJSUnmarshalledRuntime.InvokeUnmarshalled<T0, T1, TResult>(string identifier, T0 arg0, T1 arg1)
|
|
|
- => ((IJSUnmarshalledRuntime)this).InvokeUnmarshalled<T0, T1, object, TResult>(identifier, arg0, arg1, null);
|
|
|
-
|
|
|
- /// <inheritdoc />
|
|
|
- TResult IJSUnmarshalledRuntime.InvokeUnmarshalled<T0, T1, T2, TResult>(string identifier, T0 arg0, T1 arg1, T2 arg2)
|
|
|
+ internal TResult InvokeUnmarshalled<T0, T1, T2, TResult>(string identifier, T0 arg0, T1 arg1, T2 arg2, long targetInstanceId)
|
|
|
{
|
|
|
+ var resultType = JSCallResultTypeHelper.FromGeneric<TResult>();
|
|
|
+
|
|
|
var callInfo = new JSCallInfo
|
|
|
{
|
|
|
FunctionIdentifier = identifier,
|
|
|
- ResultType = JSCallResultTypeHelper.FromGeneric<TResult>()
|
|
|
+ TargetInstanceId = targetInstanceId,
|
|
|
+ ResultType = resultType,
|
|
|
};
|
|
|
|
|
|
- var result = InternalCalls.InvokeJS<T0, T1, T2, TResult>(out var exception, ref callInfo, arg0, arg1, arg2);
|
|
|
+ string exception;
|
|
|
|
|
|
- return exception != null
|
|
|
- ? throw new JSException(exception)
|
|
|
- : result;
|
|
|
+ switch (resultType)
|
|
|
+ {
|
|
|
+ case JSCallResultType.Default:
|
|
|
+ var result = InternalCalls.InvokeJS<T0, T1, T2, TResult>(out exception, ref callInfo, arg0, arg1, arg2);
|
|
|
+ return exception != null
|
|
|
+ ? throw new JSException(exception)
|
|
|
+ : result;
|
|
|
+ case JSCallResultType.JSObjectReference:
|
|
|
+ var id = InternalCalls.InvokeJS<T0, T1, T2, int>(out exception, ref callInfo, arg0, arg1, arg2);
|
|
|
+ return exception != null
|
|
|
+ ? throw new JSException(exception)
|
|
|
+ : (TResult)(object)new WebAssemblyJSObjectReference(this, id);
|
|
|
+ default:
|
|
|
+ throw new InvalidOperationException($"Invalid result type '{resultType}'.");
|
|
|
+ }
|
|
|
}
|
|
|
+
|
|
|
+ /// <inheritdoc />
|
|
|
+ public TResult InvokeUnmarshalled<TResult>(string identifier)
|
|
|
+ => InvokeUnmarshalled<object, object, object, TResult>(identifier, null, null, null, 0);
|
|
|
+
|
|
|
+ /// <inheritdoc />
|
|
|
+ public TResult InvokeUnmarshalled<T0, TResult>(string identifier, T0 arg0)
|
|
|
+ => InvokeUnmarshalled<T0, object, object, TResult>(identifier, arg0, null, null, 0);
|
|
|
+
|
|
|
+ /// <inheritdoc />
|
|
|
+ public TResult InvokeUnmarshalled<T0, T1, TResult>(string identifier, T0 arg0, T1 arg1)
|
|
|
+ => InvokeUnmarshalled<T0, T1, object, TResult>(identifier, arg0, arg1, null, 0);
|
|
|
+
|
|
|
+ /// <inheritdoc />
|
|
|
+ public TResult InvokeUnmarshalled<T0, T1, T2, TResult>(string identifier, T0 arg0, T1 arg1, T2 arg2)
|
|
|
+ => InvokeUnmarshalled<T0, T1, T2, TResult>(identifier, arg0, arg1, arg2, 0);
|
|
|
}
|
|
|
}
|