Skip to content

Commit

Permalink
Fix Async JSB unable to return class
Browse files Browse the repository at this point in the history
Added note about memory leak
Added Test case to validate fix
  • Loading branch information
amaitland committed Mar 5, 2018
1 parent 33c0620 commit e47dd3e
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 4 deletions.
8 changes: 8 additions & 0 deletions CefSharp.Example/AsyncBoundObject.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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[]
Expand Down
6 changes: 3 additions & 3 deletions CefSharp.Example/Resources/BindingTest.html
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@
});
});

QUnit.test("Async call (Struct):", function( assert )
QUnit.test("Async call (return Struct):", function( assert )
{
var asyncCallback = assert.async();

Expand All @@ -239,7 +239,7 @@
});
});

QUnit.test("Async call (Class):", function (assert)
QUnit.test("Async call (return Class):", function (assert)
{
var asyncCallback = assert.async();

Expand All @@ -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();
});
Expand Down
5 changes: 4 additions & 1 deletion CefSharp/Internals/JavascriptObjectRepository.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit e47dd3e

Please sign in to comment.