Skip to content

Commit 78bb02c

Browse files
committed
Editorial: rearrange serialized state management
Previously, we were setting an entry's serialized state as part of the end of the navigate() call. This will work less well after #235; there, we need to set the state right after the commit, but before any handlers are called. So most of this patch is just a for-now-editorial rearrangement, to set the serialized state in a different place in the spec (but observably the same given the current API). One part of this includes rearranging things so that if options["state"] is not given to reload() or navigate(), we now pass through the serialization of undefined, instead of passing through null. This allows null to be used as a sentinel for traverse cases. This change is also not observable, since getState() would turn null into undefined.
1 parent ac1aae2 commit 78bb02c

File tree

1 file changed

+16
-19
lines changed

1 file changed

+16
-19
lines changed

spec.bs

Lines changed: 16 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -756,6 +756,12 @@ An <dfn>navigation API method navigation</dfn> is a [=struct=] with the followin
756756

757757
1. Set |navigation|'s [=navigation API method navigation/committed-to entry=] to |entry|.
758758

759+
1. If |navigation|'s [=navigation API method navigation/serialized state=] is not null, then set |entry|'s [=NavigationHistoryEntry/session history entry=]'s [=session history entry/navigation API state=] to |navigation|'s [=navigation API method navigation/serialized state=].
760+
761+
<p class="note">If it's null, then we're traversing to |entry| via {{Navigation/traverseTo()}}, which does not allow changing the state.
762+
763+
<p class="note">After this point, |navigation|'s [=navigation API method navigation/serialized state=] is no longer needed. Implementations might want to clear it out to avoid keeping it alive for the lifetime of the [=navigation API method navigation=].
764+
759765
1. [=Resolve=] |navigation|'s [=navigation API method navigation/committed promise=] with |entry|.
760766

761767
<p class="note">After this point, |navigation|'s [=navigation API method navigation/committed promise=] is only needed in cases where it has not yet been returned to author code. Implementations might want to clear it out to avoid keeping it alive for the lifetime of the [=navigation API method navigation=].
@@ -776,10 +782,10 @@ An <dfn>navigation API method navigation</dfn> is a [=struct=] with the followin
776782

777783
1. If |navigation|'s [=navigation API method navigation/finished promise=] is null, then return.
778784

779-
1. [=Reject=] |navigation|'s [=navigation API method navigation/finished promise=] with |exception|.
780-
781785
1. If |navigation|'s [=navigation API method navigation/committed promise=] is not null, then [=reject=] |navigation|'s [=navigation API method navigation/committed promise=] with |exception|.
782786

787+
1. [=Reject=] |navigation|'s [=navigation API method navigation/finished promise=] with |exception|.
788+
783789
1. [=navigation API method navigation/Clean up=] |navigation|.
784790
</div>
785791

@@ -845,9 +851,9 @@ An <dfn>navigation API method navigation</dfn> is a [=struct=] with the followin
845851
<p>In the future, we could consider loosening some of these conditions, e.g., allowing explicitly-requested push navigations to the current URL or before the document is completely loaded.
846852
</div>
847853

848-
1. Let |serializedState| be null.
854+
1. Let |state| be |options|["{{NavigationNavigateOptions/state}}"] if it exists; otherwise, undefined.
849855

850-
1. If |options|["{{NavigationNavigateOptions/state}}"] [=map/exists=], then set |serializedState| to [$StructuredSerializeForStorage$](|options|["{{NavigationNavigateOptions/state}}"]). If this throws an exception, then return [=an early error result=] for that exception.
856+
1. Let |serializedState| be [$StructuredSerializeForStorage$](|state|). If this throws an exception, then return [=an early error result=] for that exception.
851857

852858
<p class="note">It is important to perform this step early, since serialization can invoke web developer code, which in turn might change the state checked in later steps.</p>
853859

@@ -875,13 +881,15 @@ An <dfn>navigation API method navigation</dfn> is a [=struct=] with the followin
875881

