mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-11-24 13:21:05 +00:00
Bug 1453339. Make it harder to mess up Promise::All. r=peterv
MozReview-Commit-ID: UO4wssYHj7
This commit is contained in:
parent
e5e108a524
commit
ecac16fefa
@ -395,8 +395,6 @@ nsFrameLoader::FireWillChangeProcessEvent()
|
||||
return nullptr;
|
||||
}
|
||||
JSContext* cx = jsapi.cx();
|
||||
GlobalObject global(cx, mOwnerContent->GetOwnerGlobal()->GetGlobalJSObject());
|
||||
MOZ_ASSERT(!global.Failed());
|
||||
|
||||
// Set our mBrowserChangingProcessBlockers property to refer to the blockers
|
||||
// list. We will synchronously dispatch a DOM event to collect this list of
|
||||
@ -418,7 +416,7 @@ nsFrameLoader::FireWillChangeProcessEvent()
|
||||
mBrowserChangingProcessBlockers = nullptr;
|
||||
|
||||
ErrorResult rv;
|
||||
RefPtr<Promise> allPromise = Promise::All(global, blockers, rv);
|
||||
RefPtr<Promise> allPromise = Promise::All(cx, blockers, rv);
|
||||
return allPromise.forget();
|
||||
}
|
||||
|
||||
|
2
dom/cache/Cache.cpp
vendored
2
dom/cache/Cache.cpp
vendored
@ -630,7 +630,7 @@ Cache::AddAll(const GlobalObject& aGlobal,
|
||||
new FetchHandler(mActor->GetWorkerHolder(), this,
|
||||
Move(aRequestList), promise);
|
||||
|
||||
RefPtr<Promise> fetchPromise = Promise::All(aGlobal, fetchList, aRv);
|
||||
RefPtr<Promise> fetchPromise = Promise::All(aGlobal.Context(), fetchList, aRv);
|
||||
if (NS_WARN_IF(aRv.Failed())) {
|
||||
return nullptr;
|
||||
}
|
||||
|
@ -135,37 +135,40 @@ Promise::Reject(nsIGlobalObject* aGlobal, JSContext* aCx,
|
||||
|
||||
// static
|
||||
already_AddRefed<Promise>
|
||||
Promise::All(const GlobalObject& aGlobal,
|
||||
Promise::All(JSContext* aCx,
|
||||
const nsTArray<RefPtr<Promise>>& aPromiseList, ErrorResult& aRv)
|
||||
{
|
||||
nsCOMPtr<nsIGlobalObject> global;
|
||||
global = do_QueryInterface(aGlobal.GetAsSupports());
|
||||
JS::Rooted<JSObject*> globalObj(aCx, JS::CurrentGlobalOrNull(aCx));
|
||||
if (!globalObj) {
|
||||
aRv.Throw(NS_ERROR_UNEXPECTED);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
nsCOMPtr<nsIGlobalObject> global = xpc::NativeGlobal(globalObj);
|
||||
if (!global) {
|
||||
aRv.Throw(NS_ERROR_UNEXPECTED);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
JSContext* cx = aGlobal.Context();
|
||||
|
||||
JS::AutoObjectVector promises(cx);
|
||||
JS::AutoObjectVector promises(aCx);
|
||||
if (!promises.reserve(aPromiseList.Length())) {
|
||||
aRv.NoteJSContextException(cx);
|
||||
aRv.NoteJSContextException(aCx);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
for (auto& promise : aPromiseList) {
|
||||
JS::Rooted<JSObject*> promiseObj(cx, promise->PromiseObj());
|
||||
JS::Rooted<JSObject*> promiseObj(aCx, promise->PromiseObj());
|
||||
// Just in case, make sure these are all in the context compartment.
|
||||
if (!JS_WrapObject(cx, &promiseObj)) {
|
||||
aRv.NoteJSContextException(cx);
|
||||
if (!JS_WrapObject(aCx, &promiseObj)) {
|
||||
aRv.NoteJSContextException(aCx);
|
||||
return nullptr;
|
||||
}
|
||||
promises.infallibleAppend(promiseObj);
|
||||
}
|
||||
|
||||
JS::Rooted<JSObject*> result(cx, JS::GetWaitForAllPromise(cx, promises));
|
||||
JS::Rooted<JSObject*> result(aCx, JS::GetWaitForAllPromise(aCx, promises));
|
||||
if (!result) {
|
||||
aRv.NoteJSContextException(cx);
|
||||
aRv.NoteJSContextException(aCx);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
|
@ -111,23 +111,26 @@ public:
|
||||
return mGlobal;
|
||||
}
|
||||
|
||||
// Do the equivalent of Promise.resolve in the current compartment of aCx.
|
||||
// Errorrs are reported on the ErrorResult; if aRv comes back !Failed(), this
|
||||
// function MUST return a non-null value.
|
||||
// Do the equivalent of Promise.resolve in the compartment of aGlobal. The
|
||||
// compartment of aCx is ignored. Errors are reported on the ErrorResult; if
|
||||
// aRv comes back !Failed(), this function MUST return a non-null value.
|
||||
static already_AddRefed<Promise>
|
||||
Resolve(nsIGlobalObject* aGlobal, JSContext* aCx,
|
||||
JS::Handle<JS::Value> aValue, ErrorResult& aRv);
|
||||
|
||||
// Do the equivalent of Promise.reject in the current compartment of aCx.
|
||||
// Errorrs are reported on the ErrorResult; if aRv comes back !Failed(), this
|
||||
// function MUST return a non-null value.
|
||||
// Do the equivalent of Promise.reject in the compartment of aGlobal. The
|
||||
// compartment of aCx is ignored. Errors are reported on the ErrorResult; if
|
||||
// aRv comes back !Failed(), this function MUST return a non-null value.
|
||||
static already_AddRefed<Promise>
|
||||
Reject(nsIGlobalObject* aGlobal, JSContext* aCx,
|
||||
JS::Handle<JS::Value> aValue, ErrorResult& aRv);
|
||||
|
||||
// Do the equivalent of Promise.all in the current compartment of aCx. Errors
|
||||
// are reported on the ErrorResult; if aRv comes back !Failed(), this function
|
||||
// MUST return a non-null value.
|
||||
static already_AddRefed<Promise>
|
||||
All(const GlobalObject& aGlobal,
|
||||
const nsTArray<RefPtr<Promise>>& aPromiseList, ErrorResult& aRv);
|
||||
All(JSContext* aCx, const nsTArray<RefPtr<Promise>>& aPromiseList,
|
||||
ErrorResult& aRv);
|
||||
|
||||
void
|
||||
Then(JSContext* aCx,
|
||||
|
@ -346,17 +346,7 @@ FontFaceSet::Load(JSContext* aCx,
|
||||
}
|
||||
}
|
||||
|
||||
nsIGlobalObject* globalObject = GetParentObject();
|
||||
if (!globalObject) {
|
||||
aRv.Throw(NS_ERROR_FAILURE);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
JS::Rooted<JSObject*> jsGlobal(aCx, globalObject->GetGlobalJSObject());
|
||||
GlobalObject global(aCx, jsGlobal);
|
||||
|
||||
RefPtr<Promise> result = Promise::All(global, promises, aRv);
|
||||
return result.forget();
|
||||
return Promise::All(aCx, promises, aRv);
|
||||
}
|
||||
|
||||
bool
|
||||
|
Loading…
Reference in New Issue
Block a user