LibWeb: Adjust implementation of Document::create_event

With this change, it no longer calls TODO() and crashes WebContent
This commit is contained in:
stelar7 2022-06-06 22:11:39 +02:00 committed by Linus Groh
parent 857c3501df
commit 96caf3aed1
Notes: sideshowbarker 2024-07-17 10:25:19 +09:00
2 changed files with 28 additions and 11 deletions

View File

@ -952,10 +952,15 @@ NonnullRefPtr<Range> Document::create_range()
}
// https://dom.spec.whatwg.org/#dom-document-createevent
NonnullRefPtr<Event> Document::create_event(String const& interface)
DOM::ExceptionOr<NonnullRefPtr<Event>> Document::create_event(String const& interface)
{
auto interface_lowercase = interface.to_lowercase();
// NOTE: This is named event here, since we do step 5 and 6 as soon as possible for each case.
// 1. Let constructor be null.
RefPtr<Event> event;
// 2. If interface is an ASCII case-insensitive match for any of the strings in the first column in the following table,
// then set constructor to the interface in the second column on the same row as the matching string:
auto interface_lowercase = interface.to_lowercase();
if (interface_lowercase == "beforeunloadevent") {
event = Event::create(""); // FIXME: Create BeforeUnloadEvent
} else if (interface_lowercase == "compositionevent") {
@ -992,17 +997,29 @@ NonnullRefPtr<Event> Document::create_event(String const& interface)
event = Event::create(""); // FIXME: Create TouchEvent
} else if (interface_lowercase.is_one_of("uievent", "uievents")) {
event = UIEvents::UIEvent::create("");
} else {
// FIXME:
// 3. If constructor is null, then throw a "NotSupportedError" DOMException.
// 4. If the interface indicated by constructor is not exposed on the relevant global object of this, then throw a "NotSupportedError" DOMException.
TODO();
}
// Setting type to empty string is handled by each constructor.
// FIXME:
// 7. Initialize events timeStamp attribute to a DOMHighResTimeStamp representing the high resolution time from the time origin to now.
// 3. If constructor is null, then throw a "NotSupportedError" DOMException.
if (!event) {
return DOM::NotSupportedError::create("No constructor for interface found");
}
// FIXME: 4. If the interface indicated by constructor is not exposed on the relevant global object of this, then throw a "NotSupportedError" DOMException.
// NOTE: These are done in the if-chain above
// 5. Let event be the result of creating an event given constructor.
// 6. Initialize events type attribute to the empty string.
// NOTE: This is handled by each constructor.
// FIXME: 7. Initialize events timeStamp attribute to the result of calling current high resolution time with thiss relevant global object.
// 8. Initialize events isTrusted attribute to false.
event->set_is_trusted(false);
// 9. Unset events initialized flag.
event->set_initialized(false);
// 10. Return event.
return event.release_nonnull();
}

View File

@ -186,7 +186,7 @@ public:
NonnullRefPtr<Text> create_text_node(String const& data);
NonnullRefPtr<Comment> create_comment(String const& data);
NonnullRefPtr<Range> create_range();
NonnullRefPtr<Event> create_event(String const& interface);
ExceptionOr<NonnullRefPtr<Event>> create_event(String const& interface);
void set_pending_parsing_blocking_script(Badge<HTML::HTMLScriptElement>, HTML::HTMLScriptElement*);
HTML::HTMLScriptElement* pending_parsing_blocking_script() { return m_pending_parsing_blocking_script; }