Skip to content

Commit

Permalink
Handle intercept() with no handler correctly
Browse files Browse the repository at this point in the history
  • Loading branch information
domenic committed Jun 14, 2022
1 parent c1ae53c commit 3b17ca0
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions spec.bs
Original file line number Diff line number Diff line change
Expand Up @@ -1218,6 +1218,8 @@ A {{NavigateEvent}} has a <dfn for="NavigateEvent">scroll restoration behavior</

A {{NavigateEvent}} has a <dfn for="NavigateEvent">did process scroll restoration</dfn>, a boolean, initially false.

A {{NavigateEvent}} has a <dfn for="NavigateEvent">was intercepted</dfn>, a boolean, initially false.

A {{NavigateEvent}} has a <dfn for="NavigateEvent">navigation handler list</dfn>, which is a [=list=] of {{NavigationInterceptHandler}} callbacks, initially empty.

<div algorithm>
Expand All @@ -1229,6 +1231,7 @@ A {{NavigateEvent}} has a <dfn for="NavigateEvent">navigation handler list</dfn>
1. If [=this=]'s [=Event/dispatch flag=] is unset, then throw an "{{InvalidStateError}}" {{DOMException}}.
1. If [=this=]'s [=Event/canceled flag=] is set, then throw an "{{InvalidStateError}}" {{DOMException}}.
1. If |options|["{{NavigationInterceptOptions/handler}}"] [=map/exists=], then [=list/append=] it to [=this=]'s [=NavigateEvent/navigation handler list=].
1. Set [=this=]'s [=NavigateEvent/was intercepted=] to true.
1. If |options|["{{NavigationInterceptOptions/focusReset}}"] [=map/exists=], then:
1. If [=this=]'s [=NavigateEvent/focus reset behavior=] is not null, and it is not equal to |options|["{{NavigationInterceptOptions/focusReset}}"], then the user agent may [=report a warning to the console=] indicating that the {{NavigationInterceptOptions/focusReset}} option for a previous call to {{NavigateEvent/intercept()}} was overridden by this new value, and the previous value will be ignored.
1. Set [=this=]'s [=NavigateEvent/focus reset behavior=] to |options|["{{NavigationInterceptOptions/focusReset}}"].
Expand Down Expand Up @@ -1423,9 +1426,8 @@ The <dfn attribute for="NavigationDestination">sameDocument</dfn> getter steps a
1. If |navigationType| is not "{{NavigationType/traverse}}" and |event|'s {{NavigateEvent/signal}} is not [=AbortSignal/aborted=], then [=finalize with an aborted navigation error=] given |navigation| and |ongoingNavigation|.
<p class="note">If |navigationType| is "{{NavigationType/traverse}}", then we will [=finalize with an aborted navigation error=] in [=perform a navigation API traversal=].
1. Return false.
1. Let |wasIntercepted| be true if |event|'s [=NavigateEvent/navigation handler list=] is not empty; otherwise false.
1. Let |endResultIsSameDocument| be true if |wasIntercepted| is true or |destination|'s [=NavigationDestination/is same document=] is true.
1. If |wasIntercepted| is true:
1. Let |endResultIsSameDocument| be true if |event|'s [=NavigateEvent/was intercepted=] is true or |destination|'s [=NavigationDestination/is same document=] is true.
1. If |event|'s [=NavigateEvent/was intercepted=] is true:
1. Let |fromEntry| be the [=Navigation/current entry=] for |navigation|.
1. [=Assert=]: |fromEntry| is not null.
1. Set |navigation|'s [=Navigation/transition=] to a [=new=] {{NavigationTransition}} created in |navigation|'s [=relevant Realm=], whose [=NavigationTransition/navigation type=] is |navigationType|, [=NavigationTransition/from entry=] is |fromEntry|, and whose [=NavigationTransition/finished promise=] is [=a new promise=] created in |navigation|'s [=relevant Realm=].
Expand Down Expand Up @@ -1459,7 +1461,7 @@ The <dfn attribute for="NavigationDestination">sameDocument</dfn> getter steps a
1. [=Potentially reset the focus=] given |navigation| and |event|.
<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.
1. Otherwise, if |ongoingNavigation| is non-null, then [=navigation API method navigation/clean up=] |ongoingNavigation|.
1. If |wasIntercepted| is true and |navigationType| is "{{NavigationType/push}}", "{{NavigationType/replace}}", or "{{NavigationType/reload}}", then return false.
1. If |event|'s [=NavigateEvent/was intercepted=] is true and |navigationType| is "{{NavigationType/push}}", "{{NavigationType/replace}}", or "{{NavigationType/reload}}", then return false.
1. Return true.
</div>

Expand Down Expand Up @@ -1506,7 +1508,7 @@ The <dfn attribute for="NavigationDestination">sameDocument</dfn> getter steps a
1. Let |focusChanged| be |navigation|'s [=Navigation/focus changed during ongoing navigation=].
1. Set |navigation|'s [=Navigation/focus changed during ongoing navigation=] to false.
1. If |focusChanged| is true, then return.
1. If |event|'s [=NavigateEvent/navigation handler list=]'s [=list/size=] is 0, then return.
1. If |event|'s [=NavigateEvent/was intercepted=] is false, then return.
1. If |event|'s [=NavigateEvent/focus reset behavior=] is "{{NavigationFocusReset/manual}}", then return.
<p class="note">If it was left as null, then we treat that as "{{NavigationFocusReset/after-transition}}", and continue onward.
1. Let |document| be |navigation|'s [=relevant global object=]'s [=associated Document=].
Expand All @@ -1520,7 +1522,7 @@ The <dfn attribute for="NavigationDestination">sameDocument</dfn> getter steps a
<div algorithm>
To <dfn>potentially perform scroll restoration</dfn> given a {{Navigation}} object |navigation| and an {{NavigateEvent}} |event|:

1. If |event|'s [=NavigateEvent/navigation handler list=]'s [=list/size=] is 0, then return.
1. If |event|'s [=NavigateEvent/was intercepted=] is false, then return.
1. If |event|'s {{NavigateEvent/navigationType}} was not initialized to "{{NavigationType/traverse}}", then return.
1. If |event|'s [=NavigateEvent/scroll restoration behavior=] is "{{NavigationScrollRestoration/manual}}", then return.
<p class="note">If it was left as null, then we treat that as "{{NavigationScrollRestoration/after-transition}}", and continue onward.
Expand Down

0 comments on commit 3b17ca0

Please sign in to comment.