mirror of
https://github.com/OutSystems/CefGlue.git
synced 2026-12-04 22:02:28 +00:00
5c6f7ebe7f
* Preserve references in serialization to allow deeper structures to be serialized * Clean unwanted changes * Fix NativeObject DateTime interop tests * CR improvements * Remove duplication in Directory.Build.props * Simplify deserializer state logic. Improve resources usage and performance * Add missing RootObjectDeserializerState file * Remove unwanted whitespaces on Directory.Build.props * Refactor DerserializerState classes and simplify Deserializer logic * CR improvements. Drop DynamicDeserializerState. * Optimize TypeInfoCache, not loading Properties and Fields for collections and primitive types * CR improvements * Fix EvaluateScript for try catch blocks - "Uncaught SyntaxError: Unexpected token 'try'" * Fix SampleApp EvaluateJavascript that were missing the return keyword * Fix deserialization of null as structures * CR improvement
50 lines
1.7 KiB
C#
50 lines
1.7 KiB
C#
using System;
|
|
using System.Linq;
|
|
using Xilium.CefGlue.Common.Shared.RendererProcessCommunication;
|
|
using Xilium.CefGlue.Common.Shared.Serialization;
|
|
|
|
namespace Xilium.CefGlue.BrowserProcess.ObjectBinding
|
|
{
|
|
internal class V8FunctionHandler : CefV8Handler
|
|
{
|
|
private readonly string _objectName;
|
|
private readonly Func<Messages.NativeObjectCallRequest, PromiseHolder> _functionCallHandler;
|
|
|
|
public V8FunctionHandler(string objectName, Func<Messages.NativeObjectCallRequest, PromiseHolder> functionCallHandler)
|
|
{
|
|
_objectName = objectName;
|
|
_functionCallHandler = functionCallHandler;
|
|
}
|
|
|
|
protected override bool Execute(string name, CefV8Value obj, CefV8Value[] arguments, out CefV8Value returnValue, out string exception)
|
|
{
|
|
if (arguments.Length > 1)
|
|
{
|
|
throw new ArgumentException($"The array must be either empty or contain only one argument, a json string. The array has {arguments.Length} elements.", nameof(arguments));
|
|
}
|
|
|
|
var message = new Messages.NativeObjectCallRequest()
|
|
{
|
|
ObjectName = _objectName,
|
|
MemberName = name,
|
|
ArgumentsAsJson = arguments.FirstOrDefault()?.GetStringValue() ?? string.Empty
|
|
};
|
|
|
|
var promiseHolder = _functionCallHandler(message);
|
|
|
|
if (promiseHolder != null)
|
|
{
|
|
returnValue = promiseHolder.Promise;
|
|
exception = null;
|
|
}
|
|
else
|
|
{
|
|
returnValue = null;
|
|
exception = "Failed to create promise";
|
|
}
|
|
|
|
return true;
|
|
}
|
|
}
|
|
}
|