diff --git a/CefSharp.BrowserSubprocess.Core/CefAppUnmanagedWrapper.cpp b/CefSharp.BrowserSubprocess.Core/CefAppUnmanagedWrapper.cpp index 41c8db33f0..f53b2db5e6 100644 --- a/CefSharp.BrowserSubprocess.Core/CefAppUnmanagedWrapper.cpp +++ b/CefSharp.BrowserSubprocess.Core/CefAppUnmanagedWrapper.cpp @@ -396,7 +396,7 @@ namespace CefSharp { auto frameId = GetInt64(argList, 0); auto callbackId = GetInt64(argList, 1); - + JavascriptRootObjectWrapper^ rootObjectWrapper; browserWrapper->JavascriptRootObjectWrappers->TryGetValue(frameId, rootObjectWrapper); @@ -405,17 +405,44 @@ namespace CefSharp JavascriptAsyncMethodCallback^ callback; if (rootObjectWrapper->TryGetAndRemoveMethodCallback(callbackId, callback)) { - auto success = argList->GetBool(2); - if (success) + + try { - callback->Success(DeserializeV8Object(argList, 3)); + auto frame = browser->GetFrame(frameId); + if (frame.get()) + { + auto context = frame->GetV8Context(); + + if (context.get() && context->Enter()) + { + try + { + auto success = argList->GetBool(2); + if (success) + { + callback->Success(DeserializeV8Object(argList, 3)); + } + else + { + callback->Fail(argList->GetString(3)); + } + } + finally + { + context->Exit(); + } + } + else + { + callback->Fail("Unable to Enter Context"); + } + } } - else + finally { - callback->Fail(argList->GetString(3)); + //dispose + delete callback; } - //dispose - delete callback; } } handled = true; diff --git a/CefSharp.Example/AsyncBoundObject.cs b/CefSharp.Example/AsyncBoundObject.cs index 76f23c27f2..14bbfc13f0 100644 --- a/CefSharp.Example/AsyncBoundObject.cs +++ b/CefSharp.Example/AsyncBoundObject.cs @@ -8,6 +8,11 @@ namespace CefSharp.Example { + public struct JsObject + { + public string Value; + } + public class AsyncBoundObject { //We expect an exception here, so tell VS to ignore @@ -33,5 +38,14 @@ public void DoSomething() { Thread.Sleep(1000); } + + public JsObject[] ObjectArray(string name) + { + return new[] + { + new JsObject() { Value = "Item1" }, + new JsObject() { Value = "Item2" } + }; + } } } diff --git a/CefSharp.Example/Resources/BindingTest.html b/CefSharp.Example/Resources/BindingTest.html index 7e3e736f57..b0f89b3b97 100644 --- a/CefSharp.Example/Resources/BindingTest.html +++ b/CefSharp.Example/Resources/BindingTest.html @@ -82,11 +82,23 @@ writeAsyncResult(call, end); }); } + + function asyncObjectArray() + { + var call = "Async call (ObjectArray): " + Date(); + boundAsync.objectArray('CefSharp').then(function (res) + { + var end = "Result: [ " + res.map(function (item) { return item.Value }) + " ] (" + Date() + ")"; + writeAsyncResult(call, end); + }); + } asyncError(); asyncDivOk(); asyncDivFail(); asyncDoSomething(); + asyncHello(); + asyncObjectArray();

diff --git a/CefSharp/Internals/JavascriptObjectRepository.cs b/CefSharp/Internals/JavascriptObjectRepository.cs index a5b12f8f69..d981a12aab 100644 --- a/CefSharp/Internals/JavascriptObjectRepository.cs +++ b/CefSharp/Internals/JavascriptObjectRepository.cs @@ -191,7 +191,7 @@ public bool TryCallMethod(long objectId, string name, object[] parameters, out o } catch (Exception e) { - throw new InvalidOperationException("Could not execute method: " + name + "(" + String.Join(", ", parameters) + ")" + " - Missing Parameters: " + missingParams, e); + throw new InvalidOperationException("Could not execute method: " + name + "(" + String.Join(", ", parameters) + ") " + (missingParams > 0 ? "- Missing Parameters: " + missingParams : ""), e); } if(result != null && IsComplexType(result.GetType())) @@ -397,7 +397,7 @@ private static bool IsComplexType(Type type) baseType = Nullable.GetUnderlyingType(type); } - if (baseType == null || baseType.Namespace.StartsWith("System")) + if (baseType == null || baseType.IsArray || baseType.Namespace.StartsWith("System")) { return false; }