Bug 1356273: Part 1 - Set document readyState to uninitialized during document.open() r?smaug
Calling SetNewDocument() immediately triggers content-document-global-created
observers for the new window global. In the case of document.open() calls,
though, the document itself is in an intermediate state at that point, and
does not have the correct URL or DOM contents for the new global. Setting the
ready state to uninitialized lets listeners determine when that's the case.
MozReview-Commit-ID: FAkyvOnkFR2
--- a/dom/html/nsHTMLDocument.cpp
+++ b/dom/html/nsHTMLDocument.cpp
@@ -1694,16 +1694,21 @@ nsHTMLDocument::Open(JSContext* cx,
nsDocument* templateContentsOwner =
static_cast<nsDocument*>(mTemplateContentsOwner.get());
if (templateContentsOwner) {
templateContentsOwner->mWillReparent = true;
}
#endif
+ // Set our ready state to uninitialized before setting the new document so
+ // that window creation listeners don't use the document in its intermediate
+ // state prior to reset.
+ SetReadyStateInternal(READYSTATE_UNINITIALIZED);
+
// Per spec, we pass false here so that a new Window is created.
rv = window->SetNewDocument(this, nullptr,
/* aForceReuseInnerWindow */ false);
if (rv.Failed()) {
return nullptr;
}
#ifdef DEBUG