LibWeb: Support Document.onreadystatechange

This is just a standard IDL event attribute handler.

Fixes at least one WPT test:
https://wpt.live/html/dom/documents/resource-metadata-management/document-readyState.html
This commit is contained in:
Andreas Kling 2024-10-08 16:24:23 +02:00 committed by Andreas Kling
parent de1475f99a
commit 26be8f865a
Notes: github-actions[bot] 2024-10-08 16:50:11 +00:00
5 changed files with 28 additions and 0 deletions

View file

@ -0,0 +1 @@
interactive

View file

@ -0,0 +1,10 @@
<script src="../include.js"></script>
<script>
let readyStates = []
document.onreadystatechange = function() {
readyStates.push(document.readyState);
}
test(() => {
println(readyStates);
});
</script>

View file

@ -5666,4 +5666,14 @@ Document::StepsToFireBeforeunloadResult Document::steps_to_fire_beforeunload(boo
return { unload_prompt_shown, unload_prompt_canceled };
}
WebIDL::CallbackType* Document::onreadystatechange()
{
return event_handler_attribute(HTML::EventNames::readystatechange);
}
void Document::set_onreadystatechange(WebIDL::CallbackType* value)
{
set_event_handler_attribute(HTML::EventNames::readystatechange, value);
}
}

View file

@ -731,6 +731,9 @@ public:
};
StepsToFireBeforeunloadResult steps_to_fire_beforeunload(bool unload_prompt_shown);
[[nodiscard]] WebIDL::CallbackType* onreadystatechange();
void set_onreadystatechange(WebIDL::CallbackType*);
protected:
virtual void initialize(JS::Realm&) override;
virtual void visit_edges(Cell::Visitor&) override;

View file

@ -149,6 +149,10 @@ interface Document : Node {
boolean queryCommandState(DOMString commandId);
boolean queryCommandSupported(DOMString commandId);
DOMString queryCommandValue(DOMString commandId);
// special event handler IDL attributes that only apply to Document objects
[LegacyLenientThis] attribute EventHandler onreadystatechange;
[FIXME] attribute EventHandler onvisibilitychange;
};
dictionary ElementCreationOptions {