From f029a22f4571c0b86a76eab3c6b5a05c702e08da Mon Sep 17 00:00:00 2001 From: ieremyashev Date: Mon, 23 Oct 2017 14:24:04 +0500 Subject: [PATCH] Fix return value serialization for async JS bindings (#2167) --- CefSharp.Example/AsyncBoundObject.cs | 8 ++++++++ CefSharp.Example/Resources/BindingTest.html | 11 +++++++++++ CefSharp/Internals/JavascriptObjectRepository.cs | 5 +++++ 3 files changed, 24 insertions(+) diff --git a/CefSharp.Example/AsyncBoundObject.cs b/CefSharp.Example/AsyncBoundObject.cs index 14bbfc13f0..c95e031e40 100644 --- a/CefSharp.Example/AsyncBoundObject.cs +++ b/CefSharp.Example/AsyncBoundObject.cs @@ -39,6 +39,14 @@ public void DoSomething() Thread.Sleep(1000); } + public JsObject ReturnObject(string name) + { + return new JsObject + { + Value = name + }; + } + public JsObject[] ObjectArray(string name) { return new[] diff --git a/CefSharp.Example/Resources/BindingTest.html b/CefSharp.Example/Resources/BindingTest.html index b23c6cc7fc..c9ef6199d1 100644 --- a/CefSharp.Example/Resources/BindingTest.html +++ b/CefSharp.Example/Resources/BindingTest.html @@ -83,6 +83,16 @@ }); } + function asyncObject() + { + var call = "Async call (Object): " + Date(); + boundAsync.returnObject('CefSharp').then(function (res) { + + var end = "Result: " + JSON.stringify(res) + " (" + Date() + ")"; + writeAsyncResult(call, end); + }); + } + function asyncObjectArray() { var call = "Async call (ObjectArray): " + Date(); @@ -98,6 +108,7 @@ asyncDivFail(); asyncDoSomething(); asyncHello(); + asyncObject(); asyncObjectArray();

diff --git a/CefSharp/Internals/JavascriptObjectRepository.cs b/CefSharp/Internals/JavascriptObjectRepository.cs index c368823df2..0f66a365c4 100644 --- a/CefSharp/Internals/JavascriptObjectRepository.cs +++ b/CefSharp/Internals/JavascriptObjectRepository.cs @@ -410,6 +410,11 @@ private static bool IsComplexType(Type type) return false; } + if (baseType.IsValueType && !baseType.IsPrimitive && !baseType.IsEnum) + { + return false; + } + return !baseType.IsPrimitive && baseType != typeof(string); }