Backed out changeset c839f283bf28 (bug 1058695) for bustage.

CLOSED TREE
This commit is contained in:
Ryan VanderMeulen 2015-04-27 14:04:24 -04:00
Родитель b3ed721b3e
Коммит cb4391caa6
8 изменённых файлов: 30 добавлений и 103 удалений

Просмотреть файл

@ -1439,8 +1439,6 @@ nsGlobalWindow::CleanUp()
return;
mCleanedUp = true;
StartDying();
mEventTargetObjects.EnumerateEntries(DisconnectEventTargetObjects, nullptr);
mEventTargetObjects.Clear();

Просмотреть файл

@ -17,47 +17,13 @@ class nsIPrincipal;
class nsIGlobalObject : public nsISupports
{
bool mIsDying;
protected:
nsIGlobalObject()
: mIsDying(false)
{}
public:
NS_DECLARE_STATIC_IID_ACCESSOR(NS_IGLOBALOBJECT_IID)
/**
* This check is added to deal with Promise microtask queues. On the main
* thread, we do not impose restrictions about when script stops running or
* when runnables can no longer be dispatched to the main thread. This means
* it is possible for a Promise chain to keep resolving an infinite chain of
* promises, preventing the browser from shutting down. See Bug 1058695. To
* prevent this, the nsGlobalWindow subclass sets this flag when it is
* closed. The Promise implementation checks this and prohibits new runnables
* from being dispatched.
*
* We pair this with checks during processing the promise microtask queue
* that pops up the slow script dialog when the Promise queue is preventing
* a window from going away.
*/
bool
IsDying() const
{
return mIsDying;
}
virtual JSObject* GetGlobalJSObject() = 0;
// This method is not meant to be overridden.
nsIPrincipal* PrincipalOrNull();
protected:
void
StartDying()
{
mIsDying = true;
}
};
NS_DEFINE_STATIC_IID_ACCESSOR(nsIGlobalObject,

Просмотреть файл

@ -263,7 +263,7 @@ protected:
// console though, for debugging.
}
return rv.ErrorCode();
return NS_OK;
}
private:
@ -489,24 +489,13 @@ Promise::PerformMicroTaskCheckpoint()
return false;
}
Maybe<AutoSafeJSContext> cx;
if (NS_IsMainThread()) {
cx.emplace();
}
do {
nsCOMPtr<nsIRunnable> runnable = microtaskQueue.ElementAt(0);
MOZ_ASSERT(runnable);
// This function can re-enter, so we remove the element before calling.
microtaskQueue.RemoveElementAt(0);
nsresult rv = runnable->Run();
if (NS_WARN_IF(NS_FAILED(rv))) {
return false;
}
if (cx.isSome()) {
JS_CheckForInterrupt(cx.ref());
}
runnable->Run();
} while (!microtaskQueue.IsEmpty());
return true;
@ -1082,10 +1071,6 @@ void
Promise::AppendCallbacks(PromiseCallback* aResolveCallback,
PromiseCallback* aRejectCallback)
{
if (mGlobal->IsDying()) {
return;
}
MOZ_ASSERT(aResolveCallback);
MOZ_ASSERT(aRejectCallback);
@ -1312,12 +1297,7 @@ Promise::RejectInternal(JSContext* aCx,
void
Promise::Settle(JS::Handle<JS::Value> aValue, PromiseState aState)
{
if (mGlobal->IsDying()) {
return;
}
mSettlementTimestamp = TimeStamp::Now();
SetResult(aValue);
SetState(aState);

Просмотреть файл

@ -71,7 +71,7 @@ ResolvePromiseCallback::~ResolvePromiseCallback()
DropJSObjects(this);
}
nsresult
void
ResolvePromiseCallback::Call(JSContext* aCx,
JS::Handle<JS::Value> aValue)
{
@ -81,11 +81,10 @@ ResolvePromiseCallback::Call(JSContext* aCx,
JS::Rooted<JS::Value> value(aCx, aValue);
if (!JS_WrapValue(aCx, &value)) {
NS_WARNING("Failed to wrap value into the right compartment.");
return NS_ERROR_FAILURE;
return;
}
mPromise->ResolveInternal(aCx, value);
return NS_OK;
}
// RejectPromiseCallback
@ -130,7 +129,7 @@ RejectPromiseCallback::~RejectPromiseCallback()
DropJSObjects(this);
}
nsresult
void
RejectPromiseCallback::Call(JSContext* aCx,
JS::Handle<JS::Value> aValue)
{
@ -140,12 +139,11 @@ RejectPromiseCallback::Call(JSContext* aCx,
JS::Rooted<JS::Value> value(aCx, aValue);
if (!JS_WrapValue(aCx, &value)) {
NS_WARNING("Failed to wrap value into the right compartment.");
return NS_ERROR_FAILURE;
return;
}
mPromise->RejectInternal(aCx, value);
return NS_OK;
}
// WrapperPromiseCallback
@ -192,7 +190,7 @@ WrapperPromiseCallback::~WrapperPromiseCallback()
DropJSObjects(this);
}
nsresult
void
WrapperPromiseCallback::Call(JSContext* aCx,
JS::Handle<JS::Value> aValue)
{
@ -200,7 +198,7 @@ WrapperPromiseCallback::Call(JSContext* aCx,
JS::Rooted<JS::Value> value(aCx, aValue);
if (!JS_WrapValue(aCx, &value)) {
NS_WARNING("Failed to wrap value into the right compartment.");
return NS_ERROR_FAILURE;
return;
}
ErrorResult rv;
@ -221,7 +219,7 @@ WrapperPromiseCallback::Call(JSContext* aCx,
if (!JS_WrapValue(aCx, &value)) {
NS_WARNING("Failed to wrap value into the right compartment.");
return NS_ERROR_FAILURE;
return;
}
} else {
// Convert the ErrorResult to a JS exception object that we can reject
@ -234,7 +232,7 @@ WrapperPromiseCallback::Call(JSContext* aCx,
}
mNextPromise->RejectInternal(aCx, value);
return NS_OK;
return;
}
// If the return value is the same as the promise itself, throw TypeError.
@ -272,7 +270,7 @@ WrapperPromiseCallback::Call(JSContext* aCx,
if (!fn) {
// Out of memory. Promise will stay unresolved.
JS_ClearPendingException(aCx);
return NS_ERROR_OUT_OF_MEMORY;
return;
}
JS::Rooted<JSString*> message(aCx,
@ -281,7 +279,7 @@ WrapperPromiseCallback::Call(JSContext* aCx,
if (!message) {
// Out of memory. Promise will stay unresolved.
JS_ClearPendingException(aCx);
return NS_ERROR_OUT_OF_MEMORY;
return;
}
JS::Rooted<JS::Value> typeError(aCx);
@ -289,22 +287,21 @@ WrapperPromiseCallback::Call(JSContext* aCx,
nullptr, message, &typeError)) {
// Out of memory. Promise will stay unresolved.
JS_ClearPendingException(aCx);
return NS_ERROR_OUT_OF_MEMORY;
return;
}
mNextPromise->RejectInternal(aCx, typeError);
return NS_OK;
return;
}
}
// Otherwise, run resolver's resolve with value.
if (!JS_WrapValue(aCx, &retValue)) {
NS_WARNING("Failed to wrap value into the right compartment.");
return NS_ERROR_FAILURE;
return;
}
mNextPromise->ResolveInternal(aCx, retValue);
return NS_OK;
}
// NativePromiseCallback
@ -330,22 +327,21 @@ NativePromiseCallback::~NativePromiseCallback()
{
}
nsresult
void
NativePromiseCallback::Call(JSContext* aCx,
JS::Handle<JS::Value> aValue)
{
if (mState == Promise::Resolved) {
mHandler->ResolvedCallback(aCx, aValue);
return NS_OK;
return;
}
if (mState == Promise::Rejected) {
mHandler->RejectedCallback(aCx, aValue);
return NS_OK;
return;
}
NS_NOTREACHED("huh?");
return NS_ERROR_FAILURE;
}
/* static */ PromiseCallback*

Просмотреть файл

@ -26,8 +26,8 @@ public:
PromiseCallback();
virtual nsresult Call(JSContext* aCx,
JS::Handle<JS::Value> aValue) = 0;
virtual void Call(JSContext* aCx,
JS::Handle<JS::Value> aValue) = 0;
// Return the Promise that this callback will end up resolving or
// rejecting, if any.
@ -54,8 +54,8 @@ public:
NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS_INHERITED(WrapperPromiseCallback,
PromiseCallback)
nsresult Call(JSContext* aCx,
JS::Handle<JS::Value> aValue) override;
void Call(JSContext* aCx,
JS::Handle<JS::Value> aValue) override;
Promise* GetDependentPromise() override
{
@ -82,8 +82,8 @@ public:
NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS_INHERITED(ResolvePromiseCallback,
PromiseCallback)
nsresult Call(JSContext* aCx,
JS::Handle<JS::Value> aValue) override;
void Call(JSContext* aCx,
JS::Handle<JS::Value> aValue) override;
Promise* GetDependentPromise() override
{
@ -108,8 +108,8 @@ public:
NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS_INHERITED(RejectPromiseCallback,
PromiseCallback)
nsresult Call(JSContext* aCx,
JS::Handle<JS::Value> aValue) override;
void Call(JSContext* aCx,
JS::Handle<JS::Value> aValue) override;
Promise* GetDependentPromise() override
{
@ -133,8 +133,8 @@ public:
NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(NativePromiseCallback,
PromiseCallback)
nsresult Call(JSContext* aCx,
JS::Handle<JS::Value> aValue) override;
void Call(JSContext* aCx,
JS::Handle<JS::Value> aValue) override;
Promise* GetDependentPromise() override
{

Просмотреть файл

@ -4462,12 +4462,6 @@ JS_New(JSContext* cx, HandleObject ctor, const JS::HandleValueArray& inputArgs)
return obj;
}
JS_PUBLIC_API(bool)
JS_CheckForInterrupt(JSContext* cx)
{
return js::CheckForInterrupt(cx);
}
JS_PUBLIC_API(JSInterruptCallback)
JS_SetInterruptCallback(JSRuntime* rt, JSInterruptCallback callback)
{

Просмотреть файл

@ -3948,10 +3948,8 @@ extern JS_PUBLIC_API(bool)
Construct(JSContext* cx, JS::HandleValue fun,
const JS::HandleValueArray& args,
MutableHandleValue rval);
} /* namespace JS */
extern JS_PUBLIC_API(bool)
JS_CheckForInterrupt(JSContext* cx);
} /* namespace JS */
/*
* These functions allow setting an interrupt callback that will be called

Просмотреть файл

@ -1461,13 +1461,8 @@ XPCJSRuntime::InterruptCallback(JSContext* cx)
win = WindowGlobalOrNull(proto);
}
}
if (!win) {
NS_WARNING("No active window");
if (!win)
return true;
}
MOZ_ASSERT(!win->IsDying());
if (win->GetIsPrerendered()) {
// We cannot display a dialog if the page is being prerendered, so