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:
Zibi Braniecki 2019-03-26 19:34:29 +00:00
parent c2150bafe9
commit 4450c1692a
3 changed files with 31 additions and 0 deletions

View File

@ -41,6 +41,7 @@
#include "PromiseWorkerProxy.h"
#include "WrapperFactory.h"
#include "xpcpublic.h"
#include "xpcprivate.h"
namespace mozilla {
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 {
return mGlobal->GetGlobalJSObject();
}

View File

@ -103,6 +103,9 @@ class Promise : public nsISupports, public SupportsWeakPtr<Promise> {
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
// rejected with Error instances.
// Note: MaybeRejectBrokenly is a template so we can use it with DOMException

View File

@ -23,6 +23,7 @@ UNIFIED_SOURCES += [
LOCAL_INCLUDES += [
'../base',
'../ipc',
'/js/xpconnect/src',
]
include('/ipc/chromium/chromium-config.mozbuild')