Bug 1553400 - XMLHttpRequestDoneNotifier should own XHR, not vice-versa, r=baku

Differential Revision: https://phabricator.services.mozilla.com/D32142

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Olli Pettay 2019-05-22 15:40:10 +00:00
Родитель 89ee522abc
Коммит 258bcca5e9
2 изменённых файлов: 11 добавлений и 5 удалений

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

@ -231,12 +231,15 @@ XMLHttpRequestMainThread::XMLHttpRequestMainThread()
mIsMappedArrayBuffer(false),
mXPCOMifier(nullptr),
mEventDispatchingSuspended(false),
mEofDecoded(false) {
mEofDecoded(false),
mDelayedDoneNotifier(nullptr) {
mozilla::HoldJSObjects(this);
}
XMLHttpRequestMainThread::~XMLHttpRequestMainThread() {
DisconnectDoneNotifier();
MOZ_ASSERT(
!mDelayedDoneNotifier,
"How can we have mDelayedDoneNotifier, which owns us, in destructor?");
mFlagDeleted = true;
@ -2234,6 +2237,8 @@ void XMLHttpRequestMainThread::MatchCharsetAndDecoderToResponseDocument() {
}
void XMLHttpRequestMainThread::DisconnectDoneNotifier() {
if (mDelayedDoneNotifier) {
// Disconnect may release the last reference to 'this'.
RefPtr<XMLHttpRequestMainThread> kungfuDeathGrip = this;
mDelayedDoneNotifier->Disconnect();
mDelayedDoneNotifier = nullptr;
}

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

@ -724,7 +724,7 @@ class XMLHttpRequestMainThread final : public XMLHttpRequest,
// Our parse-end listener, if we are parsing.
RefPtr<nsXHRParseEndListener> mParseEndListener;
RefPtr<XMLHttpRequestDoneNotifier> mDelayedDoneNotifier;
XMLHttpRequestDoneNotifier* mDelayedDoneNotifier;
void DisconnectDoneNotifier();
// Any stack information for the point the XHR was opened. This is deleted
@ -795,8 +795,9 @@ class XMLHttpRequestDoneNotifier : public Runnable {
NS_IMETHOD Run() override {
if (mXHR) {
RefPtr<XMLHttpRequestMainThread> xhr = mXHR;
mXHR = nullptr;
// ChangeStateToDoneInternal ends up calling Disconnect();
xhr->ChangeStateToDoneInternal();
MOZ_ASSERT(!mXHR);
}
return NS_OK;
}
@ -804,7 +805,7 @@ class XMLHttpRequestDoneNotifier : public Runnable {
void Disconnect() { mXHR = nullptr; }
private:
XMLHttpRequestMainThread* mXHR;
RefPtr<XMLHttpRequestMainThread> mXHR;
};
class nsXHRParseEndListener : public nsIDOMEventListener {