876882
1. If |current| is not null, then set |serializedState| to |current|'s [=session history entry/navigation API state=].
877883

884+
1. Otherwise, set |serializedState| to [$StructuredSerializeForStorage$](undefined).
885+
878886
1. Let |info| be |options|["{{NavigationOptions/info}}"] if it exists; otherwise, undefined.
879887

880888
1. Return the result of [=performing a non-traverse navigation API navigation=] given [=this=], |urlRecord|, |serializedState|, |info|, and "<a for="history handling behavior">`reload`</a>".
881889
</div>
882890

883891
<div algorithm>
884-
To <dfn>perform a non-traverse navigation API navigation</dfn> given a {{Navigation}} object |navigation|, a [=URL=] |url|, a [=serialized state=]-or-null |serializedState|, a JavaScript value |info|, and a <a spec="HTML">history handling behavior</a> |historyHandling|:
892+
To <dfn>perform a non-traverse navigation API navigation</dfn> given a {{Navigation}} object |navigation|, a [=URL=] |url|, a [=serialized state=] |serializedState|, a JavaScript value |info|, and a <a spec="HTML">history handling behavior</a> |historyHandling|:
885893

886894
1. If |navigation|'s [=relevant global object=]'s [=associated Document=] is not [=Document/fully active=], then return [=an early error result=] for an "{{InvalidStateError}}" {{DOMException}}.
887895

@@ -905,10 +913,6 @@ An <dfn>navigation API method navigation</dfn> is a [=struct=] with the followin
905913

906914
1. Return [=an early error result=] for an "{{AbortError}}" {{DOMException}}.
907915

908-
1. If |ongoingNavigation|'s [=navigation API method navigation/serialized state=] is non-null, then set |browsingContext|'s [=session history=]'s [=session history/current entry=]'s [=session history entry/navigation API state=] to |ongoingNavigation|'s [=navigation API method navigation/serialized state=].
909-
910-
<p class="note">At this point |ongoingNavigation|'s [=navigation API method navigation/serialized state=] is no longer needed and can be nulled out instead of keeping it alive for the lifetime of the [=navigation API method navigation=].
911-
912916
1. Return «[ "{{NavigationResult/committed}}" → |ongoingNavigation|'s [=navigation API method navigation/committed promise=], "{{NavigationResult/finished}}" → |ongoingNavigation|'s [=navigation API method navigation/finished promise=] ]».
913917
</div>
914918

@@ -1391,10 +1395,9 @@ The <dfn attribute for="NavigationDestination">sameDocument</dfn> getter steps a
13911395
1. Let |ongoingNavigation| be |navigation|'s [=Navigation/ongoing navigation=].
13921396
1. If |navigation| [=Navigation/has entries and events disabled=], then:
13931397
1. If |ongoingNavigation| is not null, then:
1394-
1. Set |ongoingNavigation|'s [=navigation API method navigation/serialized state=] to null.
13951398
1. [=navigation API method navigation/Clean up=] |ongoingNavigation|.
13961399

