1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-31 11:38:11 +00:00

LibWeb: Implement "update the current document readiness" from spec

The only difference from what we were already doing is that setting the
same ready state twice no longer fires a "readystatechange" event.
I don't think that could happen in practice though.
This commit is contained in:
Andreas Kling 2021-09-26 12:22:16 +02:00
parent 8496024756
commit a2f77a2e39
3 changed files with 20 additions and 8 deletions

View file

@ -899,7 +899,7 @@ void Document::set_active_element(Element* element)
String Document::ready_state() const
{
switch (m_ready_state) {
switch (m_readiness) {
case HTML::DocumentReadyState::Loading:
return "loading"sv;
case HTML::DocumentReadyState::Interactive:
@ -910,11 +910,23 @@ String Document::ready_state() const
VERIFY_NOT_REACHED();
}
void Document::set_ready_state(HTML::DocumentReadyState ready_state)
// https://html.spec.whatwg.org/#update-the-current-document-readiness
void Document::update_readiness(HTML::DocumentReadyState readiness_value)
{
if (m_ready_state == ready_state)
// 1. If document's current document readiness equals readinessValue, then return.
if (m_readiness == readiness_value)
return;
m_ready_state = ready_state;
// The spec doesn't actually mention updating the current readiness value.
// FIXME: https://github.com/whatwg/html/issues/7120
m_readiness = readiness_value;
// FIXME: 2. If document is associated with an HTML parser, then:
// FIXME: 1. If document is associated with an HTML parser, then:
// FIXME: 2. If readinessValue is "complete", and document's load timing info's DOM complete time is 0, then set document's load timing info's DOM complete time to now.
// FIXME: 3. Otherwise, if readinessValue is "interactive", and document's load timing info's DOM interactive time is 0, then set document's load timing info's DOM interactive time to now.
// 3. Fire an event named readystatechange at document.
dispatch_event(Event::create(HTML::EventNames::readystatechange));
}

View file

@ -228,7 +228,7 @@ public:
void set_associated_inert_template_document(Document& document) { m_associated_inert_template_document = document; }
String ready_state() const;
void set_ready_state(HTML::DocumentReadyState);
void update_readiness(HTML::DocumentReadyState);
void ref_from_node(Badge<Node>)
{
@ -359,7 +359,7 @@ private:
bool m_created_for_appropriate_template_contents { false };
RefPtr<Document> m_associated_inert_template_document;
HTML::DocumentReadyState m_ready_state { HTML::DocumentReadyState::Loading };
HTML::DocumentReadyState m_readiness { HTML::DocumentReadyState::Loading };
String m_content_type { "application/xml" };
Optional<String> m_encoding;

View file

@ -188,7 +188,7 @@ void HTMLParser::the_end()
// FIXME: 2. Set the insertion point to undefined.
// 3. Update the current document readiness to "interactive".
m_document->set_ready_state(HTML::DocumentReadyState::Interactive);
m_document->update_readiness(HTML::DocumentReadyState::Interactive);
// 4. Pop all the nodes off the stack of open elements.
while (!m_stack_of_open_elements.is_empty())
@ -240,7 +240,7 @@ void HTMLParser::the_end()
// 9. Queue a global task on the DOM manipulation task source given the Document's relevant global object to run the following steps:
queue_global_task(HTML::Task::Source::DOMManipulation, *m_document, [document = m_document]() mutable {
// 1. Update the current document readiness to "complete".
document->set_ready_state(HTML::DocumentReadyState::Complete);
document->update_readiness(HTML::DocumentReadyState::Complete);
// 2. If the Document object's browsing context is null, then abort these steps.
if (!document->browsing_context())