Skip to content

Commit 4fb2853

Browse files
committed
LibWeb/HTML: Implement NavigationTransition committed promise
1 parent 945c4ca commit 4fb2853

File tree

4 files changed

+27
-9
lines changed

4 files changed

+27
-9
lines changed

Libraries/LibWeb/HTML/Navigation.cpp

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -806,7 +806,8 @@ void Navigation::abort_a_navigate_event(GC::Ref<NavigateEvent> event, GC::Ref<We
806806
if (!m_transition)
807807
return;
808808

809-
// FIXME: 8. Reject navigation's transition's committed promise with error.
809+
// 8. Reject navigation's transition's committed promise with error.
810+
WebIDL::reject_promise(realm(), m_transition->committed(), reason);
810811

811812
// 9. Reject navigation's transition's finished promise with reason.
812813
WebIDL::reject_promise(realm(), m_transition->finished(), reason);
@@ -1127,13 +1128,17 @@ bool Navigation::inner_navigate_event_firing_algorithm(
11271128
// navigation type: navigationType
11281129
// from entry: fromNHE
11291130
// destination: event's destination
1130-
// FIXME: committed promise: a new promise created in navigation's relevant realm
1131+
// committed promise: a new promise created in navigation's relevant realm
11311132
// finished promise: a new promise created in navigation's relevant realm
1132-
m_transition = NavigationTransition::create(realm, navigation_type, *from_nhe, event->destination(), WebIDL::create_promise(realm));
1133+
m_transition = NavigationTransition::create(realm, navigation_type, *from_nhe, event->destination(), WebIDL::create_promise(realm), WebIDL::create_promise(realm));
11331134

11341135
// 5. Mark as handled navigation's transition's finished promise.
11351136
WebIDL::mark_promise_as_handled(*m_transition->finished());
11361137

1138+
// AD-HOC: The current spec has changed significantly from what we implement here, but marks the committed
1139+
// promise as handled at the equivalent place.
1140+
WebIDL::mark_promise_as_handled(*m_transition->committed());
1141+
11371142
// 6. If navigationType is "traverse", then set navigation's suppress normal scroll restoration during ongoing navigation to true.
11381143
// NOTE: If event's scroll behavior was set to "after-transition", then scroll restoration will happen as part of finishing
11391144
// the relevant NavigateEvent. Otherwise, there will be no scroll restoration. That is, no navigation which is intercepted

Libraries/LibWeb/HTML/NavigationTransition.cpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,16 +17,17 @@ namespace Web::HTML {
1717

1818
GC_DEFINE_ALLOCATOR(NavigationTransition);
1919

20-
GC::Ref<NavigationTransition> NavigationTransition::create(JS::Realm& realm, Bindings::NavigationType navigation_type, GC::Ref<NavigationHistoryEntry> from_entry, GC::Ref<NavigationDestination> destination, GC::Ref<WebIDL::Promise> finished_promise)
20+
GC::Ref<NavigationTransition> NavigationTransition::create(JS::Realm& realm, Bindings::NavigationType navigation_type, GC::Ref<NavigationHistoryEntry> from_entry, GC::Ref<NavigationDestination> destination, GC::Ref<WebIDL::Promise> committed_promise, GC::Ref<WebIDL::Promise> finished_promise)
2121
{
22-
return realm.create<NavigationTransition>(realm, navigation_type, from_entry, destination, finished_promise);
22+
return realm.create<NavigationTransition>(realm, navigation_type, from_entry, destination, committed_promise, finished_promise);
2323
}
2424

25-
NavigationTransition::NavigationTransition(JS::Realm& realm, Bindings::NavigationType navigation_type, GC::Ref<NavigationHistoryEntry> from_entry, GC::Ref<NavigationDestination> destination, GC::Ref<WebIDL::Promise> finished_promise)
25+
NavigationTransition::NavigationTransition(JS::Realm& realm, Bindings::NavigationType navigation_type, GC::Ref<NavigationHistoryEntry> from_entry, GC::Ref<NavigationDestination> destination, GC::Ref<WebIDL::Promise> committed_promise, GC::Ref<WebIDL::Promise> finished_promise)
2626
: Bindings::PlatformObject(realm)
2727
, m_navigation_type(navigation_type)
2828
, m_from_entry(from_entry)
2929
, m_destination(destination)
30+
, m_committed_promise(committed_promise)
3031
, m_finished_promise(finished_promise)
3132
{
3233
}
@@ -44,6 +45,7 @@ void NavigationTransition::visit_edges(JS::Cell::Visitor& visitor)
4445
Base::visit_edges(visitor);
4546
visitor.visit(m_from_entry);
4647
visitor.visit(m_destination);
48+
visitor.visit(m_committed_promise);
4749
visitor.visit(m_finished_promise);
4850
}
4951

Libraries/LibWeb/HTML/NavigationTransition.h

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ class NavigationTransition : public Bindings::PlatformObject {
1717
GC_DECLARE_ALLOCATOR(NavigationTransition);
1818

1919
public:
20-
[[nodiscard]] static GC::Ref<NavigationTransition> create(JS::Realm&, Bindings::NavigationType, GC::Ref<NavigationHistoryEntry>, GC::Ref<NavigationDestination>, GC::Ref<WebIDL::Promise>);
20+
[[nodiscard]] static GC::Ref<NavigationTransition> create(JS::Realm&, Bindings::NavigationType, GC::Ref<NavigationHistoryEntry>, GC::Ref<NavigationDestination>, GC::Ref<WebIDL::Promise> committed, GC::Ref<WebIDL::Promise> finished);
2121

2222
// https://html.spec.whatwg.org/multipage/nav-history-apis.html#dom-navigationtransition-navigationtype
2323
Bindings::NavigationType navigation_type() const
@@ -40,6 +40,13 @@ class NavigationTransition : public Bindings::PlatformObject {
4040
return m_destination;
4141
}
4242

43+
// https://html.spec.whatwg.org/multipage/nav-history-apis.html#dom-navigationtransition-committed
44+
GC::Ref<WebIDL::Promise> committed() const
45+
{
46+
// The committed getter steps are to return this's committed promise.
47+
return m_committed_promise;
48+
}
49+
4350
// https://html.spec.whatwg.org/multipage/nav-history-apis.html#dom-navigationtransition-finished
4451
GC::Ref<WebIDL::Promise> finished() const
4552
{
@@ -50,7 +57,7 @@ class NavigationTransition : public Bindings::PlatformObject {
5057
virtual ~NavigationTransition() override;
5158

5259
private:
53-
NavigationTransition(JS::Realm&, Bindings::NavigationType, GC::Ref<NavigationHistoryEntry>, GC::Ref<NavigationDestination>, GC::Ref<WebIDL::Promise>);
60+
NavigationTransition(JS::Realm&, Bindings::NavigationType, GC::Ref<NavigationHistoryEntry>, GC::Ref<NavigationDestination>, GC::Ref<WebIDL::Promise> committed, GC::Ref<WebIDL::Promise> finished);
5461

5562
virtual void initialize(JS::Realm&) override;
5663
virtual void visit_edges(JS::Cell::Visitor&) override;
@@ -67,6 +74,10 @@ class NavigationTransition : public Bindings::PlatformObject {
6774
// Each NavigationTransition has an associated destination, which is a NavigationDestination.
6875
GC::Ref<NavigationDestination> m_destination;
6976

77+
// https://html.spec.whatwg.org/multipage/nav-history-apis.html#concept-navigationtransition-committedc
78+
// Each NavigationTransition has an associated committed promise, which is a promise.
79+
GC::Ref<WebIDL::Promise> m_committed_promise;
80+
7081
// https://html.spec.whatwg.org/multipage/nav-history-apis.html#concept-navigationtransition-finished
7182
// Each NavigationTransition has an associated finished promise, which is a promise.
7283
GC::Ref<WebIDL::Promise> m_finished_promise;

Libraries/LibWeb/HTML/NavigationTransition.idl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,6 @@ interface NavigationTransition {
88
readonly attribute NavigationType navigationType;
99
readonly attribute NavigationHistoryEntry from;
1010
readonly attribute NavigationDestination to;
11-
// FIXME: readonly attribute Promise<undefined> committed;
11+
readonly attribute Promise<undefined> committed;
1212
readonly attribute Promise<undefined> finished;
1313
};

0 commit comments

Comments
 (0)