mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 06:17:34 +00:00
LibWeb+LibJS: Make the EventTarget hierarchy (incl. DOM) GC-allocated
This is a monster patch that turns all EventTargets into GC-allocated PlatformObjects. Their C++ wrapper classes are removed, and the LibJS garbage collector is now responsible for their lifetimes. There's a fair amount of hacks and band-aids in this patch, and we'll have a lot of cleanup to do after this.
This commit is contained in:
parent
bb547ce1c4
commit
6f433c8656
445 changed files with 4797 additions and 4268 deletions
|
@ -5,11 +5,11 @@
|
|||
*/
|
||||
|
||||
#include <LibWeb/Bindings/HTMLOptionElementPrototype.h>
|
||||
#include <LibWeb/Bindings/HTMLOptionElementWrapper.h>
|
||||
#include <LibWeb/Bindings/NodeWrapperFactory.h>
|
||||
#include <LibWeb/Bindings/OptionConstructor.h>
|
||||
#include <LibWeb/DOM/ElementFactory.h>
|
||||
#include <LibWeb/DOM/Text.h>
|
||||
#include <LibWeb/HTML/HTMLOptionElement.h>
|
||||
#include <LibWeb/HTML/Scripting/Environments.h>
|
||||
#include <LibWeb/HTML/Window.h>
|
||||
#include <LibWeb/Namespace.h>
|
||||
|
||||
|
@ -23,7 +23,7 @@ OptionConstructor::OptionConstructor(JS::Realm& realm)
|
|||
void OptionConstructor::initialize(JS::Realm& realm)
|
||||
{
|
||||
auto& vm = this->vm();
|
||||
auto& window = static_cast<WindowObject&>(realm.global_object());
|
||||
auto& window = verify_cast<HTML::Window>(realm.global_object());
|
||||
NativeFunction::initialize(realm);
|
||||
|
||||
define_direct_property(vm.names.prototype, &window.ensure_web_prototype<HTMLOptionElementPrototype>("HTMLOptionElement"), 0);
|
||||
|
@ -42,18 +42,18 @@ JS::ThrowCompletionOr<JS::Object*> OptionConstructor::construct(FunctionObject&)
|
|||
auto& realm = *vm.current_realm();
|
||||
|
||||
// 1. Let document be the current global object's associated Document.
|
||||
auto& window = static_cast<WindowObject&>(HTML::current_global_object());
|
||||
auto& document = window.impl().associated_document();
|
||||
auto& window = verify_cast<HTML::Window>(HTML::current_global_object());
|
||||
auto& document = window.associated_document();
|
||||
|
||||
// 2. Let option be the result of creating an element given document, option, and the HTML namespace.
|
||||
auto option_element = static_ptr_cast<HTML::HTMLOptionElement>(DOM::create_element(document, HTML::TagNames::option, Namespace::HTML));
|
||||
JS::NonnullGCPtr<HTML::HTMLOptionElement> option_element = verify_cast<HTML::HTMLOptionElement>(*DOM::create_element(document, HTML::TagNames::option, Namespace::HTML));
|
||||
|
||||
// 3. If text is not the empty string, then append to option a new Text node whose data is text.
|
||||
if (vm.argument_count() > 0) {
|
||||
auto text = TRY(vm.argument(0).to_string(vm));
|
||||
if (!text.is_empty()) {
|
||||
auto new_text_node = adopt_ref(*new DOM::Text(document, text));
|
||||
option_element->append_child(new_text_node);
|
||||
auto new_text_node = vm.heap().allocate<DOM::Text>(realm, document, text);
|
||||
option_element->append_child(*new_text_node);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -75,7 +75,7 @@ JS::ThrowCompletionOr<JS::Object*> OptionConstructor::construct(FunctionObject&)
|
|||
option_element->m_selected = vm.argument(3).to_boolean();
|
||||
|
||||
// 7. Return option.
|
||||
return wrap(realm, option_element);
|
||||
return option_element.ptr();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue