Slide 20
Slide 20 text
Spec of document.open
document.open
1. If document is an XML document, then throw an "InvalidStateError" DOMException exception.
2. If document's throw-on-dynamic-markup-insertion counter is greater than 0, then throw an "InvalidStateError" DOMException.
3. Let entryDocument be the entry global object's associated Document.
4. If document's origin is not same origin to entryDocument's origin, then throw a "SecurityError" DOMException.
5. If document has an active parser whose script nesting level is greater than 0, then return document.
This basically causes document.open() to be ignored when it's called in an inline script found during parsing, while still letting it have an e
ff
ect when called from a non-parser task such as a timer callback or event handler.
6. Similarly, if document's unload counter is greater than 0, then return document.
This basically causes document.open() to be ignored when it's called from a beforeunload, pagehide, or unload event handler while the Document is being unloaded.
7. If document's active parser was aborted is true, then return document.
This notably causes document.open() to be ignored if it is called after a navigation has started, but only during the initial parse. See issue #4723 for more background.
8. If document's node navigable is non-null and document's node navigable's ongoing navigation is a navigation ID, then stop loading document's node navigable.
9. For each shadow-including inclusive descendant node of document, erase all event listeners and handlers given node.
10. If document is the associated Document of document's relevant global object, then erase all event listeners and handlers given document's relevant global object.
11. Let oldFlag be the value of document's
fi
re mutation events
fl
ag.
12. Set document's
fi
re mutation events
fl
ag to false.
13. Replace all with null within document.
14. Set document's
fi
re mutation events
fl
ag to oldFlag.
15. If document is fully active, then:
1. Let newURL be a copy of entryDocument's URL.
2. If entryDocument is not document, then set newURL's fragment to null.
3. Run the URL and history update steps with document and newURL.
16. Set document's is initial about:blank to false.
17. If document's iframe load in progress
fl
ag is set, then set document's mute iframe load
fl
ag.
18. Set document to no-quirks mode.
19. Create a new HTML parser and associate it with document. This is a script-created parser (meaning that it can be closed by the document.open() and document.close() methods, and that the tokenizer will wait for an explicit call to document.close() before emitting an end-of-
fi
le token). The encoding con
fi
dence is irrelevant.
20. Set the insertion point to point at just before the end of the input stream (which at this point will be empty).
21. Update the current document readiness of document to "loading".
This causes a readystatechange event to
fi
re, but the event is actually unobservable to author code, because of the previous step which erased all event listeners and handlers that could observe it.
22. Return document.