LibWeb: Replace ad-hoc EventHandler type with callback function typedef

This commit is contained in:
Idan Horowitz 2022-03-30 23:35:42 +03:00 committed by Andreas Kling
parent 1c4f128fd1
commit f45d361f03
Notes: sideshowbarker 2024-07-17 17:06:59 +09:00
12 changed files with 15 additions and 23 deletions

View File

@ -510,18 +510,6 @@ static void generate_to_cpp(SourceGenerator& generator, ParameterType& parameter
@cpp_name@ = @parameter.optional_default_value@L;
)~~~");
}
} else if (parameter.type->name == "EventHandler") {
// x.onfoo = function() { ... }, x.onfoo = () => { ... }, x.onfoo = {}
// NOTE: Anything else than an object will be treated as null. This is because EventHandler has the [LegacyTreatNonObjectAsNull] extended attribute.
// Yes, you can store objects in event handler attributes. They just get ignored when there's any attempt to invoke them.
// FIXME: Replace this with proper support for callback function types.
scoped_generator.append(R"~~~(
Optional<Bindings::CallbackType> @cpp_name@;
if (@js_name@@js_suffix@.is_object()) {
@cpp_name@ = Bindings::CallbackType { JS::make_handle(&@js_name@@js_suffix@.as_object()), HTML::incumbent_settings_object() };
}
)~~~");
} else if (parameter.type->name == "Promise") {
// NOTE: It's not clear to me where the implicit wrapping of non-Promise values in a resolved
// Promise is defined in the spec; https://webidl.spec.whatwg.org/#idl-promise doesn't say
@ -1350,17 +1338,6 @@ static void generate_wrap_statement(SourceGenerator& generator, String const& va
} else if (type.name == "Location" || type.name == "Promise" || type.name == "Uint8Array" || type.name == "Uint8ClampedArray" || type.name == "any") {
scoped_generator.append(R"~~~(
@result_expression@ @value@;
)~~~");
} else if (type.name == "EventHandler") {
// FIXME: Replace this with proper support for callback function types.
scoped_generator.append(R"~~~(
if (!@value@) {
@result_expression@ JS::js_null();
} else {
VERIFY(!@value@->callback.is_null());
@result_expression@ @value@->callback.cell();
}
)~~~");
} else if (is<IDL::UnionType>(type)) {
TODO();

View File

@ -1,4 +1,5 @@
#import <DOM/EventTarget.idl>
#import <DOM/EventHandler.idl>
[Exposed=Window]
interface MediaQueryList : EventTarget {

View File

@ -1,4 +1,5 @@
#import <DOM/EventTarget.idl>
#import <DOM/EventHandler.idl>
[Exposed=(Window,Worker), CustomVisit]
interface AbortSignal : EventTarget {

View File

@ -5,6 +5,7 @@
#import <DOM/DocumentType.idl>
#import <DOM/Element.idl>
#import <DOM/Event.idl>
#import <DOM/EventHandler.idl>
#import <DOM/HTMLCollection.idl>
#import <DOM/Node.idl>
#import <DOM/NodeFilter.idl>

View File

@ -0,0 +1,3 @@
[LegacyTreatNonObjectAsNull]
callback EventHandlerNonNull = any (Event event);
typedef EventHandlerNonNull? EventHandler;

View File

@ -1,4 +1,5 @@
#import <HTML/DOMStringMap.idl>
#import <DOM/EventHandler.idl>
interface HTMLElement : Element {

View File

@ -1,4 +1,5 @@
#import <DOM/EventTarget.idl>
#import <DOM/EventHandler.idl>
interface MessagePort : EventTarget {

View File

@ -1,3 +1,6 @@
#import <DOM/EventTarget.idl>
#import <DOM/EventHandler.idl>
[Exposed=(Window)]
interface Worker : EventTarget {
constructor(DOMString scriptURL, optional WorkerOptions options = {});

View File

@ -1,4 +1,5 @@
#import <DOM/EventTarget.idl>
#import <DOM/EventHandler.idl>
#import <HTML/WorkerLocation.idl>
#import <HTML/WorkerNavigator.idl>

View File

@ -1,4 +1,5 @@
#import <DOM/EventTarget.idl>
#import <DOM/EventHandler.idl>
interface WebSocket : EventTarget {

View File

@ -1,4 +1,5 @@
#import <XHR/XMLHttpRequestEventTarget.idl>
#import <DOM/EventHandler.idl>
enum XMLHttpRequestResponseType {
"",

View File

@ -1,4 +1,5 @@
#import <DOM/EventTarget.idl>
#import <DOM/EventHandler.idl>
interface XMLHttpRequestEventTarget : EventTarget {