mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-10-19 00:05:36 +00:00
Bug 1483036 - Add MaybeResolveWithClone and MaybeRejectWithClone to Promise. r=smaug
Differential Revision: https://phabricator.services.mozilla.com/D24385 --HG-- extra : moz-landing-system : lando
This commit is contained in:
parent
c2150bafe9
commit
4450c1692a
@ -41,6 +41,7 @@
|
|||||||
#include "PromiseWorkerProxy.h"
|
#include "PromiseWorkerProxy.h"
|
||||||
#include "WrapperFactory.h"
|
#include "WrapperFactory.h"
|
||||||
#include "xpcpublic.h"
|
#include "xpcpublic.h"
|
||||||
|
#include "xpcprivate.h"
|
||||||
|
|
||||||
namespace mozilla {
|
namespace mozilla {
|
||||||
namespace dom {
|
namespace dom {
|
||||||
@ -548,6 +549,32 @@ void Promise::ReportRejectedPromise(JSContext* aCx, JS::HandleObject aPromise) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Promise::MaybeResolveWithClone(JSContext* aCx,
|
||||||
|
JS::Handle<JS::Value> aValue) {
|
||||||
|
JS::Rooted<JSObject*> sourceScope(aCx, JS::CurrentGlobalOrNull(aCx));
|
||||||
|
AutoEntryScript aes(GetParentObject(), "Promise resolution");
|
||||||
|
JSContext* cx = aes.cx();
|
||||||
|
JS::Rooted<JS::Value> value(cx, aValue);
|
||||||
|
|
||||||
|
xpc::StackScopedCloneOptions options;
|
||||||
|
options.wrapReflectors = true;
|
||||||
|
StackScopedClone(cx, options, sourceScope, &value);
|
||||||
|
MaybeResolve(aCx, value);
|
||||||
|
}
|
||||||
|
|
||||||
|
void Promise::MaybeRejectWithClone(JSContext* aCx,
|
||||||
|
JS::Handle<JS::Value> aValue) {
|
||||||
|
JS::Rooted<JSObject*> sourceScope(aCx, JS::CurrentGlobalOrNull(aCx));
|
||||||
|
AutoEntryScript aes(GetParentObject(), "Promise rejection");
|
||||||
|
JSContext* cx = aes.cx();
|
||||||
|
JS::Rooted<JS::Value> value(cx, aValue);
|
||||||
|
|
||||||
|
xpc::StackScopedCloneOptions options;
|
||||||
|
options.wrapReflectors = true;
|
||||||
|
StackScopedClone(cx, options, sourceScope, &value);
|
||||||
|
MaybeReject(aCx, value);
|
||||||
|
}
|
||||||
|
|
||||||
JSObject* Promise::GlobalJSObject() const {
|
JSObject* Promise::GlobalJSObject() const {
|
||||||
return mGlobal->GetGlobalJSObject();
|
return mGlobal->GetGlobalJSObject();
|
||||||
}
|
}
|
||||||
|
@ -103,6 +103,9 @@ class Promise : public nsISupports, public SupportsWeakPtr<Promise> {
|
|||||||
|
|
||||||
void MaybeRejectWithUndefined();
|
void MaybeRejectWithUndefined();
|
||||||
|
|
||||||
|
void MaybeResolveWithClone(JSContext* aCx, JS::Handle<JS::Value> aValue);
|
||||||
|
void MaybeRejectWithClone(JSContext* aCx, JS::Handle<JS::Value> aValue);
|
||||||
|
|
||||||
// DO NOT USE MaybeRejectBrokenly with in new code. Promises should be
|
// DO NOT USE MaybeRejectBrokenly with in new code. Promises should be
|
||||||
// rejected with Error instances.
|
// rejected with Error instances.
|
||||||
// Note: MaybeRejectBrokenly is a template so we can use it with DOMException
|
// Note: MaybeRejectBrokenly is a template so we can use it with DOMException
|
||||||
|
@ -23,6 +23,7 @@ UNIFIED_SOURCES += [
|
|||||||
LOCAL_INCLUDES += [
|
LOCAL_INCLUDES += [
|
||||||
'../base',
|
'../base',
|
||||||
'../ipc',
|
'../ipc',
|
||||||
|
'/js/xpconnect/src',
|
||||||
]
|
]
|
||||||
|
|
||||||
include('/ipc/chromium/chromium-config.mozbuild')
|
include('/ipc/chromium/chromium-config.mozbuild')
|
||||||
|
Loading…
Reference in New Issue
Block a user