Skip to content

Commit e47dd3e

Browse files
committed
Fix Async JSB unable to return class
Added note about memory leak Added Test case to validate fix
1 parent 33c0620 commit e47dd3e

File tree

3 files changed

+15
-4
lines changed

3 files changed

+15
-4
lines changed

CefSharp.Example/AsyncBoundObject.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,14 @@ public JsSerializableStruct ReturnObject(string name)
4646
};
4747
}
4848

49+
public JsSerializableClass ReturnClass(string name)
50+
{
51+
return new JsSerializableClass
52+
{
53+
Value = name
54+
};
55+
}
56+
4957
public JsSerializableStruct[] ReturnStructArray(string name)
5058
{
5159
return new[]

CefSharp.Example/Resources/BindingTest.html

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,7 @@
227227
});
228228
});
229229

230-
QUnit.test("Async call (Struct):", function( assert )
230+
QUnit.test("Async call (return Struct):", function( assert )
231231
{
232232
var asyncCallback = assert.async();
233233

@@ -239,7 +239,7 @@
239239
});
240240
});
241241

242-
QUnit.test("Async call (Class):", function (assert)
242+
QUnit.test("Async call (return Class):", function (assert)
243243
{
244244
var asyncCallback = assert.async();
245245

@@ -248,7 +248,7 @@
248248
{
249249
const expectedResult = 'CefSharp Class Test';
250250

251-
assert.equal(expectedResult, res.Value, "Class with a single field " + expectedResult);
251+
assert.equal(expectedResult, res.Value, "Class with a single property");
252252

253253
asyncCallback();
254254
});

CefSharp/Internals/JavascriptObjectRepository.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -266,7 +266,10 @@ public bool TryCallMethod(long objectId, string name, object[] parameters, out o
266266
throw new InvalidOperationException("Could not execute method: " + name + "(" + String.Join(", ", parameters) + ") " + (missingParams > 0 ? "- Missing Parameters: " + missingParams : ""), e);
267267
}
268268

269-
if(result != null && IsComplexType(result.GetType()))
269+
//For sync binding with methods that return a complex property we create a new JavascriptObject
270+
//TODO: Fix the memory leak, every call to a method that returns an object will create a new
271+
//JavascriptObject and they are never released
272+
if(!obj.IsAsync && result != null && IsComplexType(result.GetType()))
270273
{
271274
var jsObject = CreateJavascriptObject(obj.CamelCaseJavascriptNames);
272275
jsObject.Value = result;

0 commit comments

Comments
 (0)