Add support for native creation and resolution of Promises (fixes issue #3305)

This commit is contained in:
VodBox
2022-10-11 14:54:32 -04:00
committed by Marshall Greenblatt
parent 60ee4a34aa
commit fa643b269e
10 changed files with 609 additions and 9 deletions

View File

@ -536,6 +536,15 @@ class CefV8Value : public virtual CefBaseRefCounted {
static CefRefPtr<CefV8Value> CreateFunction(const CefString& name,
CefRefPtr<CefV8Handler> handler);
///
/// Create a new CefV8Value object of type Promise. This method should only be
/// called from within the scope of a CefRenderProcessHandler, CefV8Handler or
/// CefV8Accessor callback, or in combination with calling Enter() and Exit()
/// on a stored CefV8Context reference.
///
/*--cef()--*/
static CefRefPtr<CefV8Value> CreatePromise();
///
/// Returns true if the underlying handle is valid and it can be accessed on
/// the current thread. Do not call any other methods if this method returns
@ -616,6 +625,12 @@ class CefV8Value : public virtual CefBaseRefCounted {
/*--cef()--*/
virtual bool IsFunction() = 0;
///
/// True if the value type is a Promise.
///
/*--cef()--*/
virtual bool IsPromise() = 0;
///
/// Returns true if this object is pointing to the same handle as |that|
/// object.
@ -893,6 +908,29 @@ class CefV8Value : public virtual CefBaseRefCounted {
CefRefPtr<CefV8Context> context,
CefRefPtr<CefV8Value> object,
const CefV8ValueList& arguments) = 0;
// PROMISE METHODS - These methods are only available on Promises.
///
/// Resolve the Promise using the current V8 context. This method should only
/// be called from within the scope of a CefV8Handler or CefV8Accessor
/// callback, or in combination with calling Enter() and Exit() on a stored
/// CefV8Context reference. |arg| is the argument passed to the resolved
/// promise. Returns true on success. Returns false if this method is called
/// incorrectly or an exception is thrown.
///
/*--cef(optional_param=arg)--*/
virtual bool ResolvePromise(CefRefPtr<CefV8Value> arg) = 0;
///
/// Reject the Promise using the current V8 context. This method should only
/// be called from within the scope of a CefV8Handler or CefV8Accessor
/// callback, or in combination with calling Enter() and Exit() on a stored
/// CefV8Context reference. Returns true on success. Returns false if this
/// method is called incorrectly or an exception is thrown.
///
/*--cef()--*/
virtual bool RejectPromise(const CefString& errorMsg) = 0;
};
///