mirror of
https://github.com/cefsharp/CefSharp.git
synced 2026-12-06 12:09:40 +00:00
Enhancement - Improve Promise support (#4326)
* Enhancement - Improved promise support Resolves #4276
This commit is contained in:
@@ -13,6 +13,8 @@
|
||||
#include "JavascriptPostMessageHandler.h"
|
||||
#include "JavascriptRootObjectWrapper.h"
|
||||
#include "JavascriptPromiseHandler.h"
|
||||
#include "JavascriptPromiseResolverCatch.h"
|
||||
#include "JavascriptPromiseResolverThen.h"
|
||||
#include "Async\JavascriptAsyncMethodCallback.h"
|
||||
#include "Serialization\V8Serialization.h"
|
||||
#include "Serialization\JsObjectsSerialization.h"
|
||||
@@ -446,6 +448,24 @@ namespace CefSharp
|
||||
{
|
||||
sendResponse = false;
|
||||
}
|
||||
else if (result->IsPromise())
|
||||
{
|
||||
sendResponse = false;
|
||||
|
||||
auto promiseThen = result->GetValue("then");
|
||||
auto promiseCatch = result->GetValue("catch");
|
||||
|
||||
auto promiseThenFunc = CefV8Value::CreateFunction("promiseResolverThen", new JavascriptPromiseResolverThen(callbackId, false));
|
||||
auto promiseCatchFunc = CefV8Value::CreateFunction("promiseResolverCatch", new JavascriptPromiseResolverCatch(callbackId, false));
|
||||
|
||||
CefV8ValueList promiseThenArgs;
|
||||
promiseThenArgs.push_back(promiseThenFunc);
|
||||
promiseThen->ExecuteFunction(result, promiseThenArgs);
|
||||
|
||||
CefV8ValueList promiseCatchArgs;
|
||||
promiseCatchArgs.push_back(promiseCatchFunc);
|
||||
promiseCatch->ExecuteFunction(result, promiseCatchArgs);
|
||||
}
|
||||
else
|
||||
{
|
||||
auto responseArgList = response->GetArgumentList();
|
||||
@@ -521,6 +541,24 @@ namespace CefSharp
|
||||
{
|
||||
sendResponse = false;
|
||||
}
|
||||
else if (result->IsPromise())
|
||||
{
|
||||
sendResponse = false;
|
||||
|
||||
auto promiseThen = result->GetValue("then");
|
||||
auto promiseCatch = result->GetValue("catch");
|
||||
|
||||
auto promiseThenFunc = CefV8Value::CreateFunction("promiseResolverThen", new JavascriptPromiseResolverThen(callbackId, true));
|
||||
auto promiseCatchFunc = CefV8Value::CreateFunction("promiseResolverCatch", new JavascriptPromiseResolverCatch(callbackId, true));
|
||||
|
||||
CefV8ValueList promiseThenArgs;
|
||||
promiseThenArgs.push_back(promiseThenFunc);
|
||||
promiseThen->ExecuteFunction(result, promiseThenArgs);
|
||||
|
||||
CefV8ValueList promiseCatchArgs;
|
||||
promiseCatchArgs.push_back(promiseCatchFunc);
|
||||
promiseCatch->ExecuteFunction(result, promiseCatchArgs);
|
||||
}
|
||||
else
|
||||
{
|
||||
auto responseArgList = response->GetArgumentList();
|
||||
|
||||
Reference in New Issue
Block a user