mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 10:28:10 +00:00
LibWeb: Bring up basic external script execution in the new parser
This only works in some narrow cases, but should be enough for our own welcome.html at least. :^)
This commit is contained in:
parent
2cb50f6750
commit
4c9c6b3a7b
7 changed files with 60 additions and 3 deletions
|
@ -424,4 +424,9 @@ void Document::set_pending_parsing_blocking_script(Badge<HTMLScriptElement>, HTM
|
|||
m_pending_parsing_blocking_script = script;
|
||||
}
|
||||
|
||||
NonnullRefPtr<HTMLScriptElement> Document::take_pending_parsing_blocking_script(Badge<HTMLDocumentParser>)
|
||||
{
|
||||
return m_pending_parsing_blocking_script.release_nonnull();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -130,6 +130,8 @@ public:
|
|||
NonnullRefPtr<Text> create_text_node(const String& data);
|
||||
|
||||
void set_pending_parsing_blocking_script(Badge<HTMLScriptElement>, HTMLScriptElement*);
|
||||
HTMLScriptElement* pending_parsing_blocking_script() { return m_pending_parsing_blocking_script; }
|
||||
NonnullRefPtr<HTMLScriptElement> take_pending_parsing_blocking_script(Badge<HTMLDocumentParser>);
|
||||
|
||||
private:
|
||||
virtual RefPtr<LayoutNode> create_layout_node(const StyleProperties* parent_style) const override;
|
||||
|
|
|
@ -189,7 +189,8 @@ void HTMLScriptElement::prepare_script(Badge<HTMLDocumentParser>)
|
|||
|
||||
// FIXME: Check classic vs. module script type
|
||||
|
||||
ResourceLoader::the().load(url, [this, url](auto& data, auto&) {
|
||||
// FIXME: This load should be made asynchronous and the parser should spin an event loop etc.
|
||||
ResourceLoader::the().load_sync(url, [this, url](auto& data, auto&) {
|
||||
if (data.is_null()) {
|
||||
dbg() << "HTMLScriptElement: Failed to load " << url;
|
||||
return;
|
||||
|
@ -212,6 +213,7 @@ void HTMLScriptElement::prepare_script(Badge<HTMLDocumentParser>)
|
|||
}
|
||||
|
||||
else if (has_attribute("src") && m_parser_inserted && !has_attribute("async")) {
|
||||
|
||||
document().set_pending_parsing_blocking_script({}, this);
|
||||
when_the_script_is_ready([this] {
|
||||
m_ready_to_be_parser_executed = true;
|
||||
|
@ -234,6 +236,7 @@ void HTMLScriptElement::prepare_script(Badge<HTMLDocumentParser>)
|
|||
|
||||
void HTMLScriptElement::script_became_ready()
|
||||
{
|
||||
m_script_ready = true;
|
||||
if (!m_script_ready_callback)
|
||||
return;
|
||||
m_script_ready_callback();
|
||||
|
|
|
@ -40,15 +40,16 @@ public:
|
|||
virtual void children_changed() override;
|
||||
|
||||
bool is_non_blocking() const { return m_non_blocking; }
|
||||
bool is_ready_to_be_parser_executed() const { return m_ready_to_be_parser_executed; }
|
||||
|
||||
void set_parser_document(Badge<HTMLDocumentParser>, Document&);
|
||||
void set_non_blocking(Badge<HTMLDocumentParser>, bool);
|
||||
void prepare_script(Badge<HTMLDocumentParser>);
|
||||
void execute_script();
|
||||
|
||||
private:
|
||||
void script_became_ready();
|
||||
void when_the_script_is_ready(Function<void()>);
|
||||
void execute_script();
|
||||
|
||||
WeakPtr<Document> m_parser_document;
|
||||
WeakPtr<Document> m_preparation_time_document;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue