JSB - Remove use of CefRegisterExtension and change Promise creator to an anon function

Use CefV8Context::Eval to create the promise using an anonymous function

Attempt to resolve #2432 (though it actually seems upgrading to a newer version resolves the underlying problem)
This commit is contained in:
amaitland
2018-08-27 13:12:55 +10:00
parent b0af05a6ab
commit 7450d0d51b
4 changed files with 35 additions and 28 deletions
@@ -23,16 +23,23 @@ namespace CefSharp
auto context = CefV8Context::GetCurrentContext();
auto browser = context->GetBrowser();
auto promiseCreator = context->GetGlobal()->GetValue(CefAppUnmanagedWrapper::kPromiseCreatorFunction);
CefRefPtr<CefV8Value> promiseData;
CefRefPtr<CefV8Exception> promiseException;
//this will create a promise and give us the reject/resolve functions {p: Promise, res: resolve(), rej: reject()}
auto promiseData = promiseCreator->ExecuteFunctionWithContext(context, nullptr, CefV8ValueList());
//when refreshing the browser this is sometimes null, in this case return true and log message
//https://github.com/cefsharp/CefSharp/pull/2446
if (!context->Eval(CefAppUnmanagedWrapper::kPromiseCreatorScript, CefString(), 0, promiseData, promiseException))
{
LOG(WARNING) << "JavascriptAsyncMethodHandler::Execute promiseData returned exception: " + promiseException->GetMessage().ToString();
exception = promiseException->GetMessage();
return true;
}
//when refreshing the browser this is sometimes null, in this case return true and log message
//https://github.com/cefsharp/CefSharp/pull/2446
if (promiseData == NULL)
{
LOG(WARNING) << "JavascriptAsyncMethodHandler::Execute promiseData returned NULL";
LOG(WARNING) << "JavascriptAsyncMethodHandler::Execute promiseData returned NULL";
return true;
}