diff --git a/CefSharp.Example/AsyncBoundObject.cs b/CefSharp.Example/AsyncBoundObject.cs index 78729ff6ff..02e87aa174 100644 --- a/CefSharp.Example/AsyncBoundObject.cs +++ b/CefSharp.Example/AsyncBoundObject.cs @@ -46,6 +46,14 @@ public JsSerializableStruct ReturnObject(string name) }; } + public JsSerializableClass ReturnClass(string name) + { + return new JsSerializableClass + { + Value = name + }; + } + public JsSerializableStruct[] ReturnStructArray(string name) { return new[] diff --git a/CefSharp.Example/Resources/BindingTest.html b/CefSharp.Example/Resources/BindingTest.html index 8836c90810..333cd071e7 100644 --- a/CefSharp.Example/Resources/BindingTest.html +++ b/CefSharp.Example/Resources/BindingTest.html @@ -227,7 +227,7 @@ }); }); - QUnit.test("Async call (Struct):", function( assert ) + QUnit.test("Async call (return Struct):", function( assert ) { var asyncCallback = assert.async(); @@ -239,7 +239,7 @@ }); }); - QUnit.test("Async call (Class):", function (assert) + QUnit.test("Async call (return Class):", function (assert) { var asyncCallback = assert.async(); @@ -248,7 +248,7 @@ { const expectedResult = 'CefSharp Class Test'; - assert.equal(expectedResult, res.Value, "Class with a single field " + expectedResult); + assert.equal(expectedResult, res.Value, "Class with a single property"); asyncCallback(); }); diff --git a/CefSharp/Internals/JavascriptObjectRepository.cs b/CefSharp/Internals/JavascriptObjectRepository.cs index 9c5670e2e9..33e1942a72 100644 --- a/CefSharp/Internals/JavascriptObjectRepository.cs +++ b/CefSharp/Internals/JavascriptObjectRepository.cs @@ -266,7 +266,10 @@ public bool TryCallMethod(long objectId, string name, object[] parameters, out o throw new InvalidOperationException("Could not execute method: " + name + "(" + String.Join(", ", parameters) + ") " + (missingParams > 0 ? "- Missing Parameters: " + missingParams : ""), e); } - if(result != null && IsComplexType(result.GetType())) + //For sync binding with methods that return a complex property we create a new JavascriptObject + //TODO: Fix the memory leak, every call to a method that returns an object will create a new + //JavascriptObject and they are never released + if(!obj.IsAsync && result != null && IsComplexType(result.GetType())) { var jsObject = CreateJavascriptObject(obj.CamelCaseJavascriptNames); jsObject.Value = result;