// 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.
namespace Microsoft.JSInterop
{
///
/// Abstract base class for an in-process JavaScript runtime.
///
public abstract class JSInProcessRuntimeBase : JSRuntimeBase, IJSInProcessRuntime
{
///
/// Invokes the specified JavaScript function synchronously.
///
/// The JSON-serializable return type.
/// An identifier for the function to invoke. For example, the value "someScope.someFunction" will invoke the function window.someScope.someFunction.
/// JSON-serializable arguments.
/// An instance of obtained by JSON-deserializing the return value.
public T Invoke(string identifier, params object[] args)
{
var resultJson = InvokeJS(identifier, Json.Serialize(args, ArgSerializerStrategy));
return Json.Deserialize(resultJson, ArgSerializerStrategy);
}
///
/// Performs a synchronous function invocation.
///
/// The identifier for the function to invoke.
/// A JSON representation of the arguments.
/// A JSON representation of the result.
protected abstract string InvokeJS(string identifier, string argsJson);
}
}