Skip to content

Commit

Permalink
Fix return value serialization for async JS bindings (#2167)
Browse files Browse the repository at this point in the history
  • Loading branch information
ieremyashev authored and jankurianski committed Oct 23, 2017
1 parent a4a1cd8 commit f029a22
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 0 deletions.
8 changes: 8 additions & 0 deletions CefSharp.Example/AsyncBoundObject.cs
Expand Up @@ -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[]
Expand Down
11 changes: 11 additions & 0 deletions CefSharp.Example/Resources/BindingTest.html
Expand Up @@ -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();
Expand All @@ -98,6 +108,7 @@
asyncDivFail();
asyncDoSomething();
asyncHello();
asyncObject();
asyncObjectArray();
</script>
</p>
Expand Down
5 changes: 5 additions & 0 deletions CefSharp/Internals/JavascriptObjectRepository.cs
Expand Up @@ -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);
}

Expand Down

0 comments on commit f029a22

Please sign in to comment.