mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-22 07:30:19 +00:00
LibWeb: Prepare script when src is set the first time
From https://html.spec.whatwg.org/multipage/scripting.html#script-processing-model: When a script element el that is not parser-inserted experiences one of the events listed in the following list, the user agent must immediately prepare the script element el: - [...] - The script element is connected and has a src attribute set where previously the element had no such attribute.
This commit is contained in:
parent
98e1ae49f5
commit
d890be6e0f
Notes:
sideshowbarker
2024-07-17 11:30:54 +09:00
Author: https://github.com/sppmacd Commit: https://github.com/LadybirdBrowser/ladybird/commit/d890be6e0f Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/498 Issue: https://github.com/LadybirdBrowser/ladybird/issues/497 Reviewed-by: https://github.com/awesomekling Reviewed-by: https://github.com/tcl3 ✅
5 changed files with 27 additions and 0 deletions
|
@ -0,0 +1 @@
|
|||
PASS
|
13
Tests/LibWeb/Text/input/script-src-set-after-insertion.html
Normal file
13
Tests/LibWeb/Text/input/script-src-set-after-insertion.html
Normal file
|
@ -0,0 +1,13 @@
|
|||
<!DOCTYPE html>
|
||||
<head></head>
|
||||
<script src="include.js"></script>
|
||||
<script>
|
||||
asyncTest((done) => {
|
||||
const el = document.createElement("script");
|
||||
el.onload = () => {
|
||||
done();
|
||||
};
|
||||
document.head.appendChild(el);
|
||||
el.setAttribute("src", "script-src-set-after-insertion.js");
|
||||
});
|
||||
</script>
|
|
@ -0,0 +1 @@
|
|||
println("PASS");
|
|
@ -58,6 +58,16 @@ void HTMLScriptElement::attribute_changed(FlyString const& name, Optional<String
|
|||
m_crossorigin = cors_setting_attribute_from_keyword(value);
|
||||
} else if (name == HTML::AttributeNames::referrerpolicy) {
|
||||
m_referrer_policy = ReferrerPolicy::from_string(value.value_or(""_string)).value_or(ReferrerPolicy::ReferrerPolicy::EmptyString);
|
||||
} else if (name == HTML::AttributeNames::src) {
|
||||
bool old_src_is_set = m_src_is_set;
|
||||
m_src_is_set = value.has_value();
|
||||
// https://html.spec.whatwg.org/multipage/scripting.html#script-processing-model
|
||||
// When a script element el that is not parser-inserted experiences one of the events listed in the following list, the user agent must immediately prepare the script element el:
|
||||
// - [...]
|
||||
// - The script element is connected and has a src attribute set where previously the element had no such attribute.
|
||||
if (!is_parser_inserted() && is_connected() && !old_src_is_set && m_src_is_set) {
|
||||
prepare_script();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -135,6 +135,8 @@ private:
|
|||
Optional<DOM::DocumentLoadEventDelayer> m_document_load_event_delayer;
|
||||
|
||||
size_t m_source_line_number { 1 };
|
||||
|
||||
bool m_src_is_set = false;
|
||||
};
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue