Index: Source/core/html/HTMLScriptElement.cpp |
diff --git a/Source/core/html/HTMLScriptElement.cpp b/Source/core/html/HTMLScriptElement.cpp |
index bce71bdbcb9686e604a03408401a08950b6eeb5f..d429566d61384e6d8863194220a569b943ce31e2 100644 |
--- a/Source/core/html/HTMLScriptElement.cpp |
+++ b/Source/core/html/HTMLScriptElement.cpp |
@@ -75,12 +75,17 @@ void HTMLScriptElement::didMoveToNewDocument(Document& oldDocument) |
{ |
RefPtrWillBeRawPtr<Document> contextDocument = document().contextDocument().get(); |
if (!contextDocument) { |
+ // Document's contextDocument() method will return no Document if the |
+ // following conditions both hold: |
+ // |
+ // - The Document wasn't created with an explicit context document |
+ // and that document is otherwise kept alive. |
+ // - The Document itself is detached from its frame. |
+ // |
+ // The script element's loader is in that case moved to document() and |
+ // its script runner, which is the non-null Document that contextDocument() |
+ // would return if not detached. |
ASSERT(!document().frame()); |
- // A frame-detached document is handled as having no context |
- // document - it would be the document if not detached. The |
- // newly moved script element needs to be the latter here as |
- // the script loader for the pending script must also move to |
- // reside with that document and its script runner. |
contextDocument = &document(); |
} |
oldDocument.scriptRunner()->movePendingAsyncScript(contextDocument->scriptRunner(), m_loader.get()); |