Backout bug 1361461 due to potentially introducing some intermittent reftest failures

This commit is contained in:
Ehsan Akhgari 2017-06-07 13:00:45 -04:00
Родитель 4dcf7f2e6f
Коммит 3cc0bd4b17
6 изменённых файлов: 44 добавлений и 83 удалений

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

@ -52,7 +52,7 @@ function test() {
gBrowser.removeCurrentTab();
yield TestUtils.topicObserved("outer-window-nuked", (subject, data) => {
yield TestUtils.topicObserved("outer-window-destroyed", (subject, data) => {
let id = subject.QueryInterface(Components.interfaces.nsISupportsPRUint64).data;
return id == winID;
});

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

@ -9628,24 +9628,16 @@ struct BrowserCompartmentMatcher : public js::CompartmentFilter {
};
class WindowDestroyedEvent final : public Runnable
class WindowDestroyedEvent : public Runnable
{
public:
WindowDestroyedEvent(nsIDOMWindow* aWindow, uint64_t aID,
const char* aTopic) :
mID(aID),
mPhase(Phase::Destroying),
mTopic(aTopic)
mID(aID), mTopic(aTopic)
{
mWindow = do_GetWeakReference(aWindow);
}
enum class Phase
{
Destroying,
Nuking
};
NS_IMETHOD Run() override
{
PROFILER_LABEL("WindowDestroyedEvent", "Run",
@ -9653,81 +9645,51 @@ public:
nsCOMPtr<nsIObserverService> observerService =
services::GetObserverService();
if (!observerService) {
return NS_OK;
if (observerService) {
nsCOMPtr<nsISupportsPRUint64> wrapper =
do_CreateInstance(NS_SUPPORTS_PRUINT64_CONTRACTID);
if (wrapper) {
wrapper->SetData(mID);
observerService->NotifyObservers(wrapper, mTopic.get(), nullptr);
}
}
nsCOMPtr<nsISupportsPRUint64> wrapper =
do_CreateInstance(NS_SUPPORTS_PRUINT64_CONTRACTID);
if (wrapper) {
wrapper->SetData(mID);
observerService->NotifyObservers(wrapper, mTopic.get(), nullptr);
}
switch (mPhase) {
case Phase::Destroying:
{
bool skipNukeCrossCompartment = false;
bool skipNukeCrossCompartment = false;
#ifndef DEBUG
nsCOMPtr<nsIAppStartup> appStartup =
do_GetService(NS_APPSTARTUP_CONTRACTID);
nsCOMPtr<nsIAppStartup> appStartup =
do_GetService(NS_APPSTARTUP_CONTRACTID);
if (appStartup) {
appStartup->GetShuttingDown(&skipNukeCrossCompartment);
}
if (appStartup) {
appStartup->GetShuttingDown(&skipNukeCrossCompartment);
}
#endif
if (!skipNukeCrossCompartment) {
// The compartment nuking phase might be too expensive, so do that
// part off of idle dispatch.
nsCOMPtr<nsISupports> window = do_QueryReferent(mWindow);
if (!skipNukeCrossCompartment && window) {
nsGlobalWindow* win = nsGlobalWindow::FromSupports(window);
nsGlobalWindow* currentInner = win->IsInnerWindow() ? win : win->GetCurrentInnerWindowInternal();
NS_ENSURE_TRUE(currentInner, NS_OK);
// For the compartment nuking phase, we dispatch either an
// inner-window-nuked or an outer-window-nuked notification.
// This will allow tests to wait for compartment nuking to happen.
if (mTopic.EqualsLiteral("inner-window-destroyed")) {
mTopic.AssignLiteral("inner-window-nuked");
} else if (mTopic.EqualsLiteral("outer-window-destroyed")) {
mTopic.AssignLiteral("outer-window-nuked");
}
mPhase = Phase::Nuking;
AutoSafeJSContext cx;
JS::Rooted<JSObject*> obj(cx, currentInner->FastGetGlobalJSObject());
if (obj && !js::IsSystemCompartment(js::GetObjectCompartment(obj))) {
JSCompartment* cpt = js::GetObjectCompartment(obj);
nsCOMPtr<nsIPrincipal> pc = nsJSPrincipals::get(JS_GetCompartmentPrincipals(cpt));
nsCOMPtr<nsIRunnable> copy(this);
NS_IdleDispatchToCurrentThread(copy.forget());
nsAutoString addonId;
if (NS_SUCCEEDED(pc->GetAddonId(addonId)) && !addonId.IsEmpty()) {
// We want to nuke all references to the add-on compartment.
xpc::NukeAllWrappersForCompartment(cx, cpt,
win->IsInnerWindow() ? js::DontNukeWindowReferences
: js::NukeWindowReferences);
} else {
// We only want to nuke wrappers for the chrome->content case
js::NukeCrossCompartmentWrappers(cx, BrowserCompartmentMatcher(), cpt,
win->IsInnerWindow() ? js::DontNukeWindowReferences
: js::NukeWindowReferences,
js::NukeIncomingReferences);
}
}
break;
case Phase::Nuking:
{
nsCOMPtr<nsISupports> window = do_QueryReferent(mWindow);
if (window) {
nsGlobalWindow* win = nsGlobalWindow::FromSupports(window);
nsGlobalWindow* currentInner = win->IsInnerWindow() ? win : win->GetCurrentInnerWindowInternal();
NS_ENSURE_TRUE(currentInner, NS_OK);
AutoSafeJSContext cx;
JS::Rooted<JSObject*> obj(cx, currentInner->FastGetGlobalJSObject());
if (obj && !js::IsSystemCompartment(js::GetObjectCompartment(obj))) {
JSCompartment* cpt = js::GetObjectCompartment(obj);
nsCOMPtr<nsIPrincipal> pc = nsJSPrincipals::get(JS_GetCompartmentPrincipals(cpt));
nsAutoString addonId;
if (NS_SUCCEEDED(pc->GetAddonId(addonId)) && !addonId.IsEmpty()) {
// We want to nuke all references to the add-on compartment.
xpc::NukeAllWrappersForCompartment(cx, cpt,
win->IsInnerWindow() ? js::DontNukeWindowReferences
: js::NukeWindowReferences);
} else {
// We only want to nuke wrappers for the chrome->content case
js::NukeCrossCompartmentWrappers(cx, BrowserCompartmentMatcher(), cpt,
win->IsInnerWindow() ? js::DontNukeWindowReferences
: js::NukeWindowReferences,
js::NukeIncomingReferences);
}
}
}
}
break;
}
return NS_OK;
@ -9735,7 +9697,6 @@ public:
private:
uint64_t mID;
Phase mPhase;
nsCString mTopic;
nsWeakPtr mWindow;
};

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

@ -13,7 +13,7 @@ add_task(function* test() {
let contentDocDead = yield ContentTask.spawn(browser,{innerWindowId}, function*(args){
let doc = content.document;
let {TestUtils} = Components.utils.import("resource://testing-common/TestUtils.jsm", {});
let promise = TestUtils.topicObserved("inner-window-nuked", (subject, data) => {
let promise = TestUtils.topicObserved("inner-window-destroyed", (subject, data) => {
let id = subject.QueryInterface(Components.interfaces.nsISupportsPRUint64).data;
return id == args.innerWindowId;
});

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

@ -49,7 +49,7 @@ function go() {
// once the window is destroyed.
frame.remove();
TestUtils.topicObserved("outer-window-nuked", (subject, data) => {
TestUtils.topicObserved("outer-window-destroyed", (subject, data) => {
let id = subject.QueryInterface(SpecialPowers.Ci.nsISupportsPRUint64).data;
return id == winID;
}).then(() => {

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

@ -25,11 +25,11 @@ function waitForWindowDestroyed(winID, callback) {
if (id != winID) {
return;
}
SpecialPowers.removeObserver(observer, "outer-window-nuked");
SpecialPowers.removeObserver(observer, "outer-window-destroyed");
SpecialPowers.executeSoon(callback);
}
};
SpecialPowers.addObserver(observer, "outer-window-nuked");
SpecialPowers.addObserver(observer, "outer-window-destroyed");
}
add_task(function* () {

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

@ -61,8 +61,8 @@ add_task(function*() {
webnavB.close();
// Wrappers are nuked asynchronously, so wait for that to happen.
yield TestUtils.topicObserved("inner-window-nuked");
// Wrappers are destroyed asynchronously, so wait for that to happen.
yield TestUtils.topicObserved("inner-window-destroyed");
// Check that it can't be accessed after he window has been closed.
let result = getThing();