From 352c62ec3c9a3db33ab85f778898f266c6644ae0 Mon Sep 17 00:00:00 2001 From: Timothy Gu Date: Mon, 20 Aug 2018 14:57:31 -0400 Subject: [PATCH] document.open() simplifications, part 2 The current behavior of adding a new entry to the session history is removed, with the "replace" parameter behavior made the only option. To fix #3885, we now reuse history.replaceState()'s history model, which keeps the document's URL and the history entry URL in sync. At the same time, we restrict the history state update (including setting the document's URL) to be only run with fully active documents. Firefox already bails out for non-fully active documents (including those that are active documents), and it's not expected that there would be much usage of the URL of non-fully active documents anyway. This allows us to additionally remove the seldom implemented "replace" parameter in document.open(), whose behavior is now the default (aligning with with Chrome and Safari). The IDL is modified accordingly. Tests: https://github.com/web-platform-tests/wpt/pull/12555 Tests: https://github.com/web-platform-tests/wpt/pull/12634 Tests: https://github.com/web-platform-tests/wpt/pull/12636 Tests: https://github.com/web-platform-tests/wpt/pull/12650 Fixes #3564. Fixes #3885. --- source | 74 ++++++++++++++-------------------------------------------- 1 file changed, 17 insertions(+), 57 deletions(-) diff --git a/source b/source index d715208b817..3c8fffbaed9 100644 --- a/source +++ b/source @@ -9168,7 +9168,7 @@ partial interface Document { readonly attribute HTMLOrSVGScriptElement? currentScript; // classic scripts in a document tree only // dynamic markup insertion - [CEReactions] Document open(optional DOMString type, optional DOMString replace = ""); // type is ignored + [CEReactions] Document open(optional DOMString type, optional DOMString replace); // both type and replace are ignored WindowProxy open(USVString url, DOMString name, DOMString features); [CEReactions] void close(); [CEReactions] void write(DOMString... text); @@ -90915,8 +90915,7 @@ document.body.appendChild(frame) unloaded. Initially, the counter must be set to zero.

-

The document open steps, given a document and replaceInput, - are as follows:

+

The document open steps, given a document, are as follows:

  1. If document is an XML document, then throw @@ -90932,10 +90931,12 @@ document.body.appendChild(frame)

  2. Let window be document's relevant global object.

  3. -
  4. If document's origin is not same origin to the - origin of the responsible document specified by the entry - settings object, then throw a "SecurityError" - DOMException.

  5. +
  6. Let entryDocument be the responsible document specified by the + entry settings object.

  7. + +
  8. If document's origin is not same origin to + entryDocument's origin, then throw a + "SecurityError" DOMException.

  9. If document has an active parser whose script nesting @@ -90958,20 +90959,6 @@ document.body.appendChild(frame) handler while the Document is being unloaded.

  10. -
  11. Let replace be false. - -

  12. -

    If replaceInput is an ASCII case-insensitive match for "replace", then set replace to true.

    - -

    Otherwise, if document's browsing context's session - history contains only one Document object, and that was the - about:blank Document created when document's browsing - context was created, and that - Document object has never had the unload a document algorithm invoked - on it, then set replace to true.

    -
  13. -
  14. Abort document.

  15. For each shadow-including inclusive descendant node of @@ -90983,9 +90970,9 @@ document.body.appendChild(frame)

  16. Replace all with null within document, without firing any mutation events.

  17. -
  18. Change document's URL to the - URL of the responsible document specified - by the entry settings object.

  19. +
  20. If document is fully active, then run the URL and history + update steps with document and entryDocument's URL.

  21. @@ -91003,44 +90990,20 @@ document.body.appendChild(frame)
  22. Set the current document readiness of document to "loading".

  23. -
  24. Remove any tasks queued by the history traversal - task source that are associated with any Document objects in the - top-level browsing context's document family.

  25. - -
  26. -

    Remove all the entries in the browsing context's session history - after the current entry. If the current entry is the last entry in the - session history, then no entries are removed.

    - -

    This doesn't necessarily have to affect the user - agent's user interface.

    -
  27. - -
  28. Remove any earlier entries whose Document object is - document.

  29. - -
  30. If replace is false, then add a new entry, just before the last entry, - and associate with the new entry the text that was parsed by the previous parser associated with - document, as well as the state of document at the start of these steps. - This allows the user to step backwards in the session history to see the page before it was blown - away by the document.open(type, - replace) call. This new entry does not have a Document object, so - a new one will be created if the session history is traversed to that entry.

  31. -
  32. Finally, set the insertion point to point at just before the end of the input stream (which at this point will be empty).

  33. Return document.

+

The document open steps do not affect whether a Document + is ready for post-load tasks or completely loaded.

+

The open(type, replace) method must return the result of running the document open - steps with this Document object and replace. + steps with this Document object. -

The type argument is ignored. Also, the document.open(type, replace) method does - not affect whether a Document is ready for post-load tasks or - completely loaded.

+

The type argument is ignored.

The open(url, name, features) method must run these steps:

@@ -91185,10 +91148,7 @@ document.body.appendChild(frame) 0 or document's ignore-destructive-writes counter is greater than 0, then return.

-
  • Run the document open steps with document and the empty string. - If the user refused to allow the document to be unloaded, then return. Otherwise, - the insertion point will point at just before the end of the (empty) input - stream.

  • +
  • Run the document open steps with document.