1397-
<p class="note">In this case the [=navigation API method navigation/committed promise=] and [=navigation API method navigation/finished promise=] will never fulfill, since we never create {{NavigationHistoryEntry}}s for the initial `about:blank` {{Document}} so we have nothing to [=resolve=] them with. We also need to prevent any call to {{Navigation/navigate()|navigation.navigate()}} which triggered this algorithm from overwriting the [=session history entry/navigation API state=] of the [=session history/current entry=].
1400+
<p class="note">In this case the [=navigation API method navigation/committed promise=] and [=navigation API method navigation/finished promise=] will never fulfill, since we never create {{NavigationHistoryEntry}}s for the initial `about:blank` {{Document}} so we have nothing to [=resolve=] them with.
13981401
1. Return true.
13991402
1. Let |document| be |navigation|'s [=relevant global object=]'s [=associated document=].
14001403
1. If |document| <a spec="HTML">can have its URL rewritten</a> to |destination|'s [=NavigationDestination/URL=], and either |destination|'s [=NavigationDestination/is same document=] is true or |navigationType| is not "{{NavigationType/traverse}}", then initialize |event|'s {{NavigateEvent/canTransition}} to true. Otherwise, initialize it to false.
@@ -1457,10 +1460,7 @@ The <dfn attribute for="NavigationDestination">sameDocument</dfn> getter steps a
14571460
1. If |ongoingNavigation| is non-null, then [=navigation API method navigation/reject the finished promise=] for |ongoingNavigation| with |rejectionReason|.
14581461
1. [=Potentially reset the focus=] given |navigation| and |event|.
14591462
<p class="note">Although we still [=potentially reset the focus=] for such failed transitions, we do <em>not</em> [=potentially perform scroll restoration=] for them.
1460-
1. Otherwise, if |ongoingNavigation| is non-null, then:
1461-
1. Set |ongoingNavigation|'s [=navigation API method navigation/serialized state=] to null.
1462-
<p class="note">This ensures that any call to {{Navigation/navigate()|navigation.navigate()}} which triggered this algorithm does not overwrite the [=session history entry/navigation API state=] of the [=session history/current entry=] for cross-document navigations.
1463-
1. [=navigation API method navigation/Clean up=] |ongoingNavigation|.
1463+
1. Otherwise, if |ongoingNavigation| is non-null, then [=navigation API method navigation/clean up=] |ongoingNavigation|.
14641464
1. If |hadTransitionWhile| is true and |navigationType| is not "{{NavigationType/traverse}}":
14651465
1. If |navigationType| is not "{{NavigationType/reload}}", then run the [=URL and history update steps=] given |document| and |event|'s {{NavigateEvent/destination}}'s [=NavigationDestination/URL=], with <i>[=URL and history update steps/serializedData=]</i> set to |event|'s [=NavigateEvent/classic history API serialized data=] and <i>[=URL and history update steps/historyHandling=]</i> set to |navigationType|.
14661466

@@ -1483,10 +1483,7 @@ The <dfn attribute for="NavigationDestination">sameDocument</dfn> getter steps a
14831483
1. Set |navigation|'s [=Navigation/ongoing navigation signal=] to null.
14841484
1. [=Fire an event=] named {{Navigation/navigateerror}} at |navigation| using {{ErrorEvent}}, with {{ErrorEvent/error}} initialized to |error|, and {{ErrorEvent/message}}, {{ErrorEvent/filename}}, {{ErrorEvent/lineno}}, and {{ErrorEvent/colno}} initialized to appropriate values that can be extracted from |error| and the current JavaScript stack in the same underspecified way the user agent typically does for the <a spec="HTML">report an exception</a> algorithm.
14851485
<p class="note">Thus, for example, if this algorithm is reached because of a call to {{Window/stop()|window.stop()}}, these properties would probably end up initialized based on the line of script that called {{Window/stop()|window.stop()}}. But if it's because the user clicked the stop button, these properties would probably end up with default values like the empty string or 0.
1486-
1. If |ongoingNavigation| is non-null, then:
1487-
1. Set |ongoingNavigation|'s [=navigation API method navigation/serialized state=] to null.
1488-
<p class="note">This ensures that any call to {{Navigation/navigate()|navigation.navigate()}} which triggered this algorithm does not overwrite the [=session history entry/navigation API state=] of the [=session history/current entry=] for aborted navigations.
1489-
1. [=navigation API method navigation/Reject the finished promise=] for |ongoingNavigation| with |error|.
1486+
1. If |ongoingNavigation| is non-null, then [=navigation API method navigation/reject the finished promise=] for |ongoingNavigation| with |error|.
14901487
1. If |navigation|'s [=Navigation/transition=] is not null, then:
14911488
1. [=Reject=] |navigation|'s [=Navigation/transition=]'s [=NavigationTransition/finished promise=] with |error|.
14921489
1. Set |navigation|'s [=Navigation/transition=] to null.

0 commit comments

Comments
 (0)