mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-04-29 07:48:47 +00:00
LibWeb: Remove hacky old ways of running <script> element contents
Now that we're using the new HTML parser, we don't have to do the weird "run the script when inserted into the document, uhh, or when the text content of the script element changes" dance. Instead, we just follow the spec, and scripts run the way they should.
This commit is contained in:
parent
c33d17d363
commit
3a5af6ef61
Notes:
sideshowbarker
2024-07-19 05:25:46 +09:00
Author: https://github.com/awesomekling
Commit: 3a5af6ef61
3 changed files with 3 additions and 65 deletions
|
@ -53,68 +53,6 @@ void HTMLScriptElement::set_non_blocking(Badge<HTMLDocumentParser>, bool non_blo
|
|||
m_non_blocking = non_blocking;
|
||||
}
|
||||
|
||||
void HTMLScriptElement::children_changed()
|
||||
{
|
||||
HTMLElement::children_changed();
|
||||
|
||||
if (has_attribute(HTML::AttributeNames::src))
|
||||
return;
|
||||
|
||||
StringBuilder builder;
|
||||
for_each_child([&](auto& child) {
|
||||
if (is<Text>(child))
|
||||
builder.append(to<Text>(child).text_content());
|
||||
});
|
||||
auto source = builder.to_string();
|
||||
if (source.is_empty())
|
||||
return;
|
||||
|
||||
auto parser = JS::Parser(JS::Lexer(source));
|
||||
auto program = parser.parse_program();
|
||||
if (parser.has_errors()) {
|
||||
parser.print_errors();
|
||||
return;
|
||||
}
|
||||
document().interpreter().run(document().interpreter().global_object(), *program);
|
||||
}
|
||||
|
||||
void HTMLScriptElement::inserted_into(Node& new_parent)
|
||||
{
|
||||
HTMLElement::inserted_into(new_parent);
|
||||
|
||||
auto src = attribute(HTML::AttributeNames::src);
|
||||
if (src.is_null())
|
||||
return;
|
||||
|
||||
URL src_url = document().complete_url(src);
|
||||
if (src_url.protocol() == "file" && document().url().protocol() != src_url.protocol()) {
|
||||
dbg() << "HTMLScriptElement: Forbidden to load " << src_url << " from " << document().url();
|
||||
return;
|
||||
}
|
||||
|
||||
String source;
|
||||
ResourceLoader::the().load_sync(src_url, [&](auto& data, auto&) {
|
||||
if (data.is_null()) {
|
||||
dbg() << "HTMLScriptElement: Failed to load " << src;
|
||||
return;
|
||||
}
|
||||
source = String::copy(data);
|
||||
});
|
||||
if (source.is_empty()) {
|
||||
dbg() << "HTMLScriptElement: No source to parse :(";
|
||||
return;
|
||||
}
|
||||
|
||||
dbg() << "Parsing and running script from " << src_url;
|
||||
auto parser = JS::Parser(JS::Lexer(source));
|
||||
auto program = parser.parse_program();
|
||||
if (parser.has_errors()) {
|
||||
parser.print_errors();
|
||||
return;
|
||||
}
|
||||
document().interpreter().run(document().interpreter().global_object(), *program);
|
||||
}
|
||||
|
||||
void HTMLScriptElement::execute_script()
|
||||
{
|
||||
auto parser = JS::Parser(JS::Lexer(m_script_source));
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue