mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 17:07:34 +00:00
LibWeb: Move event listeners, handlers and callbacks to the GC heap
This patch moves the following things to being GC-allocated: - Bindings::CallbackType - HTML::EventHandler - DOM::IDLEventListener - DOM::DOMEventListener - DOM::NodeFilter Note that we only use PlatformObject for things that might be exposed to web content. Anything that is only used internally inherits directly from JS::Cell instead, making them a bit more lightweight.
This commit is contained in:
parent
967a3e5a45
commit
8cda70c892
57 changed files with 425 additions and 345 deletions
|
@ -395,13 +395,13 @@ static void generate_to_cpp(SourceGenerator& generator, ParameterType& parameter
|
|||
|
||||
if (parameter.type->nullable) {
|
||||
scoped_generator.append(R"~~~(
|
||||
RefPtr<@cpp_type@> @cpp_name@;
|
||||
@cpp_type@* @cpp_name@ = nullptr;
|
||||
if (!@js_name@@js_suffix@.is_nullish()) {
|
||||
if (!@js_name@@js_suffix@.is_object())
|
||||
return vm.throw_completion<JS::TypeError>(JS::ErrorType::NotAnObject, @js_name@@js_suffix@.to_string_without_side_effects());
|
||||
|
||||
CallbackType callback_type(JS::make_handle(&@js_name@@js_suffix@.as_object()), HTML::incumbent_settings_object());
|
||||
@cpp_name@ = adopt_ref(*new @cpp_type@(move(callback_type)));
|
||||
auto* callback_type = vm.heap().allocate_without_realm<CallbackType>(@js_name@@js_suffix@.as_object(), HTML::incumbent_settings_object());
|
||||
@cpp_name@ = @cpp_type@::create(realm, *callback_type).ptr();
|
||||
}
|
||||
)~~~");
|
||||
} else {
|
||||
|
@ -409,7 +409,7 @@ static void generate_to_cpp(SourceGenerator& generator, ParameterType& parameter
|
|||
if (!@js_name@@js_suffix@.is_object())
|
||||
return vm.throw_completion<JS::TypeError>(JS::ErrorType::NotAnObject, @js_name@@js_suffix@.to_string_without_side_effects());
|
||||
|
||||
CallbackType callback_type(JS::make_handle(&@js_name@@js_suffix@.as_object()), HTML::incumbent_settings_object());
|
||||
auto* callback_type = vm.heap().allocate_without_realm<CallbackType>(@js_name@@js_suffix@.as_object(), HTML::incumbent_settings_object());
|
||||
auto @cpp_name@ = adopt_ref(*new @cpp_type@(move(callback_type)));
|
||||
)~~~");
|
||||
}
|
||||
|
@ -758,13 +758,13 @@ static void generate_to_cpp(SourceGenerator& generator, ParameterType& parameter
|
|||
// 2. Return the IDL callback function type value that represents a reference to the same object that V represents, with the incumbent settings object as the callback context.
|
||||
if (callback_function.is_legacy_treat_non_object_as_null) {
|
||||
callback_function_generator.append(R"~~~(
|
||||
Optional<Bindings::CallbackType> @cpp_name@;
|
||||
Bindings::CallbackType* @cpp_name@ = nullptr;
|
||||
if (@js_name@@js_suffix@.is_object())
|
||||
@cpp_name@ = Bindings::CallbackType { JS::make_handle(&@js_name@@js_suffix@.as_object()), HTML::incumbent_settings_object() };
|
||||
@cpp_name@ = vm.heap().allocate_without_realm<CallbackType>(@js_name@@js_suffix@.as_object(), HTML::incumbent_settings_object());
|
||||
)~~~");
|
||||
} else {
|
||||
callback_function_generator.append(R"~~~(
|
||||
auto @cpp_name@ = Bindings::CallbackType { JS::make_handle(&@js_name@@js_suffix@.as_object()), HTML::incumbent_settings_object() };
|
||||
auto @cpp_name@ = vm.heap().allocate_without_realm<CallbackType>(@js_name@@js_suffix@.as_object(), HTML::incumbent_settings_object());
|
||||
)~~~");
|
||||
}
|
||||
} else if (parameter.type->name == "sequence") {
|
||||
|
@ -1599,14 +1599,12 @@ static void generate_wrap_statement(SourceGenerator& generator, String const& va
|
|||
if (!@value@) {
|
||||
@result_expression@ JS::js_null();
|
||||
} else {
|
||||
VERIFY(!@value@->callback.is_null());
|
||||
@result_expression@ @value@->callback.cell();
|
||||
@result_expression@ &@value@->callback;
|
||||
}
|
||||
)~~~");
|
||||
} else {
|
||||
scoped_generator.append(R"~~~(
|
||||
VERIFY(!@value@->callback.is_null());
|
||||
@result_expression@ @value@->callback.cell();
|
||||
@result_expression@ &@value@->callback;
|
||||
)~~~");
|
||||
}
|
||||
} else if (interface.dictionaries.contains(type.name)) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue