File tree Expand file tree Collapse file tree 3 files changed +13
-1
lines changed
Userland/Libraries/LibWeb Expand file tree Collapse file tree 3 files changed +13
-1
lines changed Original file line number Diff line number Diff line change @@ -3628,7 +3628,8 @@ void Document::update_for_history_step_application(JS::NonnullGCPtr<HTML::Sessio
3628
3628
// "process scroll behavior".
3629
3629
scroll_to_the_fragment ();
3630
3630
3631
- // FIXME: 2. At this point scripts may run for the newly-created document document.
3631
+ // 2. At this point scripts may run for the newly-created document document.
3632
+ m_ready_to_run_scripts = true ;
3632
3633
}
3633
3634
3634
3635
// 7. Otherwise, if documentsEntryChanged is false and doNotReactivate is false, then:
Original file line number Diff line number Diff line change @@ -551,6 +551,8 @@ class Document
551
551
};
552
552
void append_pending_animation_event (PendingAnimationEvent const &);
553
553
554
+ bool ready_to_run_scripts () const { return m_ready_to_run_scripts; }
555
+
554
556
protected:
555
557
virtual void initialize (JS::Realm&) override ;
556
558
virtual void visit_edges (Cell::Visitor&) override ;
@@ -769,6 +771,9 @@ class Document
769
771
Vector<PendingAnimationEvent> m_pending_animation_event_queue;
770
772
771
773
bool m_needs_to_call_page_did_load { false };
774
+
775
+ // https://html.spec.whatwg.org/multipage/browsing-the-web.html#scripts-may-run-for-the-newly-created-document
776
+ bool m_ready_to_run_scripts { false };
772
777
};
773
778
774
779
template <>
Original file line number Diff line number Diff line change @@ -2729,6 +2729,12 @@ void HTMLParser::handle_text(HTMLToken& token)
2729
2729
2730
2730
// -> An end tag whose tag name is "script"
2731
2731
if (token.is_end_tag () && token.tag_name () == HTML::TagNames::script) {
2732
+ // https://html.spec.whatwg.org/multipage/document-lifecycle.html#read-html
2733
+ // Before any script execution occurs, the user agent must wait for scripts may run for the newly-created document to be true for document.
2734
+ if (!m_document->ready_to_run_scripts ()) {
2735
+ main_thread_event_loop ().spin_until ([&] { return m_document->ready_to_run_scripts (); });
2736
+ }
2737
+
2732
2738
// FIXME: If the active speculative HTML parser is null and the JavaScript execution context stack is empty, then perform a microtask checkpoint.
2733
2739
2734
2740
// Non-standard: Make sure the <script> element has up-to-date text content before preparing the script.
You can’t perform that action at this time.
0 commit comments