mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-01-08 20:32:56 +03:00
LibWeb: Replace ad-hoc EventHandler type with callback function typedef
This commit is contained in:
parent
1c4f128fd1
commit
f45d361f03
Notes:
sideshowbarker
2024-07-17 17:06:59 +09:00
Author: https://github.com/IdanHo Commit: https://github.com/SerenityOS/serenity/commit/f45d361f03 Pull-request: https://github.com/SerenityOS/serenity/pull/13369 Reviewed-by: https://github.com/alimpfard ✅
@ -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();
|
||||
|
@ -1,4 +1,5 @@
|
||||
#import <DOM/EventTarget.idl>
|
||||
#import <DOM/EventHandler.idl>
|
||||
|
||||
[Exposed=Window]
|
||||
interface MediaQueryList : EventTarget {
|
||||
|
@ -1,4 +1,5 @@
|
||||
#import <DOM/EventTarget.idl>
|
||||
#import <DOM/EventHandler.idl>
|
||||
|
||||
[Exposed=(Window,Worker), CustomVisit]
|
||||
interface AbortSignal : EventTarget {
|
||||
|
@ -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>
|
||||
|
3
Userland/Libraries/LibWeb/DOM/EventHandler.idl
Normal file
3
Userland/Libraries/LibWeb/DOM/EventHandler.idl
Normal file
@ -0,0 +1,3 @@
|
||||
[LegacyTreatNonObjectAsNull]
|
||||
callback EventHandlerNonNull = any (Event event);
|
||||
typedef EventHandlerNonNull? EventHandler;
|
@ -1,4 +1,5 @@
|
||||
#import <HTML/DOMStringMap.idl>
|
||||
#import <DOM/EventHandler.idl>
|
||||
|
||||
interface HTMLElement : Element {
|
||||
|
||||
|
@ -1,4 +1,5 @@
|
||||
#import <DOM/EventTarget.idl>
|
||||
#import <DOM/EventHandler.idl>
|
||||
|
||||
interface MessagePort : EventTarget {
|
||||
|
||||
|
@ -1,3 +1,6 @@
|
||||
#import <DOM/EventTarget.idl>
|
||||
#import <DOM/EventHandler.idl>
|
||||
|
||||
[Exposed=(Window)]
|
||||
interface Worker : EventTarget {
|
||||
constructor(DOMString scriptURL, optional WorkerOptions options = {});
|
||||
|
@ -1,4 +1,5 @@
|
||||
#import <DOM/EventTarget.idl>
|
||||
#import <DOM/EventHandler.idl>
|
||||
#import <HTML/WorkerLocation.idl>
|
||||
#import <HTML/WorkerNavigator.idl>
|
||||
|
||||
|
@ -1,4 +1,5 @@
|
||||
#import <DOM/EventTarget.idl>
|
||||
#import <DOM/EventHandler.idl>
|
||||
|
||||
interface WebSocket : EventTarget {
|
||||
|
||||
|
@ -1,4 +1,5 @@
|
||||
#import <XHR/XMLHttpRequestEventTarget.idl>
|
||||
#import <DOM/EventHandler.idl>
|
||||
|
||||
enum XMLHttpRequestResponseType {
|
||||
"",
|
||||
|
@ -1,4 +1,5 @@
|
||||
#import <DOM/EventTarget.idl>
|
||||
#import <DOM/EventHandler.idl>
|
||||
|
||||
interface XMLHttpRequestEventTarget : EventTarget {
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user