Backed out changeset cb59db723d15 (Bug 1058695) for bustage on CLOSED TREE

--HG--
extra : amend_source : 273b62b6c171f65718e8c59e833ba30f6ea96a05
This commit is contained in:
Nikhil Marathe 2015-04-23 09:46:52 -07:00
parent b2bcb0c719
commit d1232d5041
8 changed files with 30 additions and 96 deletions

View File

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

View File

@ -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,

View File

@ -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);

View File

@ -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*

View File

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

View File

@ -3941,6 +3941,7 @@ extern JS_PUBLIC_API(bool)
Construct(JSContext* cx, JS::HandleValue fun,
const JS::HandleValueArray& args,
MutableHandleValue rval);
} /* namespace JS */
/*

View File

@ -2742,8 +2742,6 @@ extern JS_FRIEND_API(bool)
DefineOwnProperty(JSContext* cx, JSObject* objArg, jsid idArg,
JS::Handle<JSPropertyDescriptor> descriptor, JS::ObjectOpResult& result);
extern JS_FRIEND_API(bool)
CheckForInterrupt(JSContext* cx);
} /* namespace js */
extern JS_FRIEND_API(void)

View File

@ -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