mirror of
				https://github.com/RGBCube/serenity
				synced 2025-10-31 06:12:43 +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
				
			
		|  | @ -38,10 +38,5 @@ interface CSSRule { | |||
|    - It must inherit from `public RefCounted<HTMLDetailsElement>` and `public Bindings::Wrappable` | ||||
|    - It must have a public `using WrapperType = Bindings::HTMLDetailsElementWrapper;` | ||||
| 
 | ||||
| 7. Depending on what kind of thing your interface is, you may need to add it to the `WrapperFactory` of that kind: | ||||
|    - Elements: [`LibWeb/Bindings/NodeWrapperFactory.cpp`](../../Userland/Libraries/LibWeb/Bindings/NodeWrapperFactory.cpp) | ||||
| 
 | ||||
|    Open the relevant wrapper factory file, and add `#include` directives and an `if` statement for your new type. | ||||
| 
 | ||||
| 8. If your type isn't an Event or Element, you will need to add it to [`is_wrappable_type()`](../../Meta/Lagom/Tools/CodeGenerators/LibWeb/WrapperGenerator/IDLGenerators.cpp) | ||||
|    so that it can be accepted as an IDL parameter, attribute or return type. | ||||
|  |  | |||
|  | @ -108,6 +108,48 @@ static bool impl_is_wrapper(Type const& type) | |||
|     if (type.name == "CSSImportRule"sv) | ||||
|         return true; | ||||
| 
 | ||||
|     if (type.name == "EventTarget"sv) | ||||
|         return true; | ||||
| 
 | ||||
|     if (type.name == "Node"sv) | ||||
|         return true; | ||||
|     if (type.name == "ShadowRoot"sv) | ||||
|         return true; | ||||
|     if (type.name == "DocumentTemporary"sv) | ||||
|         return true; | ||||
|     if (type.name == "Text"sv) | ||||
|         return true; | ||||
|     if (type.name == "Document"sv) | ||||
|         return true; | ||||
|     if (type.name == "DocumentType"sv) | ||||
|         return true; | ||||
|     if (type.name.ends_with("Element"sv)) | ||||
|         return true; | ||||
|     if (type.name == "XMLHttpRequest"sv) | ||||
|         return true; | ||||
|     if (type.name == "XMLHttpRequestEventTarget"sv) | ||||
|         return true; | ||||
|     if (type.name == "AbortSignal"sv) | ||||
|         return true; | ||||
|     if (type.name == "WebSocket"sv) | ||||
|         return true; | ||||
|     if (type.name == "Worker"sv) | ||||
|         return true; | ||||
|     if (type.name == "NodeIterator"sv) | ||||
|         return true; | ||||
|     if (type.name == "TreeWalker"sv) | ||||
|         return true; | ||||
|     if (type.name == "MediaQueryList"sv) | ||||
|         return true; | ||||
|     if (type.name == "MessagePort"sv) | ||||
|         return true; | ||||
|     if (type.name == "NodeFilter"sv) | ||||
|         return true; | ||||
|     if (type.name == "DOMTokenList"sv) | ||||
|         return true; | ||||
|     if (type.name == "DOMStringMap"sv) | ||||
|         return true; | ||||
| 
 | ||||
|     return false; | ||||
| } | ||||
| 
 | ||||
|  | @ -328,9 +370,10 @@ static void generate_to_cpp(SourceGenerator& generator, ParameterType& parameter | |||
|     scoped_generator.set("legacy_null_to_empty_string", legacy_null_to_empty_string ? "true" : "false"); | ||||
|     scoped_generator.set("parameter.type.name", parameter.type->name); | ||||
|     if (parameter.type->name == "Window") | ||||
|         scoped_generator.set("wrapper_name", "WindowObject"); | ||||
|     else | ||||
|         scoped_generator.set("wrapper_name", "HTML::Window"); | ||||
|     else { | ||||
|         scoped_generator.set("wrapper_name", String::formatted("{}Wrapper", parameter.type->name)); | ||||
|     } | ||||
| 
 | ||||
|     if (optional_default_value.has_value()) | ||||
|         scoped_generator.set("parameter.optional_default_value", *optional_default_value); | ||||
|  | @ -422,7 +465,7 @@ static void generate_to_cpp(SourceGenerator& generator, ParameterType& parameter | |||
| )~~~"); | ||||
|             } else { | ||||
|                 scoped_generator.append(R"~~~( | ||||
|     Optional<NonnullRefPtr<@parameter.type.name@>> @cpp_name@; | ||||
|     Optional<JS::NonnullGCPtr<@parameter.type.name@>> @cpp_name@; | ||||
|     if (!@js_name@@js_suffix@.is_undefined()) { | ||||
|         if (!@js_name@@js_suffix@.is_object() || !is<@wrapper_name@>(@js_name@@js_suffix@.as_object())) | ||||
|             return vm.throw_completion<JS::TypeError>(JS::ErrorType::NotAnObjectOfType, "@parameter.type.name@"); | ||||
|  | @ -1500,7 +1543,13 @@ static void generate_wrap_statement(SourceGenerator& generator, String const& va | |||
| )~~~"); | ||||
|         } | ||||
| 
 | ||||
|         if (impl_is_wrapper(sequence_generic_type.parameters.first())) { | ||||
|             scoped_generator.append(R"~~~( | ||||
|             auto* wrapped_element@recursion_depth@ = wrap(realm, *element@recursion_depth@); | ||||
| )~~~"); | ||||
|         } else { | ||||
|             generate_wrap_statement(scoped_generator, String::formatted("element{}", recursion_depth), sequence_generic_type.parameters.first(), interface, String::formatted("auto wrapped_element{} =", recursion_depth), WrappingReference::Yes, recursion_depth + 1); | ||||
|         } | ||||
| 
 | ||||
|         scoped_generator.append(R"~~~( | ||||
|         auto property_index@recursion_depth@ = JS::PropertyKey { i@recursion_depth@ }; | ||||
|  | @ -1950,40 +1999,6 @@ private: | |||
| }; | ||||
| )~~~"); | ||||
| 
 | ||||
|     for (auto& it : interface.enumerations) { | ||||
|         if (!it.value.is_original_definition) | ||||
|             continue; | ||||
|         auto enum_generator = generator.fork(); | ||||
|         enum_generator.set("enum.type.name", it.key); | ||||
|         enum_generator.append(R"~~~( | ||||
| enum class @enum.type.name@ { | ||||
| )~~~"); | ||||
|         for (auto& entry : it.value.translated_cpp_names) { | ||||
|             enum_generator.set("enum.entry", entry.value); | ||||
|             enum_generator.append(R"~~~( | ||||
|     @enum.entry@, | ||||
| )~~~"); | ||||
|         } | ||||
| 
 | ||||
|         enum_generator.append(R"~~~( | ||||
| }; | ||||
| inline String idl_enum_to_string(@enum.type.name@ value) { | ||||
|     switch(value) { | ||||
| )~~~"); | ||||
|         for (auto& entry : it.value.translated_cpp_names) { | ||||
|             enum_generator.set("enum.entry", entry.value); | ||||
|             enum_generator.set("enum.string", entry.key); | ||||
|             enum_generator.append(R"~~~( | ||||
|     case @enum.type.name@::@enum.entry@: return "@enum.string@"; | ||||
| )~~~"); | ||||
|         } | ||||
|         enum_generator.append(R"~~~( | ||||
|     default: return "<unknown>"; | ||||
|     }; | ||||
| } | ||||
| )~~~"); | ||||
|     } | ||||
| 
 | ||||
|     if (should_emit_wrapper_factory(interface)) { | ||||
|         generator.append(R"~~~( | ||||
| @wrapper_class@* wrap(JS::Realm&, @fully_qualified_name@&); | ||||
|  | @ -2021,8 +2036,7 @@ void generate_implementation(IDL::Interface const& interface) | |||
| #include <LibWeb/Bindings/@wrapper_class@.h> | ||||
| #endif | ||||
| #include <LibWeb/Bindings/ExceptionOrUtils.h> | ||||
| #include <LibWeb/Bindings/NodeWrapper.h> | ||||
| #include <LibWeb/Bindings/WindowObject.h> | ||||
| #include <LibWeb/HTML/Window.h> | ||||
| )~~~"); | ||||
| 
 | ||||
|     emit_includes_for_all_imports(interface, generator); | ||||
|  | @ -2055,7 +2069,7 @@ namespace Web::Bindings { | |||
|     if (interface.wrapper_base_class == "Wrapper") { | ||||
|         generator.append(R"~~~( | ||||
| @wrapper_class@::@wrapper_class@(JS::Realm& realm, @fully_qualified_name@& impl) | ||||
|     : Wrapper(static_cast<WindowObject&>(realm.global_object()).ensure_web_prototype<@prototype_class@>("@name@")) | ||||
|     : Wrapper(verify_cast<HTML::Window>(realm.global_object()).ensure_web_prototype<@prototype_class@>("@name@")) | ||||
|     , m_impl(impl) | ||||
| { | ||||
| } | ||||
|  | @ -2065,7 +2079,7 @@ namespace Web::Bindings { | |||
| @wrapper_class@::@wrapper_class@(JS::Realm& realm, @fully_qualified_name@& impl) | ||||
|     : @wrapper_base_class@(realm, impl) | ||||
| { | ||||
|     set_prototype(&static_cast<WindowObject&>(realm.global_object()).ensure_web_prototype<@prototype_class@>("@name@")); | ||||
|     set_prototype(&verify_cast<HTML::Window>(realm.global_object()).ensure_web_prototype<@prototype_class@>("@name@")); | ||||
| } | ||||
| )~~~"); | ||||
|     } | ||||
|  | @ -2902,11 +2916,8 @@ void generate_constructor_implementation(IDL::Interface const& interface) | |||
| #if __has_include(<LibWeb/Bindings/@wrapper_class@.h>) | ||||
| #include <LibWeb/Bindings/@wrapper_class@.h> | ||||
| #endif | ||||
| #include <LibWeb/Bindings/EventTargetWrapperFactory.h> | ||||
| #include <LibWeb/Bindings/ExceptionOrUtils.h> | ||||
| #include <LibWeb/Bindings/NodeWrapper.h> | ||||
| #include <LibWeb/Bindings/NodeWrapperFactory.h> | ||||
| #include <LibWeb/Bindings/WindowObject.h> | ||||
| #include <LibWeb/HTML/Window.h> | ||||
| #if __has_include(<LibWeb/Crypto/@name@.h>) | ||||
| #    include <LibWeb/Crypto/@name@.h> | ||||
| #elif __has_include(<LibWeb/CSS/@name@.h>) | ||||
|  | @ -3007,7 +3018,7 @@ JS::ThrowCompletionOr<JS::Object*> @constructor_class@::construct(FunctionObject | |||
|     auto& vm = this->vm(); | ||||
|     [[maybe_unused]] auto& realm = *vm.current_realm(); | ||||
| 
 | ||||
|     auto& window = static_cast<WindowObject&>(realm.global_object()); | ||||
|     auto& window = verify_cast<HTML::Window>(realm.global_object()); | ||||
| )~~~"); | ||||
| 
 | ||||
|         if (!constructor.parameters.is_empty()) { | ||||
|  | @ -3039,7 +3050,7 @@ JS::ThrowCompletionOr<JS::Object*> @constructor_class@::construct(FunctionObject | |||
| void @constructor_class@::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()); | ||||
|     [[maybe_unused]] u8 default_attributes = JS::Attribute::Enumerable; | ||||
| 
 | ||||
|     NativeFunction::initialize(realm); | ||||
|  | @ -3165,8 +3176,46 @@ private: | |||
|     } | ||||
| 
 | ||||
|     generator.append(R"~~~( | ||||
| 
 | ||||
| }; | ||||
| 
 | ||||
| )~~~"); | ||||
| 
 | ||||
|     for (auto& it : interface.enumerations) { | ||||
|         if (!it.value.is_original_definition) | ||||
|             continue; | ||||
|         auto enum_generator = generator.fork(); | ||||
|         enum_generator.set("enum.type.name", it.key); | ||||
|         enum_generator.append(R"~~~( | ||||
| enum class @enum.type.name@ { | ||||
| )~~~"); | ||||
|         for (auto& entry : it.value.translated_cpp_names) { | ||||
|             enum_generator.set("enum.entry", entry.value); | ||||
|             enum_generator.append(R"~~~( | ||||
|     @enum.entry@, | ||||
| )~~~"); | ||||
|         } | ||||
| 
 | ||||
|         enum_generator.append(R"~~~( | ||||
| }; | ||||
| inline String idl_enum_to_string(@enum.type.name@ value) { | ||||
|     switch(value) { | ||||
| )~~~"); | ||||
|         for (auto& entry : it.value.translated_cpp_names) { | ||||
|             enum_generator.set("enum.entry", entry.value); | ||||
|             enum_generator.set("enum.string", entry.key); | ||||
|             enum_generator.append(R"~~~( | ||||
|     case @enum.type.name@::@enum.entry@: return "@enum.string@"; | ||||
| )~~~"); | ||||
|         } | ||||
|         enum_generator.append(R"~~~( | ||||
|     default: return "<unknown>"; | ||||
|     }; | ||||
| } | ||||
| )~~~"); | ||||
|     } | ||||
| 
 | ||||
|     generator.append(R"~~~( | ||||
| } // namespace Web::Bindings
 | ||||
|     )~~~"); | ||||
| 
 | ||||
|  | @ -3208,10 +3257,8 @@ void generate_prototype_implementation(IDL::Interface const& interface) | |||
| #endif | ||||
| #include <LibWeb/Bindings/ExceptionOrUtils.h> | ||||
| #include <LibWeb/Bindings/LocationObject.h> | ||||
| #include <LibWeb/Bindings/WindowObject.h> | ||||
| #include <LibWeb/Bindings/WorkerLocationWrapper.h> | ||||
| #include <LibWeb/Bindings/WorkerNavigatorWrapper.h> | ||||
| #include <LibWeb/Bindings/WorkerWrapper.h> | ||||
| #include <LibWeb/DOM/Element.h> | ||||
| #include <LibWeb/DOM/Event.h> | ||||
| #include <LibWeb/DOM/IDLEventListener.h> | ||||
|  | @ -3266,7 +3313,7 @@ namespace Web::Bindings { | |||
| )~~~"); | ||||
|     } else if (!interface.parent_name.is_empty()) { | ||||
|         generator.append(R"~~~( | ||||
|     : Object(static_cast<WindowObject&>(realm.global_object()).ensure_web_prototype<@prototype_base_class@>("@parent_name@")) | ||||
|     : Object(verify_cast<HTML::Window>(realm.global_object()).ensure_web_prototype<@prototype_base_class@>("@parent_name@")) | ||||
| )~~~"); | ||||
|     } else { | ||||
|         generator.append(R"~~~( | ||||
|  | @ -3418,8 +3465,8 @@ static JS::ThrowCompletionOr<@fully_qualified_name@*> impl_from(JS::VM& vm) | |||
| 
 | ||||
|         if (interface.name == "EventTarget") { | ||||
|             generator.append(R"~~~( | ||||
|     if (is<WindowObject>(this_object)) { | ||||
|         return &static_cast<WindowObject*>(this_object)->impl(); | ||||
|     if (is<HTML::Window>(this_object)) { | ||||
|         return &static_cast<HTML::Window*>(this_object)->impl(); | ||||
|     } | ||||
| )~~~"); | ||||
|         } | ||||
|  | @ -3686,7 +3733,7 @@ void generate_iterator_implementation(IDL::Interface const& interface) | |||
| #include <LibWeb/Bindings/@wrapper_class@.h> | ||||
| #endif | ||||
| #include <LibWeb/Bindings/IDLAbstractOperations.h> | ||||
| #include <LibWeb/Bindings/WindowObject.h> | ||||
| #include <LibWeb/HTML/Window.h> | ||||
| 
 | ||||
| )~~~"); | ||||
| 
 | ||||
|  | @ -3720,7 +3767,7 @@ namespace Web::Bindings { | |||
| } | ||||
| 
 | ||||
| @wrapper_class@::@wrapper_class@(JS::Realm& realm, @fully_qualified_name@& impl) | ||||
|     : Wrapper(static_cast<WindowObject&>(realm.global_object()).ensure_web_prototype<@prototype_class@>("@name@")) | ||||
|     : Wrapper(verify_cast<HTML::Window>(realm.global_object()).ensure_web_prototype<@prototype_class@>("@name@")) | ||||
|     , m_impl(impl) | ||||
| { | ||||
| } | ||||
|  | @ -3804,7 +3851,7 @@ void generate_iterator_prototype_implementation(IDL::Interface const& interface) | |||
| #include <LibJS/Runtime/TypedArray.h> | ||||
| #include <LibWeb/Bindings/@prototype_class@.h> | ||||
| #include <LibWeb/Bindings/ExceptionOrUtils.h> | ||||
| #include <LibWeb/Bindings/WindowObject.h> | ||||
| #include <LibWeb/HTML/Window.h> | ||||
| 
 | ||||
| #if __has_include(<LibWeb/@possible_include_path@.h>) | ||||
| #    include <LibWeb/@possible_include_path@.h> | ||||
|  |  | |||
|  | @ -20,7 +20,6 @@ | |||
| #include <LibJS/Heap/CellAllocator.h> | ||||
| #include <LibJS/Heap/Handle.h> | ||||
| #include <LibJS/Heap/MarkedVector.h> | ||||
| #include <LibJS/Runtime/Object.h> | ||||
| #include <LibJS/Runtime/WeakContainer.h> | ||||
| 
 | ||||
| namespace JS { | ||||
|  |  | |||
|  | @ -6,9 +6,8 @@ | |||
| 
 | ||||
| #include <LibWeb/Bindings/AudioConstructor.h> | ||||
| #include <LibWeb/Bindings/HTMLAudioElementPrototype.h> | ||||
| #include <LibWeb/Bindings/HTMLAudioElementWrapper.h> | ||||
| #include <LibWeb/Bindings/NodeWrapperFactory.h> | ||||
| #include <LibWeb/DOM/ElementFactory.h> | ||||
| #include <LibWeb/HTML/Scripting/Environments.h> | ||||
| #include <LibWeb/HTML/Window.h> | ||||
| #include <LibWeb/Namespace.h> | ||||
| 
 | ||||
|  | @ -22,7 +21,7 @@ AudioConstructor::AudioConstructor(JS::Realm& realm) | |||
| void AudioConstructor::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<HTMLAudioElementPrototype>("HTMLAudioElement"), 0); | ||||
|  | @ -38,10 +37,9 @@ JS::ThrowCompletionOr<JS::Value> AudioConstructor::call() | |||
| JS::ThrowCompletionOr<JS::Object*> AudioConstructor::construct(FunctionObject&) | ||||
| { | ||||
|     auto& vm = this->vm(); | ||||
|     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& window = verify_cast<HTML::Window>(HTML::current_global_object()); | ||||
|     auto& document = window.impl().associated_document(); | ||||
| 
 | ||||
|     // 2. Let audio be the result of creating an element given document, audio, and the HTML namespace.
 | ||||
|  | @ -60,7 +58,7 @@ JS::ThrowCompletionOr<JS::Object*> AudioConstructor::construct(FunctionObject&) | |||
|     } | ||||
| 
 | ||||
|     // 5. Return audio.
 | ||||
|     return wrap(realm, audio); | ||||
|     return audio.ptr(); | ||||
| } | ||||
| 
 | ||||
| } | ||||
|  |  | |||
|  | @ -17,14 +17,14 @@ | |||
| #include <LibWeb/Bindings/DOMExceptionWrapper.h> | ||||
| #include <LibWeb/Bindings/LocationObject.h> | ||||
| #include <LibWeb/Bindings/MainThreadVM.h> | ||||
| #include <LibWeb/Bindings/WindowObject.h> | ||||
| #include <LibWeb/DOM/DOMException.h> | ||||
| #include <LibWeb/HTML/Scripting/Environments.h> | ||||
| #include <LibWeb/HTML/Window.h> | ||||
| 
 | ||||
| namespace Web::Bindings { | ||||
| 
 | ||||
| // 7.2.3.1 CrossOriginProperties ( O ), https://html.spec.whatwg.org/multipage/browsers.html#crossoriginproperties-(-o-)
 | ||||
| Vector<CrossOriginProperty> cross_origin_properties(Variant<LocationObject const*, WindowObject const*> const& object) | ||||
| Vector<CrossOriginProperty> cross_origin_properties(Variant<LocationObject const*, HTML::Window const*> const& object) | ||||
| { | ||||
|     // 1. Assert: O is a Location or Window object.
 | ||||
| 
 | ||||
|  | @ -37,7 +37,7 @@ Vector<CrossOriginProperty> cross_origin_properties(Variant<LocationObject const | |||
|             }; | ||||
|         }, | ||||
|         // 3. Return « { [[Property]]: "window", [[NeedsGet]]: true, [[NeedsSet]]: false }, { [[Property]]: "self", [[NeedsGet]]: true, [[NeedsSet]]: false }, { [[Property]]: "location", [[NeedsGet]]: true, [[NeedsSet]]: true }, { [[Property]]: "close" }, { [[Property]]: "closed", [[NeedsGet]]: true, [[NeedsSet]]: false }, { [[Property]]: "focus" }, { [[Property]]: "blur" }, { [[Property]]: "frames", [[NeedsGet]]: true, [[NeedsSet]]: false }, { [[Property]]: "length", [[NeedsGet]]: true, [[NeedsSet]]: false }, { [[Property]]: "top", [[NeedsGet]]: true, [[NeedsSet]]: false }, { [[Property]]: "opener", [[NeedsGet]]: true, [[NeedsSet]]: false }, { [[Property]]: "parent", [[NeedsGet]]: true, [[NeedsSet]]: false }, { [[Property]]: "postMessage" } ».
 | ||||
|         [](WindowObject const*) -> Vector<CrossOriginProperty> { | ||||
|         [](HTML::Window const*) -> Vector<CrossOriginProperty> { | ||||
|             return { | ||||
|                 { .property = "window"sv, .needs_get = true, .needs_set = false }, | ||||
|                 { .property = "self"sv, .needs_get = true, .needs_set = false }, | ||||
|  | @ -90,11 +90,11 @@ bool is_platform_object_same_origin(JS::Object const& object) | |||
| } | ||||
| 
 | ||||
| // 7.2.3.4 CrossOriginGetOwnPropertyHelper ( O, P ), https://html.spec.whatwg.org/multipage/browsers.html#crossorigingetownpropertyhelper-(-o,-p-)
 | ||||
| Optional<JS::PropertyDescriptor> cross_origin_get_own_property_helper(Variant<LocationObject*, WindowObject*> const& object, JS::PropertyKey const& property_key) | ||||
| Optional<JS::PropertyDescriptor> cross_origin_get_own_property_helper(Variant<LocationObject*, HTML::Window*> const& object, JS::PropertyKey const& property_key) | ||||
| { | ||||
|     auto& realm = *main_thread_vm().current_realm(); | ||||
|     auto const* object_ptr = object.visit([](auto* o) { return static_cast<JS::Object const*>(o); }); | ||||
|     auto const object_const_variant = object.visit([](auto* o) { return Variant<LocationObject const*, WindowObject const*> { o }; }); | ||||
|     auto const object_const_variant = object.visit([](auto* o) { return Variant<LocationObject const*, HTML::Window const*> { o }; }); | ||||
| 
 | ||||
|     // 1. Let crossOriginKey be a tuple consisting of the current settings object, O's relevant settings object, and P.
 | ||||
|     auto cross_origin_key = CrossOriginKey { | ||||
|  | @ -227,7 +227,7 @@ JS::ThrowCompletionOr<bool> cross_origin_set(JS::VM& vm, JS::Object& object, JS: | |||
| } | ||||
| 
 | ||||
| // 7.2.3.7 CrossOriginOwnPropertyKeys ( O ), https://html.spec.whatwg.org/multipage/browsers.html#crossoriginownpropertykeys-(-o-)
 | ||||
| JS::MarkedVector<JS::Value> cross_origin_own_property_keys(Variant<LocationObject const*, WindowObject const*> const& object) | ||||
| JS::MarkedVector<JS::Value> cross_origin_own_property_keys(Variant<LocationObject const*, HTML::Window const*> const& object) | ||||
| { | ||||
|     auto& event_loop = HTML::main_thread_event_loop(); | ||||
|     auto& vm = event_loop.vm(); | ||||
|  |  | |||
|  | @ -9,6 +9,7 @@ | |||
| #include <AK/Forward.h> | ||||
| #include <AK/Traits.h> | ||||
| #include <LibJS/Forward.h> | ||||
| #include <LibJS/Runtime/PropertyKey.h> | ||||
| #include <LibWeb/Forward.h> | ||||
| 
 | ||||
| namespace Web::Bindings { | ||||
|  | @ -27,14 +28,14 @@ struct CrossOriginKey { | |||
| 
 | ||||
| using CrossOriginPropertyDescriptorMap = HashMap<CrossOriginKey, JS::PropertyDescriptor>; | ||||
| 
 | ||||
| Vector<CrossOriginProperty> cross_origin_properties(Variant<LocationObject const*, WindowObject const*> const&); | ||||
| Vector<CrossOriginProperty> cross_origin_properties(Variant<LocationObject const*, HTML::Window const*> const&); | ||||
| bool is_cross_origin_accessible_window_property_name(JS::PropertyKey const&); | ||||
| JS::ThrowCompletionOr<JS::PropertyDescriptor> cross_origin_property_fallback(JS::VM&, JS::PropertyKey const&); | ||||
| bool is_platform_object_same_origin(JS::Object const&); | ||||
| Optional<JS::PropertyDescriptor> cross_origin_get_own_property_helper(Variant<LocationObject*, WindowObject*> const&, JS::PropertyKey const&); | ||||
| Optional<JS::PropertyDescriptor> cross_origin_get_own_property_helper(Variant<LocationObject*, HTML::Window*> const&, JS::PropertyKey const&); | ||||
| JS::ThrowCompletionOr<JS::Value> cross_origin_get(JS::VM&, JS::Object const&, JS::PropertyKey const&, JS::Value receiver); | ||||
| JS::ThrowCompletionOr<bool> cross_origin_set(JS::VM&, JS::Object&, JS::PropertyKey const&, JS::Value, JS::Value receiver); | ||||
| JS::MarkedVector<JS::Value> cross_origin_own_property_keys(Variant<LocationObject const*, WindowObject const*> const&); | ||||
| JS::MarkedVector<JS::Value> cross_origin_own_property_keys(Variant<LocationObject const*, HTML::Window const*> const&); | ||||
| 
 | ||||
| } | ||||
| 
 | ||||
|  |  | |||
|  | @ -1,17 +0,0 @@ | |||
| /*
 | ||||
|  * Copyright (c) 2020, Andreas Kling <kling@serenityos.org> | ||||
|  * | ||||
|  * SPDX-License-Identifier: BSD-2-Clause | ||||
|  */ | ||||
| 
 | ||||
| #include <LibWeb/Bindings/EventTargetWrapperFactory.h> | ||||
| #include <LibWeb/DOM/EventTarget.h> | ||||
| 
 | ||||
| namespace Web::Bindings { | ||||
| 
 | ||||
| JS::Object* wrap(JS::Realm& realm, DOM::EventTarget& target) | ||||
| { | ||||
|     return target.create_wrapper(realm); | ||||
| } | ||||
| 
 | ||||
| } | ||||
|  | @ -1,16 +0,0 @@ | |||
| /*
 | ||||
|  * Copyright (c) 2020, Andreas Kling <kling@serenityos.org> | ||||
|  * | ||||
|  * SPDX-License-Identifier: BSD-2-Clause | ||||
|  */ | ||||
| 
 | ||||
| #pragma once | ||||
| 
 | ||||
| #include <LibJS/Forward.h> | ||||
| #include <LibWeb/Forward.h> | ||||
| 
 | ||||
| namespace Web::Bindings { | ||||
| 
 | ||||
| JS::Object* wrap(JS::Realm&, DOM::EventTarget&); | ||||
| 
 | ||||
| } | ||||
|  | @ -128,7 +128,7 @@ JS::Completion invoke_callback(Bindings::CallbackType& callback, Optional<JS::Va | |||
| { | ||||
|     auto& function_object = callback.callback; | ||||
| 
 | ||||
|     JS::MarkedVector<JS::Value> arguments_list { function_object->vm().heap() }; | ||||
|     JS::MarkedVector<JS::Value> arguments_list { function_object.vm().heap() }; | ||||
|     (arguments_list.append(forward<Args>(args)), ...); | ||||
| 
 | ||||
|     return invoke_callback(callback, move(this_argument), move(arguments_list)); | ||||
|  |  | |||
|  | @ -5,10 +5,9 @@ | |||
|  */ | ||||
| 
 | ||||
| #include <LibWeb/Bindings/HTMLImageElementPrototype.h> | ||||
| #include <LibWeb/Bindings/HTMLImageElementWrapper.h> | ||||
| #include <LibWeb/Bindings/ImageConstructor.h> | ||||
| #include <LibWeb/Bindings/NodeWrapperFactory.h> | ||||
| #include <LibWeb/DOM/ElementFactory.h> | ||||
| #include <LibWeb/HTML/Scripting/Environments.h> | ||||
| #include <LibWeb/HTML/Window.h> | ||||
| #include <LibWeb/Namespace.h> | ||||
| 
 | ||||
|  | @ -22,7 +21,7 @@ ImageConstructor::ImageConstructor(JS::Realm& realm) | |||
| void ImageConstructor::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<HTMLImageElementPrototype>("HTMLImageElement"), 0); | ||||
|  | @ -38,11 +37,10 @@ JS::ThrowCompletionOr<JS::Value> ImageConstructor::call() | |||
| JS::ThrowCompletionOr<JS::Object*> ImageConstructor::construct(FunctionObject&) | ||||
| { | ||||
|     auto& vm = this->vm(); | ||||
|     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 img be the result of creating an element given document, img, and the HTML namespace.
 | ||||
|     auto image_element = DOM::create_element(document, HTML::TagNames::img, Namespace::HTML); | ||||
|  | @ -60,7 +58,7 @@ JS::ThrowCompletionOr<JS::Object*> ImageConstructor::construct(FunctionObject&) | |||
|     } | ||||
| 
 | ||||
|     // 5. Return img.
 | ||||
|     return wrap(realm, image_element); | ||||
|     return image_element.ptr(); | ||||
| } | ||||
| 
 | ||||
| } | ||||
|  |  | |||
|  | @ -12,7 +12,7 @@ namespace Web::Bindings { | |||
| 
 | ||||
| // https://webidl.spec.whatwg.org/#dfn-legacy-platform-object
 | ||||
| class LegacyPlatformObject : public PlatformObject { | ||||
|     JS_OBJECT(LegacyPlatformObject, PlatformObject); | ||||
|     WEB_PLATFORM_OBJECT(LegacyPlatformObject, PlatformObject); | ||||
| 
 | ||||
| public: | ||||
|     virtual ~LegacyPlatformObject() override; | ||||
|  |  | |||
|  | @ -7,7 +7,7 @@ | |||
| #include <LibJS/Runtime/GlobalObject.h> | ||||
| #include <LibWeb/Bindings/LocationConstructor.h> | ||||
| #include <LibWeb/Bindings/LocationPrototype.h> | ||||
| #include <LibWeb/Bindings/WindowObject.h> | ||||
| #include <LibWeb/HTML/Window.h> | ||||
| 
 | ||||
| namespace Web::Bindings { | ||||
| 
 | ||||
|  | @ -31,7 +31,7 @@ JS::ThrowCompletionOr<JS::Object*> LocationConstructor::construct(FunctionObject | |||
| void LocationConstructor::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<LocationPrototype>("Location"), 0); | ||||
|  |  | |||
|  | @ -15,7 +15,6 @@ | |||
| #include <LibWeb/Bindings/DOMExceptionWrapper.h> | ||||
| #include <LibWeb/Bindings/LocationObject.h> | ||||
| #include <LibWeb/Bindings/LocationPrototype.h> | ||||
| #include <LibWeb/Bindings/WindowObject.h> | ||||
| #include <LibWeb/DOM/DOMException.h> | ||||
| #include <LibWeb/DOM/Document.h> | ||||
| #include <LibWeb/HTML/Window.h> | ||||
|  | @ -24,7 +23,7 @@ namespace Web::Bindings { | |||
| 
 | ||||
| // https://html.spec.whatwg.org/multipage/history.html#the-location-interface
 | ||||
| LocationObject::LocationObject(JS::Realm& realm) | ||||
|     : Object(static_cast<WindowObject&>(realm.global_object()).ensure_web_prototype<LocationPrototype>("Location")) | ||||
|     : Object(verify_cast<HTML::Window>(realm.global_object()).ensure_web_prototype<LocationPrototype>("Location")) | ||||
|     , m_default_properties(heap()) | ||||
| { | ||||
| } | ||||
|  | @ -60,7 +59,7 @@ DOM::Document const* LocationObject::relevant_document() const | |||
|     // A Location object has an associated relevant Document, which is this Location object's
 | ||||
|     // relevant global object's browsing context's active document, if this Location object's
 | ||||
|     // relevant global object's browsing context is non-null, and null otherwise.
 | ||||
|     auto* browsing_context = verify_cast<WindowObject>(HTML::relevant_global_object(*this)).impl().browsing_context(); | ||||
|     auto* browsing_context = verify_cast<HTML::Window>(HTML::relevant_global_object(*this)).browsing_context(); | ||||
|     return browsing_context ? browsing_context->active_document() : nullptr; | ||||
| } | ||||
| 
 | ||||
|  | @ -95,7 +94,7 @@ JS_DEFINE_NATIVE_FUNCTION(LocationObject::href_getter) | |||
| // https://html.spec.whatwg.org/multipage/history.html#the-location-interface:dom-location-href-2
 | ||||
| JS_DEFINE_NATIVE_FUNCTION(LocationObject::href_setter) | ||||
| { | ||||
|     auto& window = static_cast<WindowObject&>(HTML::current_global_object()); | ||||
|     auto& window = verify_cast<HTML::Window>(HTML::current_global_object()); | ||||
| 
 | ||||
|     // FIXME: 1. If this's relevant Document is null, then return.
 | ||||
| 
 | ||||
|  | @ -218,7 +217,7 @@ JS_DEFINE_NATIVE_FUNCTION(LocationObject::port_getter) | |||
| // https://html.spec.whatwg.org/multipage/history.html#dom-location-reload
 | ||||
| JS_DEFINE_NATIVE_FUNCTION(LocationObject::reload) | ||||
| { | ||||
|     auto& window = static_cast<WindowObject&>(HTML::current_global_object()); | ||||
|     auto& window = verify_cast<HTML::Window>(HTML::current_global_object()); | ||||
|     window.impl().did_call_location_reload({}); | ||||
|     return JS::js_undefined(); | ||||
| } | ||||
|  | @ -226,7 +225,7 @@ JS_DEFINE_NATIVE_FUNCTION(LocationObject::reload) | |||
| // https://html.spec.whatwg.org/multipage/history.html#dom-location-replace
 | ||||
| JS_DEFINE_NATIVE_FUNCTION(LocationObject::replace) | ||||
| { | ||||
|     auto& window = static_cast<WindowObject&>(HTML::current_global_object()); | ||||
|     auto& window = verify_cast<HTML::Window>(HTML::current_global_object()); | ||||
|     auto url = TRY(vm.argument(0).to_string(vm)); | ||||
|     // FIXME: This needs spec compliance work.
 | ||||
|     window.impl().did_call_location_replace({}, move(url)); | ||||
|  |  | |||
|  | @ -9,8 +9,8 @@ | |||
| #include <LibJS/Runtime/GlobalObject.h> | ||||
| #include <LibJS/Runtime/Object.h> | ||||
| #include <LibJS/Runtime/VM.h> | ||||
| #include <LibWeb/Bindings/WindowObject.h> | ||||
| #include <LibWeb/Forward.h> | ||||
| #include <LibWeb/HTML/Window.h> | ||||
| 
 | ||||
| namespace Web::Bindings { | ||||
| 
 | ||||
|  |  | |||
|  | @ -127,7 +127,7 @@ JS::VM& main_thread_vm() | |||
|                 //    with the promise attribute initialized to promise, and the reason attribute initialized to the value of promise's [[PromiseResult]] internal slot.
 | ||||
|                 HTML::queue_global_task(HTML::Task::Source::DOMManipulation, global, [global = JS::make_handle(&global), promise = JS::make_handle(&promise)]() mutable { | ||||
|                     // FIXME: This currently assumes that global is a WindowObject.
 | ||||
|                     auto& window = verify_cast<Bindings::WindowObject>(*global.cell()); | ||||
|                     auto& window = verify_cast<HTML::Window>(*global.cell()); | ||||
| 
 | ||||
|                     HTML::PromiseRejectionEventInit event_init { | ||||
|                         {}, // Initialize the inherited DOM::EventInit
 | ||||
|  | @ -135,7 +135,7 @@ JS::VM& main_thread_vm() | |||
|                         /* .reason = */ promise.cell()->result(), | ||||
|                     }; | ||||
|                     auto promise_rejection_event = HTML::PromiseRejectionEvent::create(window, HTML::EventNames::rejectionhandled, event_init); | ||||
|                     window.impl().dispatch_event(*promise_rejection_event); | ||||
|                     window.dispatch_event(*promise_rejection_event); | ||||
|                 }); | ||||
|                 break; | ||||
|             } | ||||
|  | @ -308,20 +308,18 @@ JS::VM& main_thread_vm() | |||
|         //       just to make sure that it's never empty.
 | ||||
|         auto& custom_data = *verify_cast<WebEngineCustomData>(vm->custom_data()); | ||||
|         custom_data.root_execution_context = MUST(JS::Realm::initialize_host_defined_realm( | ||||
|             *vm, [&](JS::Realm& realm) -> JS::GlobalObject* { | ||||
|                 auto internal_window = HTML::Window::create(); | ||||
|                 custom_data.internal_window_object = JS::make_handle(vm->heap().allocate<Bindings::WindowObject>(realm, realm, internal_window)); | ||||
|                 return custom_data.internal_window_object.cell(); }, | ||||
|             [](JS::Realm&) -> JS::GlobalObject* { | ||||
|                 return nullptr; | ||||
|             })); | ||||
|             *vm, [&](JS::Realm& realm) -> JS::Object* { | ||||
|                 custom_data.internal_window_object = JS::make_handle(*HTML::Window::create(realm)); | ||||
|                 return custom_data.internal_window_object.cell(); | ||||
|             }, | ||||
|             nullptr)); | ||||
| 
 | ||||
|         vm->push_execution_context(*custom_data.root_execution_context); | ||||
|     } | ||||
|     return *vm; | ||||
| } | ||||
| 
 | ||||
| Bindings::WindowObject& main_thread_internal_window_object() | ||||
| HTML::Window& main_thread_internal_window_object() | ||||
| { | ||||
|     auto& vm = main_thread_vm(); | ||||
|     auto& custom_data = verify_cast<WebEngineCustomData>(*vm.custom_data()); | ||||
|  | @ -398,7 +396,7 @@ void queue_mutation_observer_microtask(DOM::Document& document) | |||
| } | ||||
| 
 | ||||
| // https://html.spec.whatwg.org/multipage/webappapis.html#creating-a-new-javascript-realm
 | ||||
| NonnullOwnPtr<JS::ExecutionContext> create_a_new_javascript_realm(JS::VM& vm, Function<JS::GlobalObject*(JS::Realm&)> create_global_object, Function<JS::GlobalObject*(JS::Realm&)> create_global_this_value) | ||||
| NonnullOwnPtr<JS::ExecutionContext> create_a_new_javascript_realm(JS::VM& vm, Function<JS::Object*(JS::Realm&)> create_global_object, Function<JS::Object*(JS::Realm&)> create_global_this_value) | ||||
| { | ||||
|     // 1. Perform InitializeHostDefinedRealm() with the provided customizations for creating the global object and the global this binding.
 | ||||
|     // 2. Let realm execution context be the running JavaScript execution context.
 | ||||
|  |  | |||
|  | @ -11,9 +11,9 @@ | |||
| #include <LibJS/Forward.h> | ||||
| #include <LibJS/Runtime/JobCallback.h> | ||||
| #include <LibJS/Runtime/VM.h> | ||||
| #include <LibWeb/Bindings/WindowObject.h> | ||||
| #include <LibWeb/DOM/MutationObserver.h> | ||||
| #include <LibWeb/HTML/EventLoop/EventLoop.h> | ||||
| #include <LibWeb/HTML/Window.h> | ||||
| 
 | ||||
| namespace Web::Bindings { | ||||
| 
 | ||||
|  | @ -35,7 +35,7 @@ struct WebEngineCustomData final : public JS::VM::CustomData { | |||
| 
 | ||||
|     // This object is used as the global object for GC-allocated objects that don't
 | ||||
|     // belong to a web-facing global object.
 | ||||
|     JS::Handle<Bindings::WindowObject> internal_window_object; | ||||
|     JS::Handle<HTML::Window> internal_window_object; | ||||
| }; | ||||
| 
 | ||||
| struct WebEngineCustomJobCallbackData final : public JS::JobCallback::CustomData { | ||||
|  | @ -53,8 +53,8 @@ struct WebEngineCustomJobCallbackData final : public JS::JobCallback::CustomData | |||
| 
 | ||||
| HTML::ClassicScript* active_script(); | ||||
| JS::VM& main_thread_vm(); | ||||
| Bindings::WindowObject& main_thread_internal_window_object(); | ||||
| HTML::Window& main_thread_internal_window_object(); | ||||
| void queue_mutation_observer_microtask(DOM::Document&); | ||||
| NonnullOwnPtr<JS::ExecutionContext> create_a_new_javascript_realm(JS::VM&, Function<JS::GlobalObject*(JS::Realm&)> create_global_object, Function<JS::GlobalObject*(JS::Realm&)> create_global_this_value); | ||||
| NonnullOwnPtr<JS::ExecutionContext> create_a_new_javascript_realm(JS::VM&, Function<JS::Object*(JS::Realm&)> create_global_object, Function<JS::Object*(JS::Realm&)> create_global_this_value); | ||||
| 
 | ||||
| } | ||||
|  |  | |||
|  | @ -7,7 +7,7 @@ | |||
| #include <LibJS/Runtime/GlobalObject.h> | ||||
| #include <LibWeb/Bindings/NavigatorConstructor.h> | ||||
| #include <LibWeb/Bindings/NavigatorPrototype.h> | ||||
| #include <LibWeb/Bindings/WindowObject.h> | ||||
| #include <LibWeb/HTML/Window.h> | ||||
| 
 | ||||
| namespace Web::Bindings { | ||||
| 
 | ||||
|  | @ -31,7 +31,7 @@ JS::ThrowCompletionOr<JS::Object*> NavigatorConstructor::construct(FunctionObjec | |||
| void NavigatorConstructor::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<NavigatorPrototype>("Navigator"), 0); | ||||
|  |  | |||
|  | @ -14,7 +14,7 @@ namespace Web { | |||
| namespace Bindings { | ||||
| 
 | ||||
| NavigatorObject::NavigatorObject(JS::Realm& realm) | ||||
|     : Object(static_cast<WindowObject&>(realm.global_object()).ensure_web_prototype<NavigatorPrototype>("Navigator")) | ||||
|     : Object(verify_cast<HTML::Window>(realm.global_object()).ensure_web_prototype<NavigatorPrototype>("Navigator")) | ||||
| { | ||||
| } | ||||
| 
 | ||||
|  |  | |||
|  | @ -9,8 +9,8 @@ | |||
| #include <LibJS/Runtime/GlobalObject.h> | ||||
| #include <LibJS/Runtime/Object.h> | ||||
| #include <LibJS/Runtime/VM.h> | ||||
| #include <LibWeb/Bindings/WindowObject.h> | ||||
| #include <LibWeb/Forward.h> | ||||
| #include <LibWeb/HTML/Window.h> | ||||
| 
 | ||||
| namespace Web::Bindings { | ||||
| 
 | ||||
|  |  | |||
|  | @ -1,360 +0,0 @@ | |||
| /*
 | ||||
|  * Copyright (c) 2020, Andreas Kling <kling@serenityos.org> | ||||
|  * Copyright (c) 2020, Luke Wilde <lukew@serenityos.org> | ||||
|  * | ||||
|  * SPDX-License-Identifier: BSD-2-Clause | ||||
|  */ | ||||
| 
 | ||||
| #include <LibWeb/Bindings/AttributeWrapper.h> | ||||
| #include <LibWeb/Bindings/CharacterDataWrapper.h> | ||||
| #include <LibWeb/Bindings/CommentWrapper.h> | ||||
| #include <LibWeb/Bindings/DocumentFragmentWrapper.h> | ||||
| #include <LibWeb/Bindings/DocumentTypeWrapper.h> | ||||
| #include <LibWeb/Bindings/DocumentWrapper.h> | ||||
| #include <LibWeb/Bindings/HTMLAnchorElementWrapper.h> | ||||
| #include <LibWeb/Bindings/HTMLAreaElementWrapper.h> | ||||
| #include <LibWeb/Bindings/HTMLAudioElementWrapper.h> | ||||
| #include <LibWeb/Bindings/HTMLBRElementWrapper.h> | ||||
| #include <LibWeb/Bindings/HTMLBaseElementWrapper.h> | ||||
| #include <LibWeb/Bindings/HTMLBodyElementWrapper.h> | ||||
| #include <LibWeb/Bindings/HTMLButtonElementWrapper.h> | ||||
| #include <LibWeb/Bindings/HTMLCanvasElementWrapper.h> | ||||
| #include <LibWeb/Bindings/HTMLDListElementWrapper.h> | ||||
| #include <LibWeb/Bindings/HTMLDataElementWrapper.h> | ||||
| #include <LibWeb/Bindings/HTMLDataListElementWrapper.h> | ||||
| #include <LibWeb/Bindings/HTMLDetailsElementWrapper.h> | ||||
| #include <LibWeb/Bindings/HTMLDialogElementWrapper.h> | ||||
| #include <LibWeb/Bindings/HTMLDirectoryElementWrapper.h> | ||||
| #include <LibWeb/Bindings/HTMLDivElementWrapper.h> | ||||
| #include <LibWeb/Bindings/HTMLElementWrapper.h> | ||||
| #include <LibWeb/Bindings/HTMLEmbedElementWrapper.h> | ||||
| #include <LibWeb/Bindings/HTMLFieldSetElementWrapper.h> | ||||
| #include <LibWeb/Bindings/HTMLFontElementWrapper.h> | ||||
| #include <LibWeb/Bindings/HTMLFormElementWrapper.h> | ||||
| #include <LibWeb/Bindings/HTMLFrameElementWrapper.h> | ||||
| #include <LibWeb/Bindings/HTMLFrameSetElementWrapper.h> | ||||
| #include <LibWeb/Bindings/HTMLHRElementWrapper.h> | ||||
| #include <LibWeb/Bindings/HTMLHeadElementWrapper.h> | ||||
| #include <LibWeb/Bindings/HTMLHeadingElementWrapper.h> | ||||
| #include <LibWeb/Bindings/HTMLHtmlElementWrapper.h> | ||||
| #include <LibWeb/Bindings/HTMLIFrameElementWrapper.h> | ||||
| #include <LibWeb/Bindings/HTMLImageElementWrapper.h> | ||||
| #include <LibWeb/Bindings/HTMLInputElementWrapper.h> | ||||
| #include <LibWeb/Bindings/HTMLLIElementWrapper.h> | ||||
| #include <LibWeb/Bindings/HTMLLabelElementWrapper.h> | ||||
| #include <LibWeb/Bindings/HTMLLegendElementWrapper.h> | ||||
| #include <LibWeb/Bindings/HTMLLinkElementWrapper.h> | ||||
| #include <LibWeb/Bindings/HTMLMapElementWrapper.h> | ||||
| #include <LibWeb/Bindings/HTMLMarqueeElementWrapper.h> | ||||
| #include <LibWeb/Bindings/HTMLMenuElementWrapper.h> | ||||
| #include <LibWeb/Bindings/HTMLMetaElementWrapper.h> | ||||
| #include <LibWeb/Bindings/HTMLMeterElementWrapper.h> | ||||
| #include <LibWeb/Bindings/HTMLModElementWrapper.h> | ||||
| #include <LibWeb/Bindings/HTMLOListElementWrapper.h> | ||||
| #include <LibWeb/Bindings/HTMLObjectElementWrapper.h> | ||||
| #include <LibWeb/Bindings/HTMLOptGroupElementWrapper.h> | ||||
| #include <LibWeb/Bindings/HTMLOptionElementWrapper.h> | ||||
| #include <LibWeb/Bindings/HTMLOutputElementWrapper.h> | ||||
| #include <LibWeb/Bindings/HTMLParagraphElementWrapper.h> | ||||
| #include <LibWeb/Bindings/HTMLParamElementWrapper.h> | ||||
| #include <LibWeb/Bindings/HTMLPictureElementWrapper.h> | ||||
| #include <LibWeb/Bindings/HTMLPreElementWrapper.h> | ||||
| #include <LibWeb/Bindings/HTMLProgressElementWrapper.h> | ||||
| #include <LibWeb/Bindings/HTMLQuoteElementWrapper.h> | ||||
| #include <LibWeb/Bindings/HTMLScriptElementWrapper.h> | ||||
| #include <LibWeb/Bindings/HTMLSelectElementWrapper.h> | ||||
| #include <LibWeb/Bindings/HTMLSlotElementWrapper.h> | ||||
| #include <LibWeb/Bindings/HTMLSourceElementWrapper.h> | ||||
| #include <LibWeb/Bindings/HTMLSpanElementWrapper.h> | ||||
| #include <LibWeb/Bindings/HTMLStyleElementWrapper.h> | ||||
| #include <LibWeb/Bindings/HTMLTableCaptionElementWrapper.h> | ||||
| #include <LibWeb/Bindings/HTMLTableCellElementWrapper.h> | ||||
| #include <LibWeb/Bindings/HTMLTableColElementWrapper.h> | ||||
| #include <LibWeb/Bindings/HTMLTableElementWrapper.h> | ||||
| #include <LibWeb/Bindings/HTMLTableRowElementWrapper.h> | ||||
| #include <LibWeb/Bindings/HTMLTableSectionElementWrapper.h> | ||||
| #include <LibWeb/Bindings/HTMLTemplateElementWrapper.h> | ||||
| #include <LibWeb/Bindings/HTMLTextAreaElementWrapper.h> | ||||
| #include <LibWeb/Bindings/HTMLTimeElementWrapper.h> | ||||
| #include <LibWeb/Bindings/HTMLTitleElementWrapper.h> | ||||
| #include <LibWeb/Bindings/HTMLTrackElementWrapper.h> | ||||
| #include <LibWeb/Bindings/HTMLUListElementWrapper.h> | ||||
| #include <LibWeb/Bindings/HTMLUnknownElementWrapper.h> | ||||
| #include <LibWeb/Bindings/HTMLVideoElementWrapper.h> | ||||
| #include <LibWeb/Bindings/NodeWrapper.h> | ||||
| #include <LibWeb/Bindings/NodeWrapperFactory.h> | ||||
| #include <LibWeb/Bindings/SVGCircleElementWrapper.h> | ||||
| #include <LibWeb/Bindings/SVGEllipseElementWrapper.h> | ||||
| #include <LibWeb/Bindings/SVGLineElementWrapper.h> | ||||
| #include <LibWeb/Bindings/SVGPathElementWrapper.h> | ||||
| #include <LibWeb/Bindings/SVGPolygonElementWrapper.h> | ||||
| #include <LibWeb/Bindings/SVGPolylineElementWrapper.h> | ||||
| #include <LibWeb/Bindings/SVGRectElementWrapper.h> | ||||
| #include <LibWeb/Bindings/SVGSVGElementWrapper.h> | ||||
| #include <LibWeb/Bindings/SVGTextContentElementWrapper.h> | ||||
| #include <LibWeb/Bindings/TextWrapper.h> | ||||
| #include <LibWeb/DOM/Document.h> | ||||
| #include <LibWeb/DOM/Node.h> | ||||
| #include <LibWeb/HTML/HTMLAnchorElement.h> | ||||
| #include <LibWeb/HTML/HTMLAreaElement.h> | ||||
| #include <LibWeb/HTML/HTMLAudioElement.h> | ||||
| #include <LibWeb/HTML/HTMLBRElement.h> | ||||
| #include <LibWeb/HTML/HTMLBaseElement.h> | ||||
| #include <LibWeb/HTML/HTMLBodyElement.h> | ||||
| #include <LibWeb/HTML/HTMLButtonElement.h> | ||||
| #include <LibWeb/HTML/HTMLCanvasElement.h> | ||||
| #include <LibWeb/HTML/HTMLDListElement.h> | ||||
| #include <LibWeb/HTML/HTMLDataElement.h> | ||||
| #include <LibWeb/HTML/HTMLDataListElement.h> | ||||
| #include <LibWeb/HTML/HTMLDetailsElement.h> | ||||
| #include <LibWeb/HTML/HTMLDialogElement.h> | ||||
| #include <LibWeb/HTML/HTMLDirectoryElement.h> | ||||
| #include <LibWeb/HTML/HTMLDivElement.h> | ||||
| #include <LibWeb/HTML/HTMLEmbedElement.h> | ||||
| #include <LibWeb/HTML/HTMLFieldSetElement.h> | ||||
| #include <LibWeb/HTML/HTMLFontElement.h> | ||||
| #include <LibWeb/HTML/HTMLFormElement.h> | ||||
| #include <LibWeb/HTML/HTMLFrameElement.h> | ||||
| #include <LibWeb/HTML/HTMLFrameSetElement.h> | ||||
| #include <LibWeb/HTML/HTMLHRElement.h> | ||||
| #include <LibWeb/HTML/HTMLHeadElement.h> | ||||
| #include <LibWeb/HTML/HTMLHeadingElement.h> | ||||
| #include <LibWeb/HTML/HTMLHtmlElement.h> | ||||
| #include <LibWeb/HTML/HTMLIFrameElement.h> | ||||
| #include <LibWeb/HTML/HTMLImageElement.h> | ||||
| #include <LibWeb/HTML/HTMLInputElement.h> | ||||
| #include <LibWeb/HTML/HTMLLIElement.h> | ||||
| #include <LibWeb/HTML/HTMLLabelElement.h> | ||||
| #include <LibWeb/HTML/HTMLLegendElement.h> | ||||
| #include <LibWeb/HTML/HTMLLinkElement.h> | ||||
| #include <LibWeb/HTML/HTMLMapElement.h> | ||||
| #include <LibWeb/HTML/HTMLMarqueeElement.h> | ||||
| #include <LibWeb/HTML/HTMLMenuElement.h> | ||||
| #include <LibWeb/HTML/HTMLMetaElement.h> | ||||
| #include <LibWeb/HTML/HTMLMeterElement.h> | ||||
| #include <LibWeb/HTML/HTMLModElement.h> | ||||
| #include <LibWeb/HTML/HTMLOListElement.h> | ||||
| #include <LibWeb/HTML/HTMLObjectElement.h> | ||||
| #include <LibWeb/HTML/HTMLOptGroupElement.h> | ||||
| #include <LibWeb/HTML/HTMLOptionElement.h> | ||||
| #include <LibWeb/HTML/HTMLOutputElement.h> | ||||
| #include <LibWeb/HTML/HTMLParagraphElement.h> | ||||
| #include <LibWeb/HTML/HTMLParamElement.h> | ||||
| #include <LibWeb/HTML/HTMLPictureElement.h> | ||||
| #include <LibWeb/HTML/HTMLPreElement.h> | ||||
| #include <LibWeb/HTML/HTMLProgressElement.h> | ||||
| #include <LibWeb/HTML/HTMLQuoteElement.h> | ||||
| #include <LibWeb/HTML/HTMLScriptElement.h> | ||||
| #include <LibWeb/HTML/HTMLSelectElement.h> | ||||
| #include <LibWeb/HTML/HTMLSlotElement.h> | ||||
| #include <LibWeb/HTML/HTMLSourceElement.h> | ||||
| #include <LibWeb/HTML/HTMLSpanElement.h> | ||||
| #include <LibWeb/HTML/HTMLStyleElement.h> | ||||
| #include <LibWeb/HTML/HTMLTableCaptionElement.h> | ||||
| #include <LibWeb/HTML/HTMLTableCellElement.h> | ||||
| #include <LibWeb/HTML/HTMLTableColElement.h> | ||||
| #include <LibWeb/HTML/HTMLTableElement.h> | ||||
| #include <LibWeb/HTML/HTMLTableRowElement.h> | ||||
| #include <LibWeb/HTML/HTMLTableSectionElement.h> | ||||
| #include <LibWeb/HTML/HTMLTemplateElement.h> | ||||
| #include <LibWeb/HTML/HTMLTextAreaElement.h> | ||||
| #include <LibWeb/HTML/HTMLTimeElement.h> | ||||
| #include <LibWeb/HTML/HTMLTitleElement.h> | ||||
| #include <LibWeb/HTML/HTMLTrackElement.h> | ||||
| #include <LibWeb/HTML/HTMLUListElement.h> | ||||
| #include <LibWeb/HTML/HTMLUnknownElement.h> | ||||
| #include <LibWeb/HTML/HTMLVideoElement.h> | ||||
| #include <LibWeb/SVG/SVGCircleElement.h> | ||||
| #include <LibWeb/SVG/SVGEllipseElement.h> | ||||
| #include <LibWeb/SVG/SVGLineElement.h> | ||||
| #include <LibWeb/SVG/SVGPathElement.h> | ||||
| #include <LibWeb/SVG/SVGPolygonElement.h> | ||||
| #include <LibWeb/SVG/SVGPolylineElement.h> | ||||
| #include <LibWeb/SVG/SVGRectElement.h> | ||||
| #include <LibWeb/SVG/SVGSVGElement.h> | ||||
| 
 | ||||
| namespace Web::Bindings { | ||||
| 
 | ||||
| NodeWrapper* wrap(JS::Realm& realm, DOM::Node& node) | ||||
| { | ||||
|     if (node.wrapper()) | ||||
|         return static_cast<NodeWrapper*>(node.wrapper()); | ||||
| 
 | ||||
|     if (is<DOM::Document>(node)) | ||||
|         return static_cast<NodeWrapper*>(wrap_impl(realm, verify_cast<DOM::Document>(node))); | ||||
|     if (is<DOM::DocumentType>(node)) | ||||
|         return static_cast<NodeWrapper*>(wrap_impl(realm, verify_cast<DOM::DocumentType>(node))); | ||||
|     if (is<HTML::HTMLAnchorElement>(node)) | ||||
|         return static_cast<NodeWrapper*>(wrap_impl(realm, verify_cast<HTML::HTMLAnchorElement>(node))); | ||||
|     if (is<HTML::HTMLAreaElement>(node)) | ||||
|         return static_cast<NodeWrapper*>(wrap_impl(realm, verify_cast<HTML::HTMLAreaElement>(node))); | ||||
|     if (is<HTML::HTMLAudioElement>(node)) | ||||
|         return static_cast<NodeWrapper*>(wrap_impl(realm, verify_cast<HTML::HTMLAudioElement>(node))); | ||||
|     if (is<HTML::HTMLBaseElement>(node)) | ||||
|         return static_cast<NodeWrapper*>(wrap_impl(realm, verify_cast<HTML::HTMLBaseElement>(node))); | ||||
|     if (is<HTML::HTMLBodyElement>(node)) | ||||
|         return static_cast<NodeWrapper*>(wrap_impl(realm, verify_cast<HTML::HTMLBodyElement>(node))); | ||||
|     if (is<HTML::HTMLBRElement>(node)) | ||||
|         return static_cast<NodeWrapper*>(wrap_impl(realm, verify_cast<HTML::HTMLBRElement>(node))); | ||||
|     if (is<HTML::HTMLButtonElement>(node)) | ||||
|         return static_cast<NodeWrapper*>(wrap_impl(realm, verify_cast<HTML::HTMLButtonElement>(node))); | ||||
|     if (is<HTML::HTMLCanvasElement>(node)) | ||||
|         return static_cast<NodeWrapper*>(wrap_impl(realm, verify_cast<HTML::HTMLCanvasElement>(node))); | ||||
|     if (is<HTML::HTMLDataElement>(node)) | ||||
|         return static_cast<NodeWrapper*>(wrap_impl(realm, verify_cast<HTML::HTMLDataElement>(node))); | ||||
|     if (is<HTML::HTMLDataListElement>(node)) | ||||
|         return static_cast<NodeWrapper*>(wrap_impl(realm, verify_cast<HTML::HTMLDataListElement>(node))); | ||||
|     if (is<HTML::HTMLDetailsElement>(node)) | ||||
|         return static_cast<NodeWrapper*>(wrap_impl(realm, verify_cast<HTML::HTMLDetailsElement>(node))); | ||||
|     if (is<HTML::HTMLDialogElement>(node)) | ||||
|         return static_cast<NodeWrapper*>(wrap_impl(realm, verify_cast<HTML::HTMLDialogElement>(node))); | ||||
|     if (is<HTML::HTMLDirectoryElement>(node)) | ||||
|         return static_cast<NodeWrapper*>(wrap_impl(realm, verify_cast<HTML::HTMLDirectoryElement>(node))); | ||||
|     if (is<HTML::HTMLDivElement>(node)) | ||||
|         return static_cast<NodeWrapper*>(wrap_impl(realm, verify_cast<HTML::HTMLDivElement>(node))); | ||||
|     if (is<HTML::HTMLDListElement>(node)) | ||||
|         return static_cast<NodeWrapper*>(wrap_impl(realm, verify_cast<HTML::HTMLDListElement>(node))); | ||||
|     if (is<HTML::HTMLEmbedElement>(node)) | ||||
|         return static_cast<NodeWrapper*>(wrap_impl(realm, verify_cast<HTML::HTMLEmbedElement>(node))); | ||||
|     if (is<HTML::HTMLFieldSetElement>(node)) | ||||
|         return static_cast<NodeWrapper*>(wrap_impl(realm, verify_cast<HTML::HTMLFieldSetElement>(node))); | ||||
|     if (is<HTML::HTMLFontElement>(node)) | ||||
|         return static_cast<NodeWrapper*>(wrap_impl(realm, verify_cast<HTML::HTMLFontElement>(node))); | ||||
|     if (is<HTML::HTMLFormElement>(node)) | ||||
|         return static_cast<NodeWrapper*>(wrap_impl(realm, verify_cast<HTML::HTMLFormElement>(node))); | ||||
|     if (is<HTML::HTMLFrameElement>(node)) | ||||
|         return static_cast<NodeWrapper*>(wrap_impl(realm, verify_cast<HTML::HTMLFrameElement>(node))); | ||||
|     if (is<HTML::HTMLFrameSetElement>(node)) | ||||
|         return static_cast<NodeWrapper*>(wrap_impl(realm, verify_cast<HTML::HTMLFrameSetElement>(node))); | ||||
|     if (is<HTML::HTMLHeadElement>(node)) | ||||
|         return static_cast<NodeWrapper*>(wrap_impl(realm, verify_cast<HTML::HTMLHeadElement>(node))); | ||||
|     if (is<HTML::HTMLHeadingElement>(node)) | ||||
|         return static_cast<NodeWrapper*>(wrap_impl(realm, verify_cast<HTML::HTMLHeadingElement>(node))); | ||||
|     if (is<HTML::HTMLHRElement>(node)) | ||||
|         return static_cast<NodeWrapper*>(wrap_impl(realm, verify_cast<HTML::HTMLHRElement>(node))); | ||||
|     if (is<HTML::HTMLHtmlElement>(node)) | ||||
|         return static_cast<NodeWrapper*>(wrap_impl(realm, verify_cast<HTML::HTMLHtmlElement>(node))); | ||||
|     if (is<HTML::HTMLIFrameElement>(node)) | ||||
|         return static_cast<NodeWrapper*>(wrap_impl(realm, verify_cast<HTML::HTMLIFrameElement>(node))); | ||||
|     if (is<HTML::HTMLImageElement>(node)) | ||||
|         return static_cast<NodeWrapper*>(wrap_impl(realm, verify_cast<HTML::HTMLImageElement>(node))); | ||||
|     if (is<HTML::HTMLInputElement>(node)) | ||||
|         return static_cast<NodeWrapper*>(wrap_impl(realm, verify_cast<HTML::HTMLInputElement>(node))); | ||||
|     if (is<HTML::HTMLLabelElement>(node)) | ||||
|         return static_cast<NodeWrapper*>(wrap_impl(realm, verify_cast<HTML::HTMLLabelElement>(node))); | ||||
|     if (is<HTML::HTMLLegendElement>(node)) | ||||
|         return static_cast<NodeWrapper*>(wrap_impl(realm, verify_cast<HTML::HTMLLegendElement>(node))); | ||||
|     if (is<HTML::HTMLLIElement>(node)) | ||||
|         return static_cast<NodeWrapper*>(wrap_impl(realm, verify_cast<HTML::HTMLLIElement>(node))); | ||||
|     if (is<HTML::HTMLLinkElement>(node)) | ||||
|         return static_cast<NodeWrapper*>(wrap_impl(realm, verify_cast<HTML::HTMLLinkElement>(node))); | ||||
|     if (is<HTML::HTMLMapElement>(node)) | ||||
|         return static_cast<NodeWrapper*>(wrap_impl(realm, verify_cast<HTML::HTMLMapElement>(node))); | ||||
|     if (is<HTML::HTMLMarqueeElement>(node)) | ||||
|         return static_cast<NodeWrapper*>(wrap_impl(realm, verify_cast<HTML::HTMLMarqueeElement>(node))); | ||||
|     if (is<HTML::HTMLMenuElement>(node)) | ||||
|         return static_cast<NodeWrapper*>(wrap_impl(realm, verify_cast<HTML::HTMLMenuElement>(node))); | ||||
|     if (is<HTML::HTMLMetaElement>(node)) | ||||
|         return static_cast<NodeWrapper*>(wrap_impl(realm, verify_cast<HTML::HTMLMetaElement>(node))); | ||||
|     if (is<HTML::HTMLMeterElement>(node)) | ||||
|         return static_cast<NodeWrapper*>(wrap_impl(realm, verify_cast<HTML::HTMLMeterElement>(node))); | ||||
|     if (is<HTML::HTMLModElement>(node)) | ||||
|         return static_cast<NodeWrapper*>(wrap_impl(realm, verify_cast<HTML::HTMLModElement>(node))); | ||||
|     if (is<HTML::HTMLObjectElement>(node)) | ||||
|         return static_cast<NodeWrapper*>(wrap_impl(realm, verify_cast<HTML::HTMLObjectElement>(node))); | ||||
|     if (is<HTML::HTMLOListElement>(node)) | ||||
|         return static_cast<NodeWrapper*>(wrap_impl(realm, verify_cast<HTML::HTMLOListElement>(node))); | ||||
|     if (is<HTML::HTMLOptGroupElement>(node)) | ||||
|         return static_cast<NodeWrapper*>(wrap_impl(realm, verify_cast<HTML::HTMLOptGroupElement>(node))); | ||||
|     if (is<HTML::HTMLOptionElement>(node)) | ||||
|         return static_cast<NodeWrapper*>(wrap_impl(realm, verify_cast<HTML::HTMLOptionElement>(node))); | ||||
|     if (is<HTML::HTMLOutputElement>(node)) | ||||
|         return static_cast<NodeWrapper*>(wrap_impl(realm, verify_cast<HTML::HTMLOutputElement>(node))); | ||||
|     if (is<HTML::HTMLParagraphElement>(node)) | ||||
|         return static_cast<NodeWrapper*>(wrap_impl(realm, verify_cast<HTML::HTMLParagraphElement>(node))); | ||||
|     if (is<HTML::HTMLParamElement>(node)) | ||||
|         return static_cast<NodeWrapper*>(wrap_impl(realm, verify_cast<HTML::HTMLParamElement>(node))); | ||||
|     if (is<HTML::HTMLPictureElement>(node)) | ||||
|         return static_cast<NodeWrapper*>(wrap_impl(realm, verify_cast<HTML::HTMLPictureElement>(node))); | ||||
|     if (is<HTML::HTMLPreElement>(node)) | ||||
|         return static_cast<NodeWrapper*>(wrap_impl(realm, verify_cast<HTML::HTMLPreElement>(node))); | ||||
|     if (is<HTML::HTMLProgressElement>(node)) | ||||
|         return static_cast<NodeWrapper*>(wrap_impl(realm, verify_cast<HTML::HTMLProgressElement>(node))); | ||||
|     if (is<HTML::HTMLQuoteElement>(node)) | ||||
|         return static_cast<NodeWrapper*>(wrap_impl(realm, verify_cast<HTML::HTMLQuoteElement>(node))); | ||||
|     if (is<HTML::HTMLScriptElement>(node)) | ||||
|         return static_cast<NodeWrapper*>(wrap_impl(realm, verify_cast<HTML::HTMLScriptElement>(node))); | ||||
|     if (is<HTML::HTMLSelectElement>(node)) | ||||
|         return static_cast<NodeWrapper*>(wrap_impl(realm, verify_cast<HTML::HTMLSelectElement>(node))); | ||||
|     if (is<HTML::HTMLSlotElement>(node)) | ||||
|         return static_cast<NodeWrapper*>(wrap_impl(realm, verify_cast<HTML::HTMLSlotElement>(node))); | ||||
|     if (is<HTML::HTMLSourceElement>(node)) | ||||
|         return static_cast<NodeWrapper*>(wrap_impl(realm, verify_cast<HTML::HTMLSourceElement>(node))); | ||||
|     if (is<HTML::HTMLSpanElement>(node)) | ||||
|         return static_cast<NodeWrapper*>(wrap_impl(realm, verify_cast<HTML::HTMLSpanElement>(node))); | ||||
|     if (is<HTML::HTMLStyleElement>(node)) | ||||
|         return static_cast<NodeWrapper*>(wrap_impl(realm, verify_cast<HTML::HTMLStyleElement>(node))); | ||||
|     if (is<HTML::HTMLTableCaptionElement>(node)) | ||||
|         return static_cast<NodeWrapper*>(wrap_impl(realm, verify_cast<HTML::HTMLTableCaptionElement>(node))); | ||||
|     if (is<HTML::HTMLTableCellElement>(node)) | ||||
|         return static_cast<NodeWrapper*>(wrap_impl(realm, verify_cast<HTML::HTMLTableCellElement>(node))); | ||||
|     if (is<HTML::HTMLTableColElement>(node)) | ||||
|         return static_cast<NodeWrapper*>(wrap_impl(realm, verify_cast<HTML::HTMLTableColElement>(node))); | ||||
|     if (is<HTML::HTMLTableElement>(node)) | ||||
|         return static_cast<NodeWrapper*>(wrap_impl(realm, verify_cast<HTML::HTMLTableElement>(node))); | ||||
|     if (is<HTML::HTMLTableRowElement>(node)) | ||||
|         return static_cast<NodeWrapper*>(wrap_impl(realm, verify_cast<HTML::HTMLTableRowElement>(node))); | ||||
|     if (is<HTML::HTMLTableSectionElement>(node)) | ||||
|         return static_cast<NodeWrapper*>(wrap_impl(realm, verify_cast<HTML::HTMLTableSectionElement>(node))); | ||||
|     if (is<HTML::HTMLTemplateElement>(node)) | ||||
|         return static_cast<NodeWrapper*>(wrap_impl(realm, verify_cast<HTML::HTMLTemplateElement>(node))); | ||||
|     if (is<HTML::HTMLTextAreaElement>(node)) | ||||
|         return static_cast<NodeWrapper*>(wrap_impl(realm, verify_cast<HTML::HTMLTextAreaElement>(node))); | ||||
|     if (is<HTML::HTMLTimeElement>(node)) | ||||
|         return static_cast<NodeWrapper*>(wrap_impl(realm, verify_cast<HTML::HTMLTimeElement>(node))); | ||||
|     if (is<HTML::HTMLTitleElement>(node)) | ||||
|         return static_cast<NodeWrapper*>(wrap_impl(realm, verify_cast<HTML::HTMLTitleElement>(node))); | ||||
|     if (is<HTML::HTMLTrackElement>(node)) | ||||
|         return static_cast<NodeWrapper*>(wrap_impl(realm, verify_cast<HTML::HTMLTrackElement>(node))); | ||||
|     if (is<HTML::HTMLUListElement>(node)) | ||||
|         return static_cast<NodeWrapper*>(wrap_impl(realm, verify_cast<HTML::HTMLUListElement>(node))); | ||||
|     if (is<HTML::HTMLUnknownElement>(node)) | ||||
|         return static_cast<NodeWrapper*>(wrap_impl(realm, verify_cast<HTML::HTMLUnknownElement>(node))); | ||||
|     if (is<HTML::HTMLVideoElement>(node)) | ||||
|         return static_cast<NodeWrapper*>(wrap_impl(realm, verify_cast<HTML::HTMLVideoElement>(node))); | ||||
|     if (is<HTML::HTMLElement>(node)) | ||||
|         return static_cast<NodeWrapper*>(wrap_impl(realm, verify_cast<HTML::HTMLElement>(node))); | ||||
|     if (is<SVG::SVGSVGElement>(node)) | ||||
|         return static_cast<NodeWrapper*>(wrap_impl(realm, verify_cast<SVG::SVGSVGElement>(node))); | ||||
|     if (is<SVG::SVGCircleElement>(node)) | ||||
|         return static_cast<NodeWrapper*>(wrap_impl(realm, verify_cast<SVG::SVGCircleElement>(node))); | ||||
|     if (is<SVG::SVGEllipseElement>(node)) | ||||
|         return static_cast<NodeWrapper*>(wrap_impl(realm, verify_cast<SVG::SVGEllipseElement>(node))); | ||||
|     if (is<SVG::SVGLineElement>(node)) | ||||
|         return static_cast<NodeWrapper*>(wrap_impl(realm, verify_cast<SVG::SVGLineElement>(node))); | ||||
|     if (is<SVG::SVGPolygonElement>(node)) | ||||
|         return static_cast<NodeWrapper*>(wrap_impl(realm, verify_cast<SVG::SVGPolygonElement>(node))); | ||||
|     if (is<SVG::SVGPolylineElement>(node)) | ||||
|         return static_cast<NodeWrapper*>(wrap_impl(realm, verify_cast<SVG::SVGPolylineElement>(node))); | ||||
|     if (is<SVG::SVGPathElement>(node)) | ||||
|         return static_cast<NodeWrapper*>(wrap_impl(realm, verify_cast<SVG::SVGPathElement>(node))); | ||||
|     if (is<SVG::SVGRectElement>(node)) | ||||
|         return static_cast<NodeWrapper*>(wrap_impl(realm, verify_cast<SVG::SVGRectElement>(node))); | ||||
|     if (is<SVG::SVGTextContentElement>(node)) | ||||
|         return static_cast<NodeWrapper*>(wrap_impl(realm, verify_cast<SVG::SVGTextContentElement>(node))); | ||||
|     if (is<DOM::Element>(node)) | ||||
|         return static_cast<NodeWrapper*>(wrap_impl(realm, verify_cast<DOM::Element>(node))); | ||||
|     if (is<DOM::DocumentFragment>(node)) | ||||
|         return static_cast<NodeWrapper*>(wrap_impl(realm, verify_cast<DOM::DocumentFragment>(node))); | ||||
|     if (is<DOM::Comment>(node)) | ||||
|         return static_cast<NodeWrapper*>(wrap_impl(realm, verify_cast<DOM::Comment>(node))); | ||||
|     if (is<DOM::Text>(node)) | ||||
|         return static_cast<NodeWrapper*>(wrap_impl(realm, verify_cast<DOM::Text>(node))); | ||||
|     if (is<DOM::CharacterData>(node)) | ||||
|         return static_cast<NodeWrapper*>(wrap_impl(realm, verify_cast<DOM::CharacterData>(node))); | ||||
|     if (is<DOM::Attribute>(node)) | ||||
|         return static_cast<NodeWrapper*>(wrap_impl(realm, verify_cast<DOM::Attribute>(node))); | ||||
|     return static_cast<NodeWrapper*>(wrap_impl(realm, node)); | ||||
| } | ||||
| 
 | ||||
| } | ||||
|  | @ -1,18 +0,0 @@ | |||
| /*
 | ||||
|  * Copyright (c) 2020, Andreas Kling <kling@serenityos.org> | ||||
|  * | ||||
|  * SPDX-License-Identifier: BSD-2-Clause | ||||
|  */ | ||||
| 
 | ||||
| #pragma once | ||||
| 
 | ||||
| #include <LibJS/Forward.h> | ||||
| #include <LibWeb/Forward.h> | ||||
| 
 | ||||
| namespace Web { | ||||
| namespace Bindings { | ||||
| 
 | ||||
| NodeWrapper* wrap(JS::Realm&, DOM::Node&); | ||||
| 
 | ||||
| } | ||||
| } | ||||
|  | @ -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(); | ||||
| } | ||||
| 
 | ||||
| } | ||||
|  |  | |||
|  | @ -4,10 +4,18 @@ | |||
|  * SPDX-License-Identifier: BSD-2-Clause | ||||
|  */ | ||||
| 
 | ||||
| #include <AK/TypeCasts.h> | ||||
| #include <LibJS/Runtime/Realm.h> | ||||
| #include <LibWeb/Bindings/PlatformObject.h> | ||||
| #include <LibWeb/HTML/Window.h> | ||||
| 
 | ||||
| namespace Web::Bindings { | ||||
| 
 | ||||
| PlatformObject::PlatformObject(JS::Realm& realm) | ||||
|     : JS::Object(realm, nullptr) | ||||
| { | ||||
| } | ||||
| 
 | ||||
| PlatformObject::PlatformObject(JS::Object& prototype) | ||||
|     : JS::Object(prototype) | ||||
| { | ||||
|  | @ -15,4 +23,14 @@ PlatformObject::PlatformObject(JS::Object& prototype) | |||
| 
 | ||||
| PlatformObject::~PlatformObject() = default; | ||||
| 
 | ||||
| JS::Realm& PlatformObject::realm() const | ||||
| { | ||||
|     return shape().realm(); | ||||
| } | ||||
| 
 | ||||
| HTML::Window& PlatformObject::global_object() const | ||||
| { | ||||
|     return verify_cast<HTML::Window>(realm().global_object()); | ||||
| } | ||||
| 
 | ||||
| } | ||||
|  |  | |||
|  | @ -6,19 +6,49 @@ | |||
| 
 | ||||
| #pragma once | ||||
| 
 | ||||
| #include <AK/Weakable.h> | ||||
| #include <LibJS/Heap/GCPtr.h> | ||||
| #include <LibJS/Runtime/Object.h> | ||||
| #include <LibWeb/Forward.h> | ||||
| 
 | ||||
| namespace Web::Bindings { | ||||
| 
 | ||||
| #define WEB_PLATFORM_OBJECT(class_, base_class) \ | ||||
|     JS_OBJECT(class_, base_class)               \ | ||||
|     auto& impl()                                \ | ||||
|     {                                           \ | ||||
|         return *this;                           \ | ||||
|     }                                           \ | ||||
|     auto const& impl() const                    \ | ||||
|     {                                           \ | ||||
|         return *this;                           \ | ||||
|     } | ||||
| 
 | ||||
| #define WRAPPER_HACK(class_, namespace_)                            \ | ||||
|     namespace Web::Bindings {                                       \ | ||||
|     inline JS::Object* wrap(JS::Realm&, namespace_::class_& object) \ | ||||
|     {                                                               \ | ||||
|         return &object;                                             \ | ||||
|     }                                                               \ | ||||
|     using class_##Wrapper = namespace_::class_;                     \ | ||||
|     } | ||||
| 
 | ||||
| // https://webidl.spec.whatwg.org/#dfn-platform-object
 | ||||
| class PlatformObject : public JS::Object { | ||||
| class PlatformObject | ||||
|     : public JS::Object | ||||
|     , public Weakable<PlatformObject> { | ||||
|     JS_OBJECT(PlatformObject, JS::Object); | ||||
| 
 | ||||
| public: | ||||
|     virtual ~PlatformObject() override; | ||||
| 
 | ||||
|     JS::Realm& realm() const; | ||||
| 
 | ||||
|     // FIXME: This should return a type that works in both window and worker contexts.
 | ||||
|     HTML::Window& global_object() const; | ||||
| 
 | ||||
| protected: | ||||
|     PlatformObject(JS::Realm&); | ||||
|     explicit PlatformObject(JS::Object& prototype); | ||||
| }; | ||||
| 
 | ||||
|  |  | |||
|  | @ -6,8 +6,8 @@ | |||
| 
 | ||||
| #include <LibJS/Runtime/GlobalObject.h> | ||||
| #include <LibWeb/Bindings/WindowConstructor.h> | ||||
| #include <LibWeb/Bindings/WindowObject.h> | ||||
| #include <LibWeb/Bindings/WindowPrototype.h> | ||||
| #include <LibWeb/HTML/Window.h> | ||||
| 
 | ||||
| namespace Web::Bindings { | ||||
| 
 | ||||
|  | @ -31,7 +31,7 @@ JS::ThrowCompletionOr<JS::Object*> WindowConstructor::construct(FunctionObject&) | |||
| void WindowConstructor::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<WindowPrototype>("Window"), 0); | ||||
|  |  | |||
|  | @ -1,774 +0,0 @@ | |||
| /*
 | ||||
|  * Copyright (c) 2020-2022, Andreas Kling <kling@serenityos.org> | ||||
|  * Copyright (c) 2021, Sam Atkins <atkinssj@serenityos.org> | ||||
|  * | ||||
|  * SPDX-License-Identifier: BSD-2-Clause | ||||
|  */ | ||||
| 
 | ||||
| #include <AK/Base64.h> | ||||
| #include <AK/String.h> | ||||
| #include <AK/Utf8View.h> | ||||
| #include <LibJS/Runtime/Completion.h> | ||||
| #include <LibJS/Runtime/Error.h> | ||||
| #include <LibJS/Runtime/FunctionObject.h> | ||||
| #include <LibJS/Runtime/Shape.h> | ||||
| #include <LibTextCodec/Decoder.h> | ||||
| #include <LibWeb/Bindings/CSSNamespace.h> | ||||
| #include <LibWeb/Bindings/CryptoWrapper.h> | ||||
| #include <LibWeb/Bindings/DocumentWrapper.h> | ||||
| #include <LibWeb/Bindings/ElementWrapper.h> | ||||
| #include <LibWeb/Bindings/EventTargetConstructor.h> | ||||
| #include <LibWeb/Bindings/EventTargetPrototype.h> | ||||
| #include <LibWeb/Bindings/ExceptionOrUtils.h> | ||||
| #include <LibWeb/Bindings/HistoryWrapper.h> | ||||
| #include <LibWeb/Bindings/LocationObject.h> | ||||
| #include <LibWeb/Bindings/MediaQueryListWrapper.h> | ||||
| #include <LibWeb/Bindings/NavigatorObject.h> | ||||
| #include <LibWeb/Bindings/NodeWrapperFactory.h> | ||||
| #include <LibWeb/Bindings/PerformanceWrapper.h> | ||||
| #include <LibWeb/Bindings/Replaceable.h> | ||||
| #include <LibWeb/Bindings/ScreenWrapper.h> | ||||
| #include <LibWeb/Bindings/SelectionWrapper.h> | ||||
| #include <LibWeb/Bindings/StorageWrapper.h> | ||||
| #include <LibWeb/Bindings/WindowObject.h> | ||||
| #include <LibWeb/Bindings/WindowObjectHelper.h> | ||||
| #include <LibWeb/Bindings/WindowPrototype.h> | ||||
| #include <LibWeb/Crypto/Crypto.h> | ||||
| #include <LibWeb/DOM/Document.h> | ||||
| #include <LibWeb/DOM/Event.h> | ||||
| #include <LibWeb/HTML/BrowsingContext.h> | ||||
| #include <LibWeb/HTML/EventHandler.h> | ||||
| #include <LibWeb/HTML/Origin.h> | ||||
| #include <LibWeb/HTML/Scripting/Environments.h> | ||||
| #include <LibWeb/HTML/Storage.h> | ||||
| #include <LibWeb/HTML/Window.h> | ||||
| #include <LibWeb/Page/Page.h> | ||||
| #include <LibWeb/WebAssembly/WebAssemblyObject.h> | ||||
| 
 | ||||
| namespace Web::Bindings { | ||||
| 
 | ||||
| WindowObject::WindowObject(JS::Realm& realm, HTML::Window& impl) | ||||
|     : GlobalObject(realm) | ||||
|     , m_impl(impl) | ||||
| { | ||||
|     impl.set_wrapper({}, *this); | ||||
| } | ||||
| 
 | ||||
| void WindowObject::initialize(JS::Realm& realm) | ||||
| { | ||||
|     Base::initialize(realm); | ||||
| 
 | ||||
|     Object::set_prototype(&ensure_web_prototype<WindowPrototype>("Window")); | ||||
| 
 | ||||
|     // FIXME: These should be native accessors, not properties
 | ||||
|     define_direct_property("window", this, JS::Attribute::Enumerable); | ||||
|     define_direct_property("frames", this, JS::Attribute::Enumerable); | ||||
|     define_direct_property("self", this, JS::Attribute::Enumerable); | ||||
|     define_native_accessor(realm, "top", top_getter, nullptr, JS::Attribute::Enumerable); | ||||
|     define_native_accessor(realm, "parent", parent_getter, {}, JS::Attribute::Enumerable); | ||||
|     define_native_accessor(realm, "document", document_getter, {}, JS::Attribute::Enumerable); | ||||
|     define_native_accessor(realm, "name", name_getter, name_setter, JS::Attribute::Enumerable); | ||||
|     define_native_accessor(realm, "history", history_getter, {}, JS::Attribute::Enumerable); | ||||
|     define_native_accessor(realm, "performance", performance_getter, performance_setter, JS::Attribute::Enumerable | JS::Attribute::Configurable); | ||||
|     define_native_accessor(realm, "crypto", crypto_getter, {}, JS::Attribute::Enumerable); | ||||
|     define_native_accessor(realm, "screen", screen_getter, {}, JS::Attribute::Enumerable); | ||||
|     define_native_accessor(realm, "innerWidth", inner_width_getter, {}, JS::Attribute::Enumerable); | ||||
|     define_native_accessor(realm, "innerHeight", inner_height_getter, {}, JS::Attribute::Enumerable); | ||||
|     define_native_accessor(realm, "devicePixelRatio", device_pixel_ratio_getter, {}, JS::Attribute::Enumerable | JS::Attribute::Configurable); | ||||
|     u8 attr = JS::Attribute::Writable | JS::Attribute::Enumerable | JS::Attribute::Configurable; | ||||
|     define_native_function(realm, "alert", alert, 0, attr); | ||||
|     define_native_function(realm, "confirm", confirm, 0, attr); | ||||
|     define_native_function(realm, "prompt", prompt, 0, attr); | ||||
|     define_native_function(realm, "setInterval", set_interval, 1, attr); | ||||
|     define_native_function(realm, "setTimeout", set_timeout, 1, attr); | ||||
|     define_native_function(realm, "clearInterval", clear_interval, 1, attr); | ||||
|     define_native_function(realm, "clearTimeout", clear_timeout, 1, attr); | ||||
|     define_native_function(realm, "requestAnimationFrame", request_animation_frame, 1, attr); | ||||
|     define_native_function(realm, "cancelAnimationFrame", cancel_animation_frame, 1, attr); | ||||
|     define_native_function(realm, "atob", atob, 1, attr); | ||||
|     define_native_function(realm, "btoa", btoa, 1, attr); | ||||
| 
 | ||||
|     define_native_function(realm, "queueMicrotask", queue_microtask, 1, attr); | ||||
| 
 | ||||
|     define_native_function(realm, "requestIdleCallback", request_idle_callback, 1, attr); | ||||
|     define_native_function(realm, "cancelIdleCallback", cancel_idle_callback, 1, attr); | ||||
| 
 | ||||
|     define_native_function(realm, "getComputedStyle", get_computed_style, 1, attr); | ||||
|     define_native_function(realm, "matchMedia", match_media, 1, attr); | ||||
|     define_native_function(realm, "getSelection", get_selection, 0, attr); | ||||
| 
 | ||||
|     define_native_function(realm, "postMessage", post_message, 1, attr); | ||||
| 
 | ||||
|     // FIXME: These properties should be [Replaceable] according to the spec, but [Writable+Configurable] is the closest we have.
 | ||||
|     define_native_accessor(realm, "scrollX", scroll_x_getter, {}, attr); | ||||
|     define_native_accessor(realm, "pageXOffset", scroll_x_getter, {}, attr); | ||||
|     define_native_accessor(realm, "scrollY", scroll_y_getter, {}, attr); | ||||
|     define_native_accessor(realm, "pageYOffset", scroll_y_getter, {}, attr); | ||||
| 
 | ||||
|     define_native_function(realm, "scroll", scroll, 2, attr); | ||||
|     define_native_function(realm, "scrollTo", scroll, 2, attr); | ||||
|     define_native_function(realm, "scrollBy", scroll_by, 2, attr); | ||||
| 
 | ||||
|     define_native_accessor(realm, "screenX", screen_x_getter, {}, attr); | ||||
|     define_native_accessor(realm, "screenY", screen_y_getter, {}, attr); | ||||
|     define_native_accessor(realm, "screenLeft", screen_left_getter, {}, attr); | ||||
|     define_native_accessor(realm, "screenTop", screen_top_getter, {}, attr); | ||||
| 
 | ||||
|     define_direct_property("CSS", heap().allocate<CSSNamespace>(realm, realm), 0); | ||||
| 
 | ||||
|     define_native_accessor(realm, "localStorage", local_storage_getter, {}, attr); | ||||
|     define_native_accessor(realm, "sessionStorage", session_storage_getter, {}, attr); | ||||
|     define_native_accessor(realm, "origin", origin_getter, {}, attr); | ||||
| 
 | ||||
|     // Legacy
 | ||||
|     define_native_accessor(realm, "event", event_getter, event_setter, JS::Attribute::Enumerable); | ||||
| 
 | ||||
|     m_location_object = heap().allocate<LocationObject>(realm, realm); | ||||
| 
 | ||||
|     auto* m_navigator_object = heap().allocate<NavigatorObject>(realm, realm); | ||||
|     define_direct_property("navigator", m_navigator_object, JS::Attribute::Enumerable | JS::Attribute::Configurable); | ||||
|     define_direct_property("clientInformation", m_navigator_object, JS::Attribute::Enumerable | JS::Attribute::Configurable); | ||||
| 
 | ||||
|     // NOTE: location is marked as [LegacyUnforgeable], meaning it isn't configurable.
 | ||||
|     define_native_accessor(realm, "location", location_getter, location_setter, JS::Attribute::Enumerable); | ||||
| 
 | ||||
|     // WebAssembly "namespace"
 | ||||
|     define_direct_property("WebAssembly", heap().allocate<WebAssemblyObject>(realm, realm), JS::Attribute::Enumerable | JS::Attribute::Configurable); | ||||
| 
 | ||||
|     // HTML::GlobalEventHandlers and HTML::WindowEventHandlers
 | ||||
| #define __ENUMERATE(attribute, event_name) \ | ||||
|     define_native_accessor(realm, #attribute, attribute##_getter, attribute##_setter, attr); | ||||
|     ENUMERATE_GLOBAL_EVENT_HANDLERS(__ENUMERATE); | ||||
|     ENUMERATE_WINDOW_EVENT_HANDLERS(__ENUMERATE); | ||||
| #undef __ENUMERATE | ||||
| 
 | ||||
|     ADD_WINDOW_OBJECT_INTERFACES; | ||||
| } | ||||
| 
 | ||||
| void WindowObject::visit_edges(Visitor& visitor) | ||||
| { | ||||
|     GlobalObject::visit_edges(visitor); | ||||
|     visitor.visit(m_location_object); | ||||
|     for (auto& it : m_prototypes) | ||||
|         visitor.visit(it.value); | ||||
|     for (auto& it : m_constructors) | ||||
|         visitor.visit(it.value); | ||||
| } | ||||
| 
 | ||||
| HTML::Origin WindowObject::origin() const | ||||
| { | ||||
|     return impl().associated_document().origin(); | ||||
| } | ||||
| 
 | ||||
| // https://webidl.spec.whatwg.org/#platform-object-setprototypeof
 | ||||
| JS::ThrowCompletionOr<bool> WindowObject::internal_set_prototype_of(JS::Object* prototype) | ||||
| { | ||||
|     // 1. Return ? SetImmutablePrototype(O, V).
 | ||||
|     return set_immutable_prototype(prototype); | ||||
| } | ||||
| 
 | ||||
| static JS::ThrowCompletionOr<HTML::Window*> impl_from(JS::VM& vm) | ||||
| { | ||||
|     // Since this is a non built-in function we must treat it as non-strict mode
 | ||||
|     // this means that a nullish this_value should be converted to the
 | ||||
|     // global_object. Generally this does not matter as we try to convert the
 | ||||
|     // this_value to a specific object type in the bindings. But since window is
 | ||||
|     // the global object we make an exception here.
 | ||||
|     // This allows calls like `setTimeout(f, 10)` to work.
 | ||||
|     auto this_value = vm.this_value(); | ||||
|     if (this_value.is_nullish()) | ||||
|         this_value = &vm.current_realm()->global_object(); | ||||
| 
 | ||||
|     auto* this_object = MUST(this_value.to_object(vm)); | ||||
| 
 | ||||
|     if (!is<WindowObject>(*this_object)) | ||||
|         return vm.throw_completion<JS::TypeError>(JS::ErrorType::NotAnObjectOfType, "WindowObject"); | ||||
|     return &static_cast<WindowObject*>(this_object)->impl(); | ||||
| } | ||||
| 
 | ||||
| JS_DEFINE_NATIVE_FUNCTION(WindowObject::alert) | ||||
| { | ||||
|     // https://html.spec.whatwg.org/multipage/timers-and-user-prompts.html#simple-dialogs
 | ||||
|     // Note: This method is defined using two overloads, instead of using an optional argument,
 | ||||
|     //       for historical reasons. The practical impact of this is that alert(undefined) is
 | ||||
|     //       treated as alert("undefined"), but alert() is treated as alert("").
 | ||||
|     auto* impl = TRY(impl_from(vm)); | ||||
|     String message = ""; | ||||
|     if (vm.argument_count()) | ||||
|         message = TRY(vm.argument(0).to_string(vm)); | ||||
|     impl->alert(message); | ||||
|     return JS::js_undefined(); | ||||
| } | ||||
| 
 | ||||
| JS_DEFINE_NATIVE_FUNCTION(WindowObject::confirm) | ||||
| { | ||||
|     auto* impl = TRY(impl_from(vm)); | ||||
|     String message = ""; | ||||
|     if (!vm.argument(0).is_undefined()) | ||||
|         message = TRY(vm.argument(0).to_string(vm)); | ||||
|     return JS::Value(impl->confirm(message)); | ||||
| } | ||||
| 
 | ||||
| JS_DEFINE_NATIVE_FUNCTION(WindowObject::prompt) | ||||
| { | ||||
|     auto* impl = TRY(impl_from(vm)); | ||||
|     String message = ""; | ||||
|     String default_ = ""; | ||||
|     if (!vm.argument(0).is_undefined()) | ||||
|         message = TRY(vm.argument(0).to_string(vm)); | ||||
|     if (!vm.argument(1).is_undefined()) | ||||
|         default_ = TRY(vm.argument(1).to_string(vm)); | ||||
|     auto response = impl->prompt(message, default_); | ||||
|     if (response.is_null()) | ||||
|         return JS::js_null(); | ||||
|     return JS::js_string(vm, response); | ||||
| } | ||||
| 
 | ||||
| static JS::ThrowCompletionOr<TimerHandler> make_timer_handler(JS::VM& vm, JS::Value handler) | ||||
| { | ||||
|     if (handler.is_function()) | ||||
|         return JS::make_handle(vm.heap().allocate_without_realm<Bindings::CallbackType>(handler.as_function(), HTML::incumbent_settings_object())); | ||||
|     return TRY(handler.to_string(vm)); | ||||
| } | ||||
| 
 | ||||
| // https://html.spec.whatwg.org/multipage/timers-and-user-prompts.html#dom-settimeout
 | ||||
| JS_DEFINE_NATIVE_FUNCTION(WindowObject::set_timeout) | ||||
| { | ||||
|     auto* impl = TRY(impl_from(vm)); | ||||
| 
 | ||||
|     if (!vm.argument_count()) | ||||
|         return vm.throw_completion<JS::TypeError>(JS::ErrorType::BadArgCountAtLeastOne, "setTimeout"); | ||||
| 
 | ||||
|     auto handler = TRY(make_timer_handler(vm, vm.argument(0))); | ||||
| 
 | ||||
|     i32 timeout = 0; | ||||
|     if (vm.argument_count() >= 2) | ||||
|         timeout = TRY(vm.argument(1).to_i32(vm)); | ||||
| 
 | ||||
|     JS::MarkedVector<JS::Value> arguments { vm.heap() }; | ||||
|     for (size_t i = 2; i < vm.argument_count(); ++i) | ||||
|         arguments.append(vm.argument(i)); | ||||
| 
 | ||||
|     auto id = impl->set_timeout(move(handler), timeout, move(arguments)); | ||||
|     return JS::Value(id); | ||||
| } | ||||
| 
 | ||||
| // https://html.spec.whatwg.org/multipage/timers-and-user-prompts.html#dom-setinterval
 | ||||
| JS_DEFINE_NATIVE_FUNCTION(WindowObject::set_interval) | ||||
| { | ||||
|     auto* impl = TRY(impl_from(vm)); | ||||
| 
 | ||||
|     if (!vm.argument_count()) | ||||
|         return vm.throw_completion<JS::TypeError>(JS::ErrorType::BadArgCountAtLeastOne, "setInterval"); | ||||
| 
 | ||||
|     auto handler = TRY(make_timer_handler(vm, vm.argument(0))); | ||||
| 
 | ||||
|     i32 timeout = 0; | ||||
|     if (vm.argument_count() >= 2) | ||||
|         timeout = TRY(vm.argument(1).to_i32(vm)); | ||||
| 
 | ||||
|     JS::MarkedVector<JS::Value> arguments { vm.heap() }; | ||||
|     for (size_t i = 2; i < vm.argument_count(); ++i) | ||||
|         arguments.append(vm.argument(i)); | ||||
| 
 | ||||
|     auto id = impl->set_interval(move(handler), timeout, move(arguments)); | ||||
|     return JS::Value(id); | ||||
| } | ||||
| 
 | ||||
| // https://html.spec.whatwg.org/multipage/timers-and-user-prompts.html#dom-cleartimeout
 | ||||
| JS_DEFINE_NATIVE_FUNCTION(WindowObject::clear_timeout) | ||||
| { | ||||
|     auto* impl = TRY(impl_from(vm)); | ||||
| 
 | ||||
|     i32 id = 0; | ||||
|     if (vm.argument_count()) | ||||
|         id = TRY(vm.argument(0).to_i32(vm)); | ||||
| 
 | ||||
|     impl->clear_timeout(id); | ||||
|     return JS::js_undefined(); | ||||
| } | ||||
| 
 | ||||
| // https://html.spec.whatwg.org/multipage/timers-and-user-prompts.html#dom-clearinterval
 | ||||
| JS_DEFINE_NATIVE_FUNCTION(WindowObject::clear_interval) | ||||
| { | ||||
|     auto* impl = TRY(impl_from(vm)); | ||||
| 
 | ||||
|     i32 id = 0; | ||||
|     if (vm.argument_count()) | ||||
|         id = TRY(vm.argument(0).to_i32(vm)); | ||||
| 
 | ||||
|     impl->clear_interval(id); | ||||
|     return JS::js_undefined(); | ||||
| } | ||||
| 
 | ||||
| JS_DEFINE_NATIVE_FUNCTION(WindowObject::request_animation_frame) | ||||
| { | ||||
|     auto* impl = TRY(impl_from(vm)); | ||||
|     if (!vm.argument_count()) | ||||
|         return vm.throw_completion<JS::TypeError>(JS::ErrorType::BadArgCountOne, "requestAnimationFrame"); | ||||
|     auto* callback_object = TRY(vm.argument(0).to_object(vm)); | ||||
|     if (!callback_object->is_function()) | ||||
|         return vm.throw_completion<JS::TypeError>(JS::ErrorType::NotAFunctionNoParam); | ||||
|     auto* callback = vm.heap().allocate_without_realm<Bindings::CallbackType>(*callback_object, HTML::incumbent_settings_object()); | ||||
|     return JS::Value(impl->request_animation_frame(*callback)); | ||||
| } | ||||
| 
 | ||||
| JS_DEFINE_NATIVE_FUNCTION(WindowObject::cancel_animation_frame) | ||||
| { | ||||
|     auto* impl = TRY(impl_from(vm)); | ||||
|     if (!vm.argument_count()) | ||||
|         return vm.throw_completion<JS::TypeError>(JS::ErrorType::BadArgCountOne, "cancelAnimationFrame"); | ||||
|     auto id = TRY(vm.argument(0).to_i32(vm)); | ||||
|     impl->cancel_animation_frame(id); | ||||
|     return JS::js_undefined(); | ||||
| } | ||||
| 
 | ||||
| JS_DEFINE_NATIVE_FUNCTION(WindowObject::queue_microtask) | ||||
| { | ||||
|     auto* impl = TRY(impl_from(vm)); | ||||
|     if (!vm.argument_count()) | ||||
|         return vm.throw_completion<JS::TypeError>(JS::ErrorType::BadArgCountAtLeastOne, "queueMicrotask"); | ||||
|     auto* callback_object = TRY(vm.argument(0).to_object(vm)); | ||||
|     if (!callback_object->is_function()) | ||||
|         return vm.throw_completion<JS::TypeError>(JS::ErrorType::NotAFunctionNoParam); | ||||
| 
 | ||||
|     auto* callback = vm.heap().allocate_without_realm<Bindings::CallbackType>(*callback_object, HTML::incumbent_settings_object()); | ||||
| 
 | ||||
|     impl->queue_microtask(*callback); | ||||
|     return JS::js_undefined(); | ||||
| } | ||||
| 
 | ||||
| JS_DEFINE_NATIVE_FUNCTION(WindowObject::request_idle_callback) | ||||
| { | ||||
|     auto* impl = TRY(impl_from(vm)); | ||||
|     if (!vm.argument_count()) | ||||
|         return vm.throw_completion<JS::TypeError>(JS::ErrorType::BadArgCountAtLeastOne, "requestIdleCallback"); | ||||
|     auto* callback_object = TRY(vm.argument(0).to_object(vm)); | ||||
|     if (!callback_object->is_function()) | ||||
|         return vm.throw_completion<JS::TypeError>(JS::ErrorType::NotAFunctionNoParam); | ||||
|     // FIXME: accept options object
 | ||||
| 
 | ||||
|     auto* callback = vm.heap().allocate_without_realm<Bindings::CallbackType>(*callback_object, HTML::incumbent_settings_object()); | ||||
| 
 | ||||
|     return JS::Value(impl->request_idle_callback(*callback)); | ||||
| } | ||||
| 
 | ||||
| JS_DEFINE_NATIVE_FUNCTION(WindowObject::cancel_idle_callback) | ||||
| { | ||||
|     auto* impl = TRY(impl_from(vm)); | ||||
|     if (!vm.argument_count()) | ||||
|         return vm.throw_completion<JS::TypeError>(JS::ErrorType::BadArgCountOne, "cancelIdleCallback"); | ||||
|     auto id = TRY(vm.argument(0).to_u32(vm)); | ||||
|     impl->cancel_idle_callback(id); | ||||
|     return JS::js_undefined(); | ||||
| } | ||||
| 
 | ||||
| JS_DEFINE_NATIVE_FUNCTION(WindowObject::atob) | ||||
| { | ||||
|     if (!vm.argument_count()) | ||||
|         return vm.throw_completion<JS::TypeError>(JS::ErrorType::BadArgCountOne, "atob"); | ||||
|     auto string = TRY(vm.argument(0).to_string(vm)); | ||||
|     auto decoded = decode_base64(StringView(string)); | ||||
|     if (decoded.is_error()) | ||||
|         return vm.throw_completion<JS::TypeError>(JS::ErrorType::InvalidFormat, "Base64"); | ||||
| 
 | ||||
|     // decode_base64() returns a byte string. LibJS uses UTF-8 for strings. Use Latin1Decoder to convert bytes 128-255 to UTF-8.
 | ||||
|     auto decoder = TextCodec::decoder_for("windows-1252"); | ||||
|     VERIFY(decoder); | ||||
|     return JS::js_string(vm, decoder->to_utf8(decoded.value())); | ||||
| } | ||||
| 
 | ||||
| JS_DEFINE_NATIVE_FUNCTION(WindowObject::btoa) | ||||
| { | ||||
|     if (!vm.argument_count()) | ||||
|         return vm.throw_completion<JS::TypeError>(JS::ErrorType::BadArgCountOne, "btoa"); | ||||
|     auto string = TRY(vm.argument(0).to_string(vm)); | ||||
| 
 | ||||
|     Vector<u8> byte_string; | ||||
|     byte_string.ensure_capacity(string.length()); | ||||
|     for (u32 code_point : Utf8View(string)) { | ||||
|         if (code_point > 0xff) { | ||||
|             return Bindings::throw_dom_exception_if_needed(vm, [] { | ||||
|                 return DOM::InvalidCharacterError::create("Data contains characters outside the range U+0000 and U+00FF"); | ||||
|             }).release_error(); | ||||
|         } | ||||
|         byte_string.append(code_point); | ||||
|     } | ||||
| 
 | ||||
|     auto encoded = encode_base64(byte_string.span()); | ||||
|     return JS::js_string(vm, move(encoded)); | ||||
| } | ||||
| 
 | ||||
| // https://html.spec.whatwg.org/multipage/browsers.html#dom-top
 | ||||
| JS_DEFINE_NATIVE_FUNCTION(WindowObject::top_getter) | ||||
| { | ||||
|     auto* impl = TRY(impl_from(vm)); | ||||
| 
 | ||||
|     auto* this_browsing_context = impl->associated_document().browsing_context(); | ||||
|     if (!this_browsing_context) | ||||
|         return JS::js_null(); | ||||
| 
 | ||||
|     VERIFY(this_browsing_context->top_level_browsing_context().active_document()); | ||||
|     auto& top_window = this_browsing_context->top_level_browsing_context().active_document()->window(); | ||||
|     return top_window.wrapper(); | ||||
| } | ||||
| 
 | ||||
| JS_DEFINE_NATIVE_FUNCTION(WindowObject::parent_getter) | ||||
| { | ||||
|     auto* impl = TRY(impl_from(vm)); | ||||
|     auto* parent = impl->parent(); | ||||
|     if (!parent) | ||||
|         return JS::js_null(); | ||||
|     return parent->wrapper(); | ||||
| } | ||||
| 
 | ||||
| JS_DEFINE_NATIVE_FUNCTION(WindowObject::document_getter) | ||||
| { | ||||
|     auto& realm = *vm.current_realm(); | ||||
|     auto* impl = TRY(impl_from(vm)); | ||||
|     return wrap(realm, impl->associated_document()); | ||||
| } | ||||
| 
 | ||||
| JS_DEFINE_NATIVE_FUNCTION(WindowObject::performance_getter) | ||||
| { | ||||
|     auto& realm = *vm.current_realm(); | ||||
|     auto* impl = TRY(impl_from(vm)); | ||||
|     return wrap(realm, impl->performance()); | ||||
| } | ||||
| 
 | ||||
| JS_DEFINE_NATIVE_FUNCTION(WindowObject::performance_setter) | ||||
| { | ||||
|     // https://webidl.spec.whatwg.org/#dfn-attribute-setter
 | ||||
|     // 4.1. If no arguments were passed, then throw a TypeError.
 | ||||
|     if (vm.argument_count() == 0) | ||||
|         return vm.throw_completion<JS::TypeError>(JS::ErrorType::BadArgCountOne, "set performance"); | ||||
| 
 | ||||
|     auto* impl = TRY(impl_from(vm)); | ||||
| 
 | ||||
|     // 5. If attribute is declared with the [Replaceable] extended attribute, then:
 | ||||
|     // 1. Perform ? CreateDataProperty(esValue, id, V).
 | ||||
|     VERIFY(impl->wrapper()); | ||||
|     TRY(impl->wrapper()->create_data_property("performance", vm.argument(0))); | ||||
| 
 | ||||
|     // 2. Return undefined.
 | ||||
|     return JS::js_undefined(); | ||||
| } | ||||
| 
 | ||||
| JS_DEFINE_NATIVE_FUNCTION(WindowObject::screen_getter) | ||||
| { | ||||
|     auto& realm = *vm.current_realm(); | ||||
|     auto* impl = TRY(impl_from(vm)); | ||||
|     return wrap(realm, impl->screen()); | ||||
| } | ||||
| 
 | ||||
| JS_DEFINE_NATIVE_FUNCTION(WindowObject::event_getter) | ||||
| { | ||||
|     auto& realm = *vm.current_realm(); | ||||
|     auto* impl = TRY(impl_from(vm)); | ||||
|     if (!impl->current_event()) | ||||
|         return JS::js_undefined(); | ||||
|     return wrap(realm, const_cast<DOM::Event&>(*impl->current_event())); | ||||
| } | ||||
| 
 | ||||
| JS_DEFINE_NATIVE_FUNCTION(WindowObject::event_setter) | ||||
| { | ||||
|     REPLACEABLE_PROPERTY_SETTER(WindowObject, event); | ||||
| } | ||||
| 
 | ||||
| JS_DEFINE_NATIVE_FUNCTION(WindowObject::location_getter) | ||||
| { | ||||
|     auto* impl = TRY(impl_from(vm)); | ||||
|     VERIFY(impl->wrapper()); | ||||
|     return impl->wrapper()->m_location_object; | ||||
| } | ||||
| 
 | ||||
| JS_DEFINE_NATIVE_FUNCTION(WindowObject::location_setter) | ||||
| { | ||||
|     auto* impl = TRY(impl_from(vm)); | ||||
|     VERIFY(impl->wrapper()); | ||||
|     TRY(impl->wrapper()->m_location_object->set(JS::PropertyKey("href"), vm.argument(0), JS::Object::ShouldThrowExceptions::Yes)); | ||||
|     return JS::js_undefined(); | ||||
| } | ||||
| 
 | ||||
| JS_DEFINE_NATIVE_FUNCTION(WindowObject::crypto_getter) | ||||
| { | ||||
|     auto& realm = *vm.current_realm(); | ||||
|     auto* impl = TRY(impl_from(vm)); | ||||
|     return wrap(realm, impl->crypto()); | ||||
| } | ||||
| 
 | ||||
| JS_DEFINE_NATIVE_FUNCTION(WindowObject::inner_width_getter) | ||||
| { | ||||
|     auto* impl = TRY(impl_from(vm)); | ||||
|     return JS::Value(impl->inner_width()); | ||||
| } | ||||
| 
 | ||||
| JS_DEFINE_NATIVE_FUNCTION(WindowObject::inner_height_getter) | ||||
| { | ||||
|     auto* impl = TRY(impl_from(vm)); | ||||
|     return JS::Value(impl->inner_height()); | ||||
| } | ||||
| 
 | ||||
| JS_DEFINE_NATIVE_FUNCTION(WindowObject::device_pixel_ratio_getter) | ||||
| { | ||||
|     auto* impl = TRY(impl_from(vm)); | ||||
|     return JS::Value(impl->device_pixel_ratio()); | ||||
| } | ||||
| 
 | ||||
| JS_DEFINE_NATIVE_FUNCTION(WindowObject::get_computed_style) | ||||
| { | ||||
|     auto& realm = *vm.current_realm(); | ||||
|     auto* impl = TRY(impl_from(vm)); | ||||
|     auto* object = TRY(vm.argument(0).to_object(vm)); | ||||
|     if (!is<ElementWrapper>(object)) | ||||
|         return vm.throw_completion<JS::TypeError>(JS::ErrorType::NotAnObjectOfType, "DOM element"); | ||||
| 
 | ||||
|     return wrap(realm, *impl->get_computed_style(static_cast<ElementWrapper*>(object)->impl())); | ||||
| } | ||||
| 
 | ||||
| JS_DEFINE_NATIVE_FUNCTION(WindowObject::get_selection) | ||||
| { | ||||
|     auto& realm = *vm.current_realm(); | ||||
|     auto* impl = TRY(impl_from(vm)); | ||||
|     auto* selection = impl->get_selection(); | ||||
|     if (!selection) | ||||
|         return JS::js_null(); | ||||
|     return wrap(realm, *selection); | ||||
| } | ||||
| 
 | ||||
| JS_DEFINE_NATIVE_FUNCTION(WindowObject::match_media) | ||||
| { | ||||
|     auto& realm = *vm.current_realm(); | ||||
|     auto* impl = TRY(impl_from(vm)); | ||||
|     auto media = TRY(vm.argument(0).to_string(vm)); | ||||
|     return wrap(realm, impl->match_media(move(media))); | ||||
| } | ||||
| 
 | ||||
| // https://www.w3.org/TR/cssom-view/#dom-window-scrollx
 | ||||
| JS_DEFINE_NATIVE_FUNCTION(WindowObject::scroll_x_getter) | ||||
| { | ||||
|     auto* impl = TRY(impl_from(vm)); | ||||
|     return JS::Value(impl->scroll_x()); | ||||
| } | ||||
| 
 | ||||
| // https://www.w3.org/TR/cssom-view/#dom-window-scrolly
 | ||||
| JS_DEFINE_NATIVE_FUNCTION(WindowObject::scroll_y_getter) | ||||
| { | ||||
|     auto* impl = TRY(impl_from(vm)); | ||||
|     return JS::Value(impl->scroll_y()); | ||||
| } | ||||
| 
 | ||||
| enum class ScrollBehavior { | ||||
|     Auto, | ||||
|     Smooth | ||||
| }; | ||||
| 
 | ||||
| // https://www.w3.org/TR/cssom-view/#perform-a-scroll
 | ||||
| static void perform_a_scroll(Page& page, double x, double y, ScrollBehavior) | ||||
| { | ||||
|     // FIXME: Stop any existing smooth-scrolls
 | ||||
|     // FIXME: Implement smooth-scroll
 | ||||
|     page.client().page_did_request_scroll_to({ x, y }); | ||||
| } | ||||
| 
 | ||||
| // https://www.w3.org/TR/cssom-view/#dom-window-scroll
 | ||||
| JS_DEFINE_NATIVE_FUNCTION(WindowObject::scroll) | ||||
| { | ||||
|     auto* impl = TRY(impl_from(vm)); | ||||
|     if (!impl->page()) | ||||
|         return JS::js_undefined(); | ||||
|     auto& page = *impl->page(); | ||||
| 
 | ||||
|     auto viewport_rect = page.top_level_browsing_context().viewport_rect(); | ||||
|     auto x_value = JS::Value(viewport_rect.x()); | ||||
|     auto y_value = JS::Value(viewport_rect.y()); | ||||
|     String behavior_string = "auto"; | ||||
| 
 | ||||
|     if (vm.argument_count() == 1) { | ||||
|         auto* options = TRY(vm.argument(0).to_object(vm)); | ||||
|         auto left = TRY(options->get("left")); | ||||
|         if (!left.is_undefined()) | ||||
|             x_value = left; | ||||
| 
 | ||||
|         auto top = TRY(options->get("top")); | ||||
|         if (!top.is_undefined()) | ||||
|             y_value = top; | ||||
| 
 | ||||
|         auto behavior_string_value = TRY(options->get("behavior")); | ||||
|         if (!behavior_string_value.is_undefined()) | ||||
|             behavior_string = TRY(behavior_string_value.to_string(vm)); | ||||
|         if (behavior_string != "smooth" && behavior_string != "auto") | ||||
|             return vm.throw_completion<JS::TypeError>("Behavior is not one of 'smooth' or 'auto'"); | ||||
| 
 | ||||
|     } else if (vm.argument_count() >= 2) { | ||||
|         // We ignore arguments 2+ in line with behavior of Chrome and Firefox
 | ||||
|         x_value = vm.argument(0); | ||||
|         y_value = vm.argument(1); | ||||
|     } | ||||
| 
 | ||||
|     ScrollBehavior behavior = (behavior_string == "smooth") ? ScrollBehavior::Smooth : ScrollBehavior::Auto; | ||||
| 
 | ||||
|     double x = TRY(x_value.to_double(vm)); | ||||
|     x = JS::Value(x).is_finite_number() ? x : 0.0; | ||||
| 
 | ||||
|     double y = TRY(y_value.to_double(vm)); | ||||
|     y = JS::Value(y).is_finite_number() ? y : 0.0; | ||||
| 
 | ||||
|     // FIXME: Are we calculating the viewport in the way this function expects?
 | ||||
|     // FIXME: Handle overflow-directions other than top-left to bottom-right
 | ||||
| 
 | ||||
|     perform_a_scroll(page, x, y, behavior); | ||||
|     return JS::js_undefined(); | ||||
| } | ||||
| 
 | ||||
| // https://www.w3.org/TR/cssom-view/#dom-window-scrollby
 | ||||
| JS_DEFINE_NATIVE_FUNCTION(WindowObject::scroll_by) | ||||
| { | ||||
|     auto& realm = *vm.current_realm(); | ||||
| 
 | ||||
|     auto* impl = TRY(impl_from(vm)); | ||||
|     if (!impl->page()) | ||||
|         return JS::js_undefined(); | ||||
|     auto& page = *impl->page(); | ||||
| 
 | ||||
|     JS::Object* options = nullptr; | ||||
| 
 | ||||
|     if (vm.argument_count() == 0) { | ||||
|         options = JS::Object::create(realm, nullptr); | ||||
|     } else if (vm.argument_count() == 1) { | ||||
|         options = TRY(vm.argument(0).to_object(vm)); | ||||
|     } else if (vm.argument_count() >= 2) { | ||||
|         // We ignore arguments 2+ in line with behavior of Chrome and Firefox
 | ||||
|         options = JS::Object::create(realm, nullptr); | ||||
|         MUST(options->set("left", vm.argument(0), ShouldThrowExceptions::No)); | ||||
|         MUST(options->set("top", vm.argument(1), ShouldThrowExceptions::No)); | ||||
|         MUST(options->set("behavior", JS::js_string(vm, "auto"), ShouldThrowExceptions::No)); | ||||
|     } | ||||
| 
 | ||||
|     auto left_value = TRY(options->get("left")); | ||||
|     auto left = TRY(left_value.to_double(vm)); | ||||
| 
 | ||||
|     auto top_value = TRY(options->get("top")); | ||||
|     auto top = TRY(top_value.to_double(vm)); | ||||
| 
 | ||||
|     left = JS::Value(left).is_finite_number() ? left : 0.0; | ||||
|     top = JS::Value(top).is_finite_number() ? top : 0.0; | ||||
| 
 | ||||
|     auto current_scroll_position = page.top_level_browsing_context().viewport_scroll_offset(); | ||||
|     left = left + current_scroll_position.x(); | ||||
|     top = top + current_scroll_position.y(); | ||||
| 
 | ||||
|     auto behavior_string_value = TRY(options->get("behavior")); | ||||
|     auto behavior_string = behavior_string_value.is_undefined() ? "auto" : TRY(behavior_string_value.to_string(vm)); | ||||
|     if (behavior_string != "smooth" && behavior_string != "auto") | ||||
|         return vm.throw_completion<JS::TypeError>("Behavior is not one of 'smooth' or 'auto'"); | ||||
|     ScrollBehavior behavior = (behavior_string == "smooth") ? ScrollBehavior::Smooth : ScrollBehavior::Auto; | ||||
| 
 | ||||
|     // FIXME: Spec wants us to call scroll(options) here.
 | ||||
|     //        The only difference is that would invoke the viewport calculations that scroll()
 | ||||
|     //        is not actually doing yet, so this is the same for now.
 | ||||
|     perform_a_scroll(page, left, top, behavior); | ||||
|     return JS::js_undefined(); | ||||
| } | ||||
| 
 | ||||
| JS_DEFINE_NATIVE_FUNCTION(WindowObject::history_getter) | ||||
| { | ||||
|     auto& realm = *vm.current_realm(); | ||||
|     auto* impl = TRY(impl_from(vm)); | ||||
|     return wrap(realm, impl->associated_document().history()); | ||||
| } | ||||
| 
 | ||||
| JS_DEFINE_NATIVE_FUNCTION(WindowObject::screen_left_getter) | ||||
| { | ||||
|     auto* impl = TRY(impl_from(vm)); | ||||
|     return JS::Value(impl->screen_x()); | ||||
| } | ||||
| 
 | ||||
| JS_DEFINE_NATIVE_FUNCTION(WindowObject::screen_top_getter) | ||||
| { | ||||
|     auto* impl = TRY(impl_from(vm)); | ||||
|     return JS::Value(impl->screen_y()); | ||||
| } | ||||
| 
 | ||||
| JS_DEFINE_NATIVE_FUNCTION(WindowObject::screen_x_getter) | ||||
| { | ||||
|     auto* impl = TRY(impl_from(vm)); | ||||
|     return JS::Value(impl->screen_x()); | ||||
| } | ||||
| 
 | ||||
| JS_DEFINE_NATIVE_FUNCTION(WindowObject::screen_y_getter) | ||||
| { | ||||
|     auto* impl = TRY(impl_from(vm)); | ||||
|     return JS::Value(impl->screen_y()); | ||||
| } | ||||
| 
 | ||||
| JS_DEFINE_NATIVE_FUNCTION(WindowObject::post_message) | ||||
| { | ||||
|     auto* impl = TRY(impl_from(vm)); | ||||
|     auto target_origin = TRY(vm.argument(1).to_string(vm)); | ||||
|     impl->post_message(vm.argument(0), target_origin); | ||||
|     return JS::js_undefined(); | ||||
| } | ||||
| 
 | ||||
| // https://html.spec.whatwg.org/multipage/webappapis.html#dom-origin
 | ||||
| JS_DEFINE_NATIVE_FUNCTION(WindowObject::origin_getter) | ||||
| { | ||||
|     auto* impl = TRY(impl_from(vm)); | ||||
|     return JS::js_string(vm, impl->associated_document().origin().serialize()); | ||||
| } | ||||
| 
 | ||||
| JS_DEFINE_NATIVE_FUNCTION(WindowObject::local_storage_getter) | ||||
| { | ||||
|     auto& realm = *vm.current_realm(); | ||||
|     auto* impl = TRY(impl_from(vm)); | ||||
|     // FIXME: localStorage may throw. We have to deal with that here.
 | ||||
|     return wrap(realm, *impl->local_storage()); | ||||
| } | ||||
| 
 | ||||
| JS_DEFINE_NATIVE_FUNCTION(WindowObject::session_storage_getter) | ||||
| { | ||||
|     auto& realm = *vm.current_realm(); | ||||
|     auto* impl = TRY(impl_from(vm)); | ||||
|     // FIXME: sessionStorage may throw. We have to deal with that here.
 | ||||
|     return wrap(realm, *impl->session_storage()); | ||||
| } | ||||
| 
 | ||||
| JS_DEFINE_NATIVE_FUNCTION(WindowObject::name_getter) | ||||
| { | ||||
|     auto* impl = TRY(impl_from(vm)); | ||||
|     return JS::js_string(vm, impl->name()); | ||||
| } | ||||
| 
 | ||||
| JS_DEFINE_NATIVE_FUNCTION(WindowObject::name_setter) | ||||
| { | ||||
|     auto* impl = TRY(impl_from(vm)); | ||||
|     impl->set_name(TRY(vm.argument(0).to_string(vm))); | ||||
|     return JS::js_undefined(); | ||||
| } | ||||
| 
 | ||||
| #define __ENUMERATE(attribute, event_name)                                        \ | ||||
|     JS_DEFINE_NATIVE_FUNCTION(WindowObject::attribute##_getter)                   \ | ||||
|     {                                                                             \ | ||||
|         auto* impl = TRY(impl_from(vm));                                          \ | ||||
|         auto retval = impl->attribute();                                          \ | ||||
|         if (!retval)                                                              \ | ||||
|             return JS::js_null();                                                 \ | ||||
|         return &retval->callback;                                                 \ | ||||
|     }                                                                             \ | ||||
|     JS_DEFINE_NATIVE_FUNCTION(WindowObject::attribute##_setter)                   \ | ||||
|     {                                                                             \ | ||||
|         auto* impl = TRY(impl_from(vm));                                          \ | ||||
|         auto value = vm.argument(0);                                              \ | ||||
|         Bindings::CallbackType* cpp_value;                                        \ | ||||
|         if (value.is_object()) {                                                  \ | ||||
|             cpp_value = vm.heap().allocate_without_realm<Bindings::CallbackType>( \ | ||||
|                 value.as_object(), HTML::incumbent_settings_object());            \ | ||||
|         }                                                                         \ | ||||
|         impl->set_##attribute(cpp_value);                                         \ | ||||
|         return JS::js_undefined();                                                \ | ||||
|     } | ||||
| ENUMERATE_GLOBAL_EVENT_HANDLERS(__ENUMERATE) | ||||
| ENUMERATE_WINDOW_EVENT_HANDLERS(__ENUMERATE) | ||||
| #undef __ENUMERATE | ||||
| 
 | ||||
| } | ||||
|  | @ -23,9 +23,6 @@ | |||
| namespace Web { | ||||
| namespace Bindings { | ||||
| 
 | ||||
| // https://html.spec.whatwg.org/#timerhandler
 | ||||
| using TimerHandler = Variant<JS::Handle<CallbackType>, String>; | ||||
| 
 | ||||
| class WindowObject | ||||
|     : public JS::GlobalObject | ||||
|     , public Weakable<WindowObject> { | ||||
|  | @ -35,134 +32,6 @@ public: | |||
|     explicit WindowObject(JS::Realm&, HTML::Window&); | ||||
|     virtual void initialize(JS::Realm&) override; | ||||
|     virtual ~WindowObject() override = default; | ||||
| 
 | ||||
|     JS::Realm& realm() const { return shape().realm(); } | ||||
| 
 | ||||
|     HTML::Window& impl() { return *m_impl; } | ||||
|     const HTML::Window& impl() const { return *m_impl; } | ||||
| 
 | ||||
|     HTML::Origin origin() const; | ||||
| 
 | ||||
|     LocationObject* location_object() { return m_location_object; } | ||||
|     LocationObject const* location_object() const { return m_location_object; } | ||||
| 
 | ||||
|     JS::Object* web_prototype(String const& class_name) { return m_prototypes.get(class_name).value_or(nullptr); } | ||||
|     JS::NativeFunction* web_constructor(String const& class_name) { return m_constructors.get(class_name).value_or(nullptr); } | ||||
| 
 | ||||
|     template<typename T> | ||||
|     JS::Object& ensure_web_prototype(String const& class_name) | ||||
|     { | ||||
|         auto it = m_prototypes.find(class_name); | ||||
|         if (it != m_prototypes.end()) | ||||
|             return *it->value; | ||||
|         auto& realm = shape().realm(); | ||||
|         auto* prototype = heap().allocate<T>(realm, realm); | ||||
|         m_prototypes.set(class_name, prototype); | ||||
|         return *prototype; | ||||
|     } | ||||
| 
 | ||||
|     template<typename T> | ||||
|     JS::NativeFunction& ensure_web_constructor(String const& class_name) | ||||
|     { | ||||
|         auto it = m_constructors.find(class_name); | ||||
|         if (it != m_constructors.end()) | ||||
|             return *it->value; | ||||
|         auto& realm = shape().realm(); | ||||
|         auto* constructor = heap().allocate<T>(realm, realm); | ||||
|         m_constructors.set(class_name, constructor); | ||||
|         define_direct_property(class_name, JS::Value(constructor), JS::Attribute::Writable | JS::Attribute::Configurable); | ||||
|         return *constructor; | ||||
|     } | ||||
| 
 | ||||
|     virtual JS::ThrowCompletionOr<bool> internal_set_prototype_of(JS::Object* prototype) override; | ||||
| 
 | ||||
|     CrossOriginPropertyDescriptorMap const& cross_origin_property_descriptor_map() const { return m_cross_origin_property_descriptor_map; } | ||||
|     CrossOriginPropertyDescriptorMap& cross_origin_property_descriptor_map() { return m_cross_origin_property_descriptor_map; } | ||||
| 
 | ||||
| private: | ||||
|     virtual void visit_edges(Visitor&) override; | ||||
| 
 | ||||
|     JS_DECLARE_NATIVE_FUNCTION(top_getter); | ||||
| 
 | ||||
|     JS_DECLARE_NATIVE_FUNCTION(document_getter); | ||||
| 
 | ||||
|     JS_DECLARE_NATIVE_FUNCTION(location_getter); | ||||
|     JS_DECLARE_NATIVE_FUNCTION(location_setter); | ||||
| 
 | ||||
|     JS_DECLARE_NATIVE_FUNCTION(name_getter); | ||||
|     JS_DECLARE_NATIVE_FUNCTION(name_setter); | ||||
| 
 | ||||
|     JS_DECLARE_NATIVE_FUNCTION(performance_getter); | ||||
|     JS_DECLARE_NATIVE_FUNCTION(performance_setter); | ||||
| 
 | ||||
|     JS_DECLARE_NATIVE_FUNCTION(history_getter); | ||||
|     JS_DECLARE_NATIVE_FUNCTION(screen_getter); | ||||
| 
 | ||||
|     JS_DECLARE_NATIVE_FUNCTION(event_getter); | ||||
|     JS_DECLARE_NATIVE_FUNCTION(event_setter); | ||||
| 
 | ||||
|     JS_DECLARE_NATIVE_FUNCTION(inner_width_getter); | ||||
|     JS_DECLARE_NATIVE_FUNCTION(inner_height_getter); | ||||
| 
 | ||||
|     JS_DECLARE_NATIVE_FUNCTION(parent_getter); | ||||
| 
 | ||||
|     JS_DECLARE_NATIVE_FUNCTION(device_pixel_ratio_getter); | ||||
| 
 | ||||
|     JS_DECLARE_NATIVE_FUNCTION(scroll_x_getter); | ||||
|     JS_DECLARE_NATIVE_FUNCTION(scroll_y_getter); | ||||
|     JS_DECLARE_NATIVE_FUNCTION(scroll); | ||||
|     JS_DECLARE_NATIVE_FUNCTION(scroll_by); | ||||
| 
 | ||||
|     JS_DECLARE_NATIVE_FUNCTION(screen_x_getter); | ||||
|     JS_DECLARE_NATIVE_FUNCTION(screen_y_getter); | ||||
|     JS_DECLARE_NATIVE_FUNCTION(screen_left_getter); | ||||
|     JS_DECLARE_NATIVE_FUNCTION(screen_top_getter); | ||||
| 
 | ||||
|     JS_DECLARE_NATIVE_FUNCTION(post_message); | ||||
| 
 | ||||
|     JS_DECLARE_NATIVE_FUNCTION(local_storage_getter); | ||||
|     JS_DECLARE_NATIVE_FUNCTION(session_storage_getter); | ||||
|     JS_DECLARE_NATIVE_FUNCTION(origin_getter); | ||||
| 
 | ||||
|     JS_DECLARE_NATIVE_FUNCTION(alert); | ||||
|     JS_DECLARE_NATIVE_FUNCTION(confirm); | ||||
|     JS_DECLARE_NATIVE_FUNCTION(prompt); | ||||
|     JS_DECLARE_NATIVE_FUNCTION(set_interval); | ||||
|     JS_DECLARE_NATIVE_FUNCTION(set_timeout); | ||||
|     JS_DECLARE_NATIVE_FUNCTION(clear_interval); | ||||
|     JS_DECLARE_NATIVE_FUNCTION(clear_timeout); | ||||
|     JS_DECLARE_NATIVE_FUNCTION(request_animation_frame); | ||||
|     JS_DECLARE_NATIVE_FUNCTION(cancel_animation_frame); | ||||
|     JS_DECLARE_NATIVE_FUNCTION(atob); | ||||
|     JS_DECLARE_NATIVE_FUNCTION(btoa); | ||||
| 
 | ||||
|     JS_DECLARE_NATIVE_FUNCTION(get_computed_style); | ||||
|     JS_DECLARE_NATIVE_FUNCTION(match_media); | ||||
|     JS_DECLARE_NATIVE_FUNCTION(get_selection); | ||||
| 
 | ||||
|     JS_DECLARE_NATIVE_FUNCTION(queue_microtask); | ||||
| 
 | ||||
|     JS_DECLARE_NATIVE_FUNCTION(request_idle_callback); | ||||
|     JS_DECLARE_NATIVE_FUNCTION(cancel_idle_callback); | ||||
| 
 | ||||
|     JS_DECLARE_NATIVE_FUNCTION(crypto_getter); | ||||
| 
 | ||||
| #define __ENUMERATE(attribute, event_name)          \ | ||||
|     JS_DECLARE_NATIVE_FUNCTION(attribute##_getter); \ | ||||
|     JS_DECLARE_NATIVE_FUNCTION(attribute##_setter); | ||||
|     ENUMERATE_GLOBAL_EVENT_HANDLERS(__ENUMERATE); | ||||
|     ENUMERATE_WINDOW_EVENT_HANDLERS(__ENUMERATE); | ||||
| #undef __ENUMERATE | ||||
| 
 | ||||
|     NonnullRefPtr<HTML::Window> m_impl; | ||||
| 
 | ||||
|     LocationObject* m_location_object { nullptr }; | ||||
| 
 | ||||
|     HashMap<String, JS::Object*> m_prototypes; | ||||
|     HashMap<String, JS::NativeFunction*> m_constructors; | ||||
| 
 | ||||
|     // [[CrossOriginPropertyDescriptorMap]], https://html.spec.whatwg.org/multipage/browsers.html#crossoriginpropertydescriptormap
 | ||||
|     CrossOriginPropertyDescriptorMap m_cross_origin_property_descriptor_map; | ||||
| }; | ||||
| 
 | ||||
| } | ||||
|  |  | |||
|  | @ -376,9 +376,9 @@ | |||
| 
 | ||||
| #define ADD_WINDOW_OBJECT_CONSTRUCTOR_AND_PROTOTYPE(interface_name, constructor_name, prototype_name)                                \ | ||||
|     {                                                                                                                                \ | ||||
|         auto& constructor = ensure_web_constructor<constructor_name>(#interface_name);                                               \ | ||||
|         auto& constructor = ensure_web_constructor<Bindings::constructor_name>(#interface_name);                                     \ | ||||
|         constructor.define_direct_property(vm.names.name, js_string(vm, #interface_name), JS::Attribute::Configurable);              \ | ||||
|         auto& prototype = ensure_web_prototype<prototype_name>(#interface_name);                                                     \ | ||||
|         auto& prototype = ensure_web_prototype<Bindings::prototype_name>(#interface_name);                                           \ | ||||
|         prototype.define_direct_property(vm.names.constructor, &constructor, JS::Attribute::Writable | JS::Attribute::Configurable); \ | ||||
|     } | ||||
| 
 | ||||
|  |  | |||
|  | @ -10,8 +10,8 @@ | |||
| #include <LibJS/Runtime/Object.h> | ||||
| #include <LibJS/Runtime/VM.h> | ||||
| #include <LibWeb/Bindings/EventTargetPrototype.h> | ||||
| #include <LibWeb/Bindings/WindowObject.h> | ||||
| #include <LibWeb/Forward.h> | ||||
| #include <LibWeb/HTML/Window.h> | ||||
| 
 | ||||
| namespace Web::Bindings { | ||||
| 
 | ||||
|  | @ -20,7 +20,7 @@ class WindowPrototype final : public JS::Object { | |||
| 
 | ||||
| public: | ||||
|     explicit WindowPrototype(JS::Realm& realm) | ||||
|         : JS::Object(static_cast<WindowObject&>(realm.global_object()).ensure_web_prototype<EventTargetPrototype>("EventTarget")) | ||||
|         : JS::Object(verify_cast<HTML::Window>(realm.global_object()).ensure_web_prototype<EventTargetPrototype>("EventTarget")) | ||||
|     { | ||||
|     } | ||||
| }; | ||||
|  |  | |||
|  | @ -12,7 +12,6 @@ | |||
| #include <LibJS/Runtime/PropertyKey.h> | ||||
| #include <LibWeb/Bindings/CrossOriginAbstractOperations.h> | ||||
| #include <LibWeb/Bindings/DOMExceptionWrapper.h> | ||||
| #include <LibWeb/Bindings/WindowObject.h> | ||||
| #include <LibWeb/Bindings/WindowProxy.h> | ||||
| #include <LibWeb/DOM/DOMException.h> | ||||
| #include <LibWeb/HTML/CrossOrigin/Reporting.h> | ||||
|  | @ -22,9 +21,9 @@ | |||
| namespace Web::Bindings { | ||||
| 
 | ||||
| // 7.4 The WindowProxy exotic object, https://html.spec.whatwg.org/multipage/window-object.html#the-windowproxy-exotic-object
 | ||||
| WindowProxy::WindowProxy(JS::Realm& realm, WindowObject& window) | ||||
| WindowProxy::WindowProxy(JS::Realm& realm, HTML::Window& window) | ||||
|     : JS::Object(realm, nullptr) | ||||
|     , m_window(&window) | ||||
|     , m_window(window) | ||||
| { | ||||
| } | ||||
| 
 | ||||
|  | @ -105,7 +104,7 @@ JS::ThrowCompletionOr<Optional<JS::PropertyDescriptor>> WindowProxy::internal_ge | |||
|         return m_window->internal_get_own_property(property_key); | ||||
| 
 | ||||
|     // 4. Let property be CrossOriginGetOwnPropertyHelper(W, P).
 | ||||
|     auto property = cross_origin_get_own_property_helper(m_window, property_key); | ||||
|     auto property = cross_origin_get_own_property_helper(const_cast<HTML::Window*>(m_window.ptr()), property_key); | ||||
| 
 | ||||
|     // 5. If property is not undefined, then return property.
 | ||||
|     if (property.has_value()) | ||||
|  | @ -155,7 +154,7 @@ JS::ThrowCompletionOr<JS::Value> WindowProxy::internal_get(JS::PropertyKey const | |||
|     // 1. Let W be the value of the [[Window]] internal slot of this.
 | ||||
| 
 | ||||
|     // 2. Check if an access between two browsing contexts should be reported, given the current global object's browsing context, W's browsing context, P, and the current settings object.
 | ||||
|     HTML::check_if_access_between_two_browsing_contexts_should_be_reported(*static_cast<WindowObject&>(HTML::current_global_object()).impl().browsing_context(), *m_window->impl().browsing_context(), property_key, HTML::current_settings_object()); | ||||
|     HTML::check_if_access_between_two_browsing_contexts_should_be_reported(*verify_cast<HTML::Window>(HTML::current_global_object()).impl().browsing_context(), *m_window->browsing_context(), property_key, HTML::current_settings_object()); | ||||
| 
 | ||||
|     // 3. If IsPlatformObjectSameOrigin(W) is true, then return ? OrdinaryGet(this, P, Receiver).
 | ||||
|     // NOTE: this is passed rather than W as OrdinaryGet and CrossOriginGet will invoke the [[GetOwnProperty]] internal method.
 | ||||
|  | @ -175,7 +174,7 @@ JS::ThrowCompletionOr<bool> WindowProxy::internal_set(JS::PropertyKey const& pro | |||
|     // 1. Let W be the value of the [[Window]] internal slot of this.
 | ||||
| 
 | ||||
|     // 2. Check if an access between two browsing contexts should be reported, given the current global object's browsing context, W's browsing context, P, and the current settings object.
 | ||||
|     HTML::check_if_access_between_two_browsing_contexts_should_be_reported(*static_cast<WindowObject&>(HTML::current_global_object()).impl().browsing_context(), *m_window->impl().browsing_context(), property_key, HTML::current_settings_object()); | ||||
|     HTML::check_if_access_between_two_browsing_contexts_should_be_reported(*verify_cast<HTML::Window>(HTML::current_global_object()).browsing_context(), *m_window->impl().browsing_context(), property_key, HTML::current_settings_object()); | ||||
| 
 | ||||
|     // 3. If IsPlatformObjectSameOrigin(W) is true, then:
 | ||||
|     if (is_platform_object_same_origin(*m_window)) { | ||||
|  | @ -252,13 +251,14 @@ JS::ThrowCompletionOr<JS::MarkedVector<JS::Value>> WindowProxy::internal_own_pro | |||
|     } | ||||
| 
 | ||||
|     // 7. Return the concatenation of keys and ! CrossOriginOwnPropertyKeys(W).
 | ||||
|     keys.extend(cross_origin_own_property_keys(m_window)); | ||||
|     keys.extend(cross_origin_own_property_keys(m_window.ptr())); | ||||
|     return keys; | ||||
| } | ||||
| 
 | ||||
| void WindowProxy::visit_edges(JS::Cell::Visitor& visitor) | ||||
| { | ||||
|     visitor.visit(m_window); | ||||
|     Base::visit_edges(visitor); | ||||
|     visitor.visit(m_window.ptr()); | ||||
| } | ||||
| 
 | ||||
| } | ||||
|  |  | |||
|  | @ -17,7 +17,6 @@ class WindowProxy final : public JS::Object { | |||
|     JS_OBJECT(WindowProxy, JS::Object); | ||||
| 
 | ||||
| public: | ||||
|     WindowProxy(JS::Realm&, WindowObject&); | ||||
|     virtual ~WindowProxy() override = default; | ||||
| 
 | ||||
|     virtual JS::ThrowCompletionOr<JS::Object*> internal_get_prototype_of() const override; | ||||
|  | @ -31,18 +30,20 @@ public: | |||
|     virtual JS::ThrowCompletionOr<bool> internal_delete(JS::PropertyKey const&) override; | ||||
|     virtual JS::ThrowCompletionOr<JS::MarkedVector<JS::Value>> internal_own_property_keys() const override; | ||||
| 
 | ||||
|     WindowObject& window() { return *m_window; } | ||||
|     WindowObject const& window() const { return *m_window; } | ||||
|     HTML::Window& window() { return *m_window; } | ||||
|     HTML::Window const& window() const { return *m_window; } | ||||
| 
 | ||||
|     // NOTE: Someone will have to replace the wrapped window object as well:
 | ||||
|     // "When the browsing context is navigated, the Window object wrapped by the browsing context's associated WindowProxy object is changed."
 | ||||
|     // I haven't found where that actually happens yet. Make sure to use a Badge<T> guarded setter.
 | ||||
| 
 | ||||
| private: | ||||
|     WindowProxy(JS::Realm&, HTML::Window&); | ||||
| 
 | ||||
|     virtual void visit_edges(JS::Cell::Visitor&) override; | ||||
| 
 | ||||
|     // [[Window]], https://html.spec.whatwg.org/multipage/window-object.html#concept-windowproxy-window
 | ||||
|     WindowObject* m_window { nullptr }; | ||||
|     JS::GCPtr<HTML::Window> m_window; | ||||
| }; | ||||
| 
 | ||||
| } | ||||
|  |  | |||
|  | @ -13,7 +13,7 @@ namespace Bindings { | |||
| void Wrappable::set_wrapper(Wrapper& wrapper) | ||||
| { | ||||
|     VERIFY(!m_wrapper); | ||||
|     m_wrapper = wrapper.make_weak_ptr(); | ||||
|     m_wrapper = wrapper.make_weak_ptr<Wrapper>(); | ||||
| } | ||||
| 
 | ||||
| } | ||||
|  |  | |||
|  | @ -12,10 +12,8 @@ | |||
| 
 | ||||
| namespace Web::Bindings { | ||||
| 
 | ||||
| class Wrapper | ||||
|     : public PlatformObject | ||||
|     , public Weakable<Wrapper> { | ||||
|     JS_OBJECT(Wrapper, PlatformObject); | ||||
| class Wrapper : public PlatformObject { | ||||
|     WEB_PLATFORM_OBJECT(Wrapper, PlatformObject); | ||||
| 
 | ||||
| public: | ||||
|     virtual ~Wrapper() override; | ||||
|  |  | |||
|  | @ -5,7 +5,6 @@ set(SOURCES | |||
|     Bindings/CSSNamespace.cpp | ||||
|     Bindings/CallbackType.cpp | ||||
|     Bindings/CrossOriginAbstractOperations.cpp | ||||
|     Bindings/EventTargetWrapperFactory.cpp | ||||
|     Bindings/IDLAbstractOperations.cpp | ||||
|     Bindings/ImageConstructor.cpp | ||||
|     Bindings/LegacyPlatformObject.cpp | ||||
|  | @ -14,11 +13,9 @@ set(SOURCES | |||
|     Bindings/MainThreadVM.cpp | ||||
|     Bindings/NavigatorConstructor.cpp | ||||
|     Bindings/NavigatorObject.cpp | ||||
|     Bindings/NodeWrapperFactory.cpp | ||||
|     Bindings/OptionConstructor.cpp | ||||
|     Bindings/PlatformObject.cpp | ||||
|     Bindings/WindowConstructor.cpp | ||||
|     Bindings/WindowObject.cpp | ||||
|     Bindings/WindowProxy.cpp | ||||
|     Bindings/Wrappable.cpp | ||||
|     Bindings/Wrapper.cpp | ||||
|  |  | |||
|  | @ -6,12 +6,12 @@ | |||
|  */ | ||||
| 
 | ||||
| #include <LibWeb/Bindings/CSSConditionRulePrototype.h> | ||||
| #include <LibWeb/Bindings/WindowObject.h> | ||||
| #include <LibWeb/CSS/CSSConditionRule.h> | ||||
| #include <LibWeb/HTML/Window.h> | ||||
| 
 | ||||
| namespace Web::CSS { | ||||
| 
 | ||||
| CSSConditionRule::CSSConditionRule(Bindings::WindowObject& window_object, CSSRuleList& rules) | ||||
| CSSConditionRule::CSSConditionRule(HTML::Window& window_object, CSSRuleList& rules) | ||||
|     : CSSGroupingRule(window_object, rules) | ||||
| { | ||||
|     set_prototype(&window_object.ensure_web_prototype<Bindings::CSSConditionRulePrototype>("CSSConditionRule")); | ||||
|  |  | |||
|  | @ -13,13 +13,9 @@ | |||
| namespace Web::CSS { | ||||
| 
 | ||||
| class CSSConditionRule : public CSSGroupingRule { | ||||
|     AK_MAKE_NONCOPYABLE(CSSConditionRule); | ||||
|     AK_MAKE_NONMOVABLE(CSSConditionRule); | ||||
|     JS_OBJECT(CSSConditionRule, CSSGroupingRule); | ||||
|     WEB_PLATFORM_OBJECT(CSSConditionRule, CSSGroupingRule); | ||||
| 
 | ||||
| public: | ||||
|     CSSConditionRule& impl() { return *this; } | ||||
| 
 | ||||
|     virtual ~CSSConditionRule() = default; | ||||
| 
 | ||||
|     virtual String condition_text() const = 0; | ||||
|  | @ -29,12 +25,9 @@ public: | |||
|     virtual void for_each_effective_style_rule(Function<void(CSSStyleRule const&)> const& callback) const override; | ||||
| 
 | ||||
| protected: | ||||
|     explicit CSSConditionRule(Bindings::WindowObject&, CSSRuleList&); | ||||
|     explicit CSSConditionRule(HTML::Window&, CSSRuleList&); | ||||
| }; | ||||
| 
 | ||||
| } | ||||
| 
 | ||||
| namespace Web::Bindings { | ||||
| inline JS::Object* wrap(JS::Realm&, Web::CSS::CSSConditionRule& object) { return &object; } | ||||
| using CSSConditionRuleWrapper = Web::CSS::CSSConditionRule; | ||||
| } | ||||
| WRAPPER_HACK(CSSConditionRule, Web::CSS) | ||||
|  |  | |||
|  | @ -6,17 +6,17 @@ | |||
|  */ | ||||
| 
 | ||||
| #include <LibWeb/Bindings/CSSFontFaceRulePrototype.h> | ||||
| #include <LibWeb/Bindings/WindowObject.h> | ||||
| #include <LibWeb/CSS/CSSFontFaceRule.h> | ||||
| #include <LibWeb/HTML/Window.h> | ||||
| 
 | ||||
| namespace Web::CSS { | ||||
| 
 | ||||
| CSSFontFaceRule* CSSFontFaceRule::create(Bindings::WindowObject& window_object, FontFace&& font_face) | ||||
| CSSFontFaceRule* CSSFontFaceRule::create(HTML::Window& window_object, FontFace&& font_face) | ||||
| { | ||||
|     return window_object.heap().allocate<CSSFontFaceRule>(window_object.realm(), window_object, move(font_face)); | ||||
| } | ||||
| 
 | ||||
| CSSFontFaceRule::CSSFontFaceRule(Bindings::WindowObject& window_object, FontFace&& font_face) | ||||
| CSSFontFaceRule::CSSFontFaceRule(HTML::Window& window_object, FontFace&& font_face) | ||||
|     : CSSRule(window_object) | ||||
|     , m_font_face(move(font_face)) | ||||
| { | ||||
|  |  | |||
|  | @ -13,16 +13,12 @@ | |||
| namespace Web::CSS { | ||||
| 
 | ||||
| class CSSFontFaceRule final : public CSSRule { | ||||
|     AK_MAKE_NONCOPYABLE(CSSFontFaceRule); | ||||
|     AK_MAKE_NONMOVABLE(CSSFontFaceRule); | ||||
|     JS_OBJECT(CSSFontFaceRule, CSSRule); | ||||
|     WEB_PLATFORM_OBJECT(CSSFontFaceRule, CSSRule); | ||||
| 
 | ||||
| public: | ||||
|     static CSSFontFaceRule* create(Bindings::WindowObject&, FontFace&&); | ||||
|     explicit CSSFontFaceRule(Bindings::WindowObject&, FontFace&&); | ||||
|     static CSSFontFaceRule* create(HTML::Window&, FontFace&&); | ||||
| 
 | ||||
|     virtual ~CSSFontFaceRule() override = default; | ||||
|     CSSFontFaceRule& impl() { return *this; } | ||||
| 
 | ||||
|     virtual Type type() const override { return Type::FontFace; } | ||||
| 
 | ||||
|  | @ -30,6 +26,8 @@ public: | |||
|     CSSStyleDeclaration* style(); | ||||
| 
 | ||||
| private: | ||||
|     explicit CSSFontFaceRule(HTML::Window&, FontFace&&); | ||||
| 
 | ||||
|     virtual String serialized() const override; | ||||
| 
 | ||||
|     FontFace m_font_face; | ||||
|  | @ -40,7 +38,4 @@ inline bool CSSRule::fast_is<CSSFontFaceRule>() const { return type() == CSSRule | |||
| 
 | ||||
| } | ||||
| 
 | ||||
| namespace Web::Bindings { | ||||
| inline JS::Object* wrap(JS::Realm&, Web::CSS::CSSFontFaceRule& object) { return &object; } | ||||
| using CSSFontFaceRuleWrapper = Web::CSS::CSSFontFaceRule; | ||||
| } | ||||
| WRAPPER_HACK(CSSFontFaceRule, Web::CSS) | ||||
|  |  | |||
|  | @ -7,13 +7,13 @@ | |||
| 
 | ||||
| #include <LibWeb/Bindings/CSSGroupingRulePrototype.h> | ||||
| #include <LibWeb/Bindings/MainThreadVM.h> | ||||
| #include <LibWeb/Bindings/WindowObject.h> | ||||
| #include <LibWeb/CSS/CSSGroupingRule.h> | ||||
| #include <LibWeb/CSS/CSSRuleList.h> | ||||
| #include <LibWeb/HTML/Window.h> | ||||
| 
 | ||||
| namespace Web::CSS { | ||||
| 
 | ||||
| CSSGroupingRule::CSSGroupingRule(Bindings::WindowObject& window_object, CSSRuleList& rules) | ||||
| CSSGroupingRule::CSSGroupingRule(HTML::Window& window_object, CSSRuleList& rules) | ||||
|     : CSSRule(window_object) | ||||
|     , m_rules(rules) | ||||
| { | ||||
|  |  | |||
|  | @ -15,13 +15,9 @@ | |||
| namespace Web::CSS { | ||||
| 
 | ||||
| class CSSGroupingRule : public CSSRule { | ||||
|     AK_MAKE_NONCOPYABLE(CSSGroupingRule); | ||||
|     AK_MAKE_NONMOVABLE(CSSGroupingRule); | ||||
|     JS_OBJECT(CSSGroupingRule, CSSRule); | ||||
|     WEB_PLATFORM_OBJECT(CSSGroupingRule, CSSRule); | ||||
| 
 | ||||
| public: | ||||
|     CSSGroupingRule& impl() { return *this; } | ||||
| 
 | ||||
|     virtual ~CSSGroupingRule() = default; | ||||
| 
 | ||||
|     CSSRuleList const& css_rules() const { return m_rules; } | ||||
|  | @ -35,7 +31,7 @@ public: | |||
|     virtual void set_parent_style_sheet(CSSStyleSheet*) override; | ||||
| 
 | ||||
| protected: | ||||
|     explicit CSSGroupingRule(Bindings::WindowObject&, CSSRuleList&); | ||||
|     explicit CSSGroupingRule(HTML::Window&, CSSRuleList&); | ||||
|     virtual void visit_edges(Cell::Visitor&) override; | ||||
| 
 | ||||
| private: | ||||
|  | @ -44,7 +40,4 @@ private: | |||
| 
 | ||||
| } | ||||
| 
 | ||||
| namespace Web::Bindings { | ||||
| inline JS::Object* wrap(JS::Realm&, Web::CSS::CSSGroupingRule& object) { return &object; } | ||||
| using CSSGroupingRuleWrapper = Web::CSS::CSSGroupingRule; | ||||
| } | ||||
| WRAPPER_HACK(CSSGroupingRule, Web::CSS) | ||||
|  |  | |||
|  | @ -9,26 +9,26 @@ | |||
| #include <AK/Debug.h> | ||||
| #include <AK/URL.h> | ||||
| #include <LibWeb/Bindings/CSSImportRulePrototype.h> | ||||
| #include <LibWeb/Bindings/WindowObject.h> | ||||
| #include <LibWeb/CSS/CSSImportRule.h> | ||||
| #include <LibWeb/CSS/Parser/Parser.h> | ||||
| #include <LibWeb/DOM/Document.h> | ||||
| #include <LibWeb/HTML/Window.h> | ||||
| #include <LibWeb/Loader/ResourceLoader.h> | ||||
| 
 | ||||
| namespace Web::CSS { | ||||
| 
 | ||||
| CSSImportRule* CSSImportRule::create(AK::URL url, DOM::Document& document) | ||||
| { | ||||
|     auto& window_object = document.preferred_window_object(); | ||||
|     auto& window_object = document.window(); | ||||
|     return window_object.heap().allocate<CSSImportRule>(window_object.realm(), move(url), document); | ||||
| } | ||||
| 
 | ||||
| CSSImportRule::CSSImportRule(AK::URL url, DOM::Document& document) | ||||
|     : CSSRule(document.preferred_window_object()) | ||||
|     : CSSRule(document.window()) | ||||
|     , m_url(move(url)) | ||||
|     , m_document(document) | ||||
| { | ||||
|     set_prototype(&document.preferred_window_object().ensure_web_prototype<Bindings::CSSImportRulePrototype>("CSSImportRule")); | ||||
|     set_prototype(&document.window().ensure_web_prototype<Bindings::CSSImportRulePrototype>("CSSImportRule")); | ||||
| 
 | ||||
|     dbgln_if(CSS_LOADER_DEBUG, "CSSImportRule: Loading import URL: {}", m_url); | ||||
|     auto request = LoadRequest::create_for_url_on_page(m_url, document.page()); | ||||
|  |  | |||
|  | @ -19,18 +19,13 @@ namespace Web::CSS { | |||
| class CSSImportRule final | ||||
|     : public CSSRule | ||||
|     , public ResourceClient { | ||||
|     AK_MAKE_NONCOPYABLE(CSSImportRule); | ||||
|     AK_MAKE_NONMOVABLE(CSSImportRule); | ||||
|     JS_OBJECT(CSSImportRule, CSSRule); | ||||
|     WEB_PLATFORM_OBJECT(CSSImportRule, CSSRule); | ||||
| 
 | ||||
| public: | ||||
|     static CSSImportRule* create(AK::URL, DOM::Document&); | ||||
|     CSSImportRule(AK::URL, DOM::Document&); | ||||
| 
 | ||||
|     virtual ~CSSImportRule() = default; | ||||
| 
 | ||||
|     CSSImportRule& impl() { return *this; } | ||||
| 
 | ||||
|     AK::URL const& url() const { return m_url; } | ||||
|     // FIXME: This should return only the specified part of the url. eg, "stuff/foo.css", not "https://example.com/stuff/foo.css".
 | ||||
|     String href() const { return m_url.to_string(); } | ||||
|  | @ -44,6 +39,8 @@ public: | |||
|     virtual Type type() const override { return Type::Import; }; | ||||
| 
 | ||||
| private: | ||||
|     CSSImportRule(AK::URL, DOM::Document&); | ||||
| 
 | ||||
|     virtual void visit_edges(Cell::Visitor&) override; | ||||
| 
 | ||||
|     virtual String serialized() const override; | ||||
|  | @ -63,7 +60,4 @@ inline bool CSSRule::fast_is<CSSImportRule>() const { return type() == CSSRule:: | |||
| 
 | ||||
| } | ||||
| 
 | ||||
| namespace Web::Bindings { | ||||
| inline JS::Object* wrap(JS::Realm&, Web::CSS::CSSImportRule& object) { return &object; } | ||||
| using CSSImportRuleWrapper = Web::CSS::CSSImportRule; | ||||
| } | ||||
| WRAPPER_HACK(CSSImportRule, Web::CSS) | ||||
|  |  | |||
|  | @ -6,17 +6,17 @@ | |||
|  */ | ||||
| 
 | ||||
| #include <LibWeb/Bindings/CSSMediaRulePrototype.h> | ||||
| #include <LibWeb/Bindings/WindowObject.h> | ||||
| #include <LibWeb/CSS/CSSMediaRule.h> | ||||
| #include <LibWeb/HTML/Window.h> | ||||
| 
 | ||||
| namespace Web::CSS { | ||||
| 
 | ||||
| CSSMediaRule* CSSMediaRule::create(Bindings::WindowObject& window_object, MediaList& media_queries, CSSRuleList& rules) | ||||
| CSSMediaRule* CSSMediaRule::create(HTML::Window& window_object, MediaList& media_queries, CSSRuleList& rules) | ||||
| { | ||||
|     return window_object.heap().allocate<CSSMediaRule>(window_object.realm(), window_object, media_queries, rules); | ||||
| } | ||||
| 
 | ||||
| CSSMediaRule::CSSMediaRule(Bindings::WindowObject& window_object, MediaList& media, CSSRuleList& rules) | ||||
| CSSMediaRule::CSSMediaRule(HTML::Window& window_object, MediaList& media, CSSRuleList& rules) | ||||
|     : CSSConditionRule(window_object, rules) | ||||
|     , m_media(media) | ||||
| { | ||||
|  |  | |||
|  | @ -15,15 +15,10 @@ namespace Web::CSS { | |||
| 
 | ||||
| // https://www.w3.org/TR/css-conditional-3/#the-cssmediarule-interface
 | ||||
| class CSSMediaRule final : public CSSConditionRule { | ||||
|     AK_MAKE_NONCOPYABLE(CSSMediaRule); | ||||
|     AK_MAKE_NONMOVABLE(CSSMediaRule); | ||||
|     JS_OBJECT(CSSMediaRule, CSSConditionRule); | ||||
|     WEB_PLATFORM_OBJECT(CSSMediaRule, CSSConditionRule); | ||||
| 
 | ||||
| public: | ||||
|     CSSMediaRule& impl() { return *this; } | ||||
| 
 | ||||
|     static CSSMediaRule* create(Bindings::WindowObject&, MediaList& media_queries, CSSRuleList&); | ||||
|     explicit CSSMediaRule(Bindings::WindowObject&, MediaList&, CSSRuleList&); | ||||
|     static CSSMediaRule* create(HTML::Window&, MediaList& media_queries, CSSRuleList&); | ||||
| 
 | ||||
|     virtual ~CSSMediaRule() = default; | ||||
| 
 | ||||
|  | @ -38,6 +33,8 @@ public: | |||
|     bool evaluate(HTML::Window const& window) { return m_media.evaluate(window); } | ||||
| 
 | ||||
| private: | ||||
|     explicit CSSMediaRule(HTML::Window&, MediaList&, CSSRuleList&); | ||||
| 
 | ||||
|     virtual void visit_edges(Cell::Visitor&) override; | ||||
|     virtual String serialized() const override; | ||||
| 
 | ||||
|  | @ -49,7 +46,4 @@ inline bool CSSRule::fast_is<CSSMediaRule>() const { return type() == CSSRule::T | |||
| 
 | ||||
| } | ||||
| 
 | ||||
| namespace Web::Bindings { | ||||
| inline JS::Object* wrap(JS::Realm&, Web::CSS::CSSMediaRule& object) { return &object; } | ||||
| using CSSMediaRuleWrapper = Web::CSS::CSSMediaRule; | ||||
| } | ||||
| WRAPPER_HACK(CSSMediaRule, Web::CSS) | ||||
|  |  | |||
|  | @ -7,13 +7,13 @@ | |||
|  */ | ||||
| 
 | ||||
| #include <LibWeb/Bindings/CSSRulePrototype.h> | ||||
| #include <LibWeb/Bindings/WindowObject.h> | ||||
| #include <LibWeb/CSS/CSSRule.h> | ||||
| #include <LibWeb/CSS/CSSStyleSheet.h> | ||||
| #include <LibWeb/HTML/Window.h> | ||||
| 
 | ||||
| namespace Web::CSS { | ||||
| 
 | ||||
| CSSRule::CSSRule(Bindings::WindowObject& window_object) | ||||
| CSSRule::CSSRule(HTML::Window& window_object) | ||||
|     : PlatformObject(window_object.ensure_web_prototype<Bindings::CSSRulePrototype>("CSSRule")) | ||||
| { | ||||
| } | ||||
|  |  | |||
|  | @ -16,10 +16,9 @@ | |||
| namespace Web::CSS { | ||||
| 
 | ||||
| class CSSRule : public Bindings::PlatformObject { | ||||
|     JS_OBJECT(CSSRule, JS::Object); | ||||
|     WEB_PLATFORM_OBJECT(CSSRule, JS::Object); | ||||
| 
 | ||||
| public: | ||||
|     CSSRule& impl() { return *this; } | ||||
|     virtual ~CSSRule() = default; | ||||
| 
 | ||||
|     // https://drafts.csswg.org/cssom/#dom-cssrule-type
 | ||||
|  | @ -46,7 +45,7 @@ public: | |||
|     bool fast_is() const = delete; | ||||
| 
 | ||||
| protected: | ||||
|     explicit CSSRule(Bindings::WindowObject&); | ||||
|     explicit CSSRule(HTML::Window&); | ||||
| 
 | ||||
|     virtual String serialized() const = 0; | ||||
| 
 | ||||
|  | @ -58,7 +57,4 @@ protected: | |||
| 
 | ||||
| } | ||||
| 
 | ||||
| namespace Web::Bindings { | ||||
| inline JS::Object* wrap(JS::Realm&, Web::CSS::CSSRule& object) { return &object; } | ||||
| using CSSRuleWrapper = Web::CSS::CSSRule; | ||||
| } | ||||
| WRAPPER_HACK(CSSRule, Web::CSS) | ||||
|  |  | |||
|  | @ -6,17 +6,17 @@ | |||
| 
 | ||||
| #include <AK/TypeCasts.h> | ||||
| #include <LibWeb/Bindings/CSSRuleListPrototype.h> | ||||
| #include <LibWeb/Bindings/WindowObject.h> | ||||
| #include <LibWeb/CSS/CSSImportRule.h> | ||||
| #include <LibWeb/CSS/CSSMediaRule.h> | ||||
| #include <LibWeb/CSS/CSSRule.h> | ||||
| #include <LibWeb/CSS/CSSRuleList.h> | ||||
| #include <LibWeb/CSS/CSSSupportsRule.h> | ||||
| #include <LibWeb/CSS/Parser/Parser.h> | ||||
| #include <LibWeb/HTML/Window.h> | ||||
| 
 | ||||
| namespace Web::CSS { | ||||
| 
 | ||||
| CSSRuleList* CSSRuleList::create(Bindings::WindowObject& window_object, JS::MarkedVector<CSSRule*> const& rules) | ||||
| CSSRuleList* CSSRuleList::create(HTML::Window& window_object, JS::MarkedVector<CSSRule*> const& rules) | ||||
| { | ||||
|     auto* rule_list = window_object.heap().allocate<CSSRuleList>(window_object.realm(), window_object); | ||||
|     for (auto* rule : rules) | ||||
|  | @ -24,12 +24,12 @@ CSSRuleList* CSSRuleList::create(Bindings::WindowObject& window_object, JS::Mark | |||
|     return rule_list; | ||||
| } | ||||
| 
 | ||||
| CSSRuleList::CSSRuleList(Bindings::WindowObject& window_object) | ||||
| CSSRuleList::CSSRuleList(HTML::Window& window_object) | ||||
|     : Bindings::LegacyPlatformObject(window_object.ensure_web_prototype<Bindings::CSSRuleListPrototype>("CSSRuleList")) | ||||
| { | ||||
| } | ||||
| 
 | ||||
| CSSRuleList* CSSRuleList::create_empty(Bindings::WindowObject& window_object) | ||||
| CSSRuleList* CSSRuleList::create_empty(HTML::Window& window_object) | ||||
| { | ||||
|     return window_object.heap().allocate<CSSRuleList>(window_object.realm(), window_object); | ||||
| } | ||||
|  | @ -65,7 +65,7 @@ DOM::ExceptionOr<unsigned> CSSRuleList::insert_a_css_rule(Variant<StringView, CS | |||
|     CSSRule* new_rule = nullptr; | ||||
|     if (rule.has<StringView>()) { | ||||
|         new_rule = parse_css_rule( | ||||
|             CSS::Parser::ParsingContext { static_cast<Bindings::WindowObject&>(global_object()) }, | ||||
|             CSS::Parser::ParsingContext { static_cast<HTML::Window&>(global_object()) }, | ||||
|             rule.get<StringView>()); | ||||
|     } else { | ||||
|         new_rule = rule.get<CSSRule*>(); | ||||
|  |  | |||
|  | @ -20,15 +20,13 @@ namespace Web::CSS { | |||
| 
 | ||||
| // https://www.w3.org/TR/cssom/#the-cssrulelist-interface
 | ||||
| class CSSRuleList : public Bindings::LegacyPlatformObject { | ||||
|     JS_OBJECT(CSSRuleList, Bindings::LegacyPlatformObject); | ||||
|     WEB_PLATFORM_OBJECT(CSSRuleList, Bindings::LegacyPlatformObject); | ||||
| 
 | ||||
| public: | ||||
|     CSSRuleList& impl() { return *this; } | ||||
|     static CSSRuleList* create(HTML::Window&, JS::MarkedVector<CSSRule*> const&); | ||||
|     static CSSRuleList* create_empty(HTML::Window&); | ||||
| 
 | ||||
|     static CSSRuleList* create(Bindings::WindowObject&, JS::MarkedVector<CSSRule*> const&); | ||||
|     static CSSRuleList* create_empty(Bindings::WindowObject&); | ||||
| 
 | ||||
|     explicit CSSRuleList(Bindings::WindowObject&); | ||||
|     explicit CSSRuleList(HTML::Window&); | ||||
|     ~CSSRuleList() = default; | ||||
| 
 | ||||
|     CSSRule const* item(size_t index) const | ||||
|  | @ -74,7 +72,4 @@ private: | |||
| 
 | ||||
| } | ||||
| 
 | ||||
| namespace Web::Bindings { | ||||
| inline JS::Object* wrap(JS::Realm&, Web::CSS::CSSRuleList& object) { return &object; } | ||||
| using CSSRuleListWrapper = Web::CSS::CSSRuleList; | ||||
| } | ||||
| WRAPPER_HACK(CSSRuleList, Web::CSS) | ||||
|  |  | |||
|  | @ -5,25 +5,25 @@ | |||
|  */ | ||||
| 
 | ||||
| #include <LibWeb/Bindings/CSSStyleDeclarationPrototype.h> | ||||
| #include <LibWeb/Bindings/WindowObject.h> | ||||
| #include <LibWeb/CSS/CSSStyleDeclaration.h> | ||||
| #include <LibWeb/CSS/Parser/Parser.h> | ||||
| #include <LibWeb/DOM/Document.h> | ||||
| #include <LibWeb/DOM/Element.h> | ||||
| #include <LibWeb/HTML/Window.h> | ||||
| 
 | ||||
| namespace Web::CSS { | ||||
| 
 | ||||
| CSSStyleDeclaration::CSSStyleDeclaration(Bindings::WindowObject& window_object) | ||||
| CSSStyleDeclaration::CSSStyleDeclaration(HTML::Window& window_object) | ||||
|     : PlatformObject(window_object.ensure_web_prototype<Bindings::CSSStyleDeclarationPrototype>("CSSStyleDeclaration")) | ||||
| { | ||||
| } | ||||
| 
 | ||||
| PropertyOwningCSSStyleDeclaration* PropertyOwningCSSStyleDeclaration::create(Bindings::WindowObject& window_object, Vector<StyleProperty> properties, HashMap<String, StyleProperty> custom_properties) | ||||
| PropertyOwningCSSStyleDeclaration* PropertyOwningCSSStyleDeclaration::create(HTML::Window& window_object, Vector<StyleProperty> properties, HashMap<String, StyleProperty> custom_properties) | ||||
| { | ||||
|     return window_object.heap().allocate<PropertyOwningCSSStyleDeclaration>(window_object.realm(), window_object, move(properties), move(custom_properties)); | ||||
| } | ||||
| 
 | ||||
| PropertyOwningCSSStyleDeclaration::PropertyOwningCSSStyleDeclaration(Bindings::WindowObject& window_object, Vector<StyleProperty> properties, HashMap<String, StyleProperty> custom_properties) | ||||
| PropertyOwningCSSStyleDeclaration::PropertyOwningCSSStyleDeclaration(HTML::Window& window_object, Vector<StyleProperty> properties, HashMap<String, StyleProperty> custom_properties) | ||||
|     : CSSStyleDeclaration(window_object) | ||||
|     , m_properties(move(properties)) | ||||
|     , m_custom_properties(move(custom_properties)) | ||||
|  | @ -39,16 +39,22 @@ String PropertyOwningCSSStyleDeclaration::item(size_t index) const | |||
| 
 | ||||
| ElementInlineCSSStyleDeclaration* ElementInlineCSSStyleDeclaration::create(DOM::Element& element, Vector<StyleProperty> properties, HashMap<String, StyleProperty> custom_properties) | ||||
| { | ||||
|     auto& window_object = element.document().preferred_window_object(); | ||||
|     auto& window_object = element.document().window(); | ||||
|     return window_object.heap().allocate<ElementInlineCSSStyleDeclaration>(window_object.realm(), element, move(properties), move(custom_properties)); | ||||
| } | ||||
| 
 | ||||
| ElementInlineCSSStyleDeclaration::ElementInlineCSSStyleDeclaration(DOM::Element& element, Vector<StyleProperty> properties, HashMap<String, StyleProperty> custom_properties) | ||||
|     : PropertyOwningCSSStyleDeclaration(element.document().preferred_window_object(), move(properties), move(custom_properties)) | ||||
|     : PropertyOwningCSSStyleDeclaration(element.document().window(), move(properties), move(custom_properties)) | ||||
|     , m_element(element.make_weak_ptr<DOM::Element>()) | ||||
| { | ||||
| } | ||||
| 
 | ||||
| void ElementInlineCSSStyleDeclaration::visit_edges(Cell::Visitor& visitor) | ||||
| { | ||||
|     Base::visit_edges(visitor); | ||||
|     visitor.visit(m_element.ptr()); | ||||
| } | ||||
| 
 | ||||
| size_t PropertyOwningCSSStyleDeclaration::length() const | ||||
| { | ||||
|     return m_properties.size(); | ||||
|  |  | |||
|  | @ -26,13 +26,11 @@ struct StyleProperty { | |||
| }; | ||||
| 
 | ||||
| class CSSStyleDeclaration : public Bindings::PlatformObject { | ||||
|     JS_OBJECT(CSSStyleDeclaration, Bindings::PlatformObject); | ||||
|     WEB_PLATFORM_OBJECT(CSSStyleDeclaration, Bindings::PlatformObject); | ||||
| 
 | ||||
| public: | ||||
|     virtual ~CSSStyleDeclaration() = default; | ||||
| 
 | ||||
|     CSSStyleDeclaration& impl() { return *this; } | ||||
| 
 | ||||
|     virtual size_t length() const = 0; | ||||
|     virtual String item(size_t index) const = 0; | ||||
| 
 | ||||
|  | @ -57,16 +55,15 @@ public: | |||
|     virtual JS::ThrowCompletionOr<bool> internal_set(JS::PropertyKey const&, JS::Value value, JS::Value receiver) override; | ||||
| 
 | ||||
| protected: | ||||
|     CSSStyleDeclaration(Bindings::WindowObject&); | ||||
|     explicit CSSStyleDeclaration(HTML::Window&); | ||||
| }; | ||||
| 
 | ||||
| class PropertyOwningCSSStyleDeclaration : public CSSStyleDeclaration { | ||||
|     JS_OBJECT(PropertyOwningCSSStyleDeclaration, CSSStyleDeclaration); | ||||
|     WEB_PLATFORM_OBJECT(PropertyOwningCSSStyleDeclaration, CSSStyleDeclaration); | ||||
|     friend class ElementInlineCSSStyleDeclaration; | ||||
| 
 | ||||
| public: | ||||
|     static PropertyOwningCSSStyleDeclaration* create(Bindings::WindowObject&, Vector<StyleProperty>, HashMap<String, StyleProperty> custom_properties); | ||||
|     PropertyOwningCSSStyleDeclaration(Bindings::WindowObject&, Vector<StyleProperty>, HashMap<String, StyleProperty>); | ||||
|     static PropertyOwningCSSStyleDeclaration* create(HTML::Window&, Vector<StyleProperty>, HashMap<String, StyleProperty> custom_properties); | ||||
| 
 | ||||
|     virtual ~PropertyOwningCSSStyleDeclaration() override = default; | ||||
| 
 | ||||
|  | @ -86,6 +83,8 @@ public: | |||
|     virtual String serialized() const final override; | ||||
| 
 | ||||
| protected: | ||||
|     PropertyOwningCSSStyleDeclaration(HTML::Window&, Vector<StyleProperty>, HashMap<String, StyleProperty>); | ||||
| 
 | ||||
|     virtual void update_style_attribute() { } | ||||
| 
 | ||||
| private: | ||||
|  | @ -96,11 +95,10 @@ private: | |||
| }; | ||||
| 
 | ||||
| class ElementInlineCSSStyleDeclaration final : public PropertyOwningCSSStyleDeclaration { | ||||
|     JS_OBJECT(ElementInlineCSSStyleDeclaration, PropertyOwningCSSStyleDeclaration); | ||||
|     WEB_PLATFORM_OBJECT(ElementInlineCSSStyleDeclaration, PropertyOwningCSSStyleDeclaration); | ||||
| 
 | ||||
| public: | ||||
|     static ElementInlineCSSStyleDeclaration* create(DOM::Element&, Vector<StyleProperty> properties, HashMap<String, StyleProperty> custom_properties); | ||||
|     explicit ElementInlineCSSStyleDeclaration(DOM::Element&, Vector<StyleProperty> properties, HashMap<String, StyleProperty> custom_properties); | ||||
| 
 | ||||
|     virtual ~ElementInlineCSSStyleDeclaration() override = default; | ||||
| 
 | ||||
|  | @ -110,9 +108,13 @@ public: | |||
|     bool is_updating() const { return m_updating; } | ||||
| 
 | ||||
| private: | ||||
|     explicit ElementInlineCSSStyleDeclaration(DOM::Element&, Vector<StyleProperty> properties, HashMap<String, StyleProperty> custom_properties); | ||||
| 
 | ||||
|     virtual void visit_edges(Cell::Visitor&) override; | ||||
| 
 | ||||
|     virtual void update_style_attribute() override; | ||||
| 
 | ||||
|     WeakPtr<DOM::Element> m_element; | ||||
|     JS::GCPtr<DOM::Element> m_element; | ||||
| 
 | ||||
|     // https://drafts.csswg.org/cssom/#cssstyledeclaration-updating-flag
 | ||||
|     bool m_updating { false }; | ||||
|  | @ -120,7 +122,4 @@ private: | |||
| 
 | ||||
| } | ||||
| 
 | ||||
| namespace Web::Bindings { | ||||
| inline JS::Object* wrap(JS::Realm&, Web::CSS::CSSStyleDeclaration& object) { return &object; } | ||||
| using CSSStyleDeclarationWrapper = Web::CSS::CSSStyleDeclaration; | ||||
| } | ||||
| WRAPPER_HACK(CSSStyleDeclaration, Web::CSS) | ||||
|  |  | |||
|  | @ -5,18 +5,18 @@ | |||
|  */ | ||||
| 
 | ||||
| #include <LibWeb/Bindings/CSSStyleRulePrototype.h> | ||||
| #include <LibWeb/Bindings/WindowObject.h> | ||||
| #include <LibWeb/CSS/CSSStyleRule.h> | ||||
| #include <LibWeb/CSS/Parser/Parser.h> | ||||
| #include <LibWeb/HTML/Window.h> | ||||
| 
 | ||||
| namespace Web::CSS { | ||||
| 
 | ||||
| CSSStyleRule* CSSStyleRule::create(Bindings::WindowObject& window_object, NonnullRefPtrVector<Web::CSS::Selector>&& selectors, CSSStyleDeclaration& declaration) | ||||
| CSSStyleRule* CSSStyleRule::create(HTML::Window& window_object, NonnullRefPtrVector<Web::CSS::Selector>&& selectors, CSSStyleDeclaration& declaration) | ||||
| { | ||||
|     return window_object.heap().allocate<CSSStyleRule>(window_object.realm(), window_object, move(selectors), declaration); | ||||
| } | ||||
| 
 | ||||
| CSSStyleRule::CSSStyleRule(Bindings::WindowObject& window_object, NonnullRefPtrVector<Selector>&& selectors, CSSStyleDeclaration& declaration) | ||||
| CSSStyleRule::CSSStyleRule(HTML::Window& window_object, NonnullRefPtrVector<Selector>&& selectors, CSSStyleDeclaration& declaration) | ||||
|     : CSSRule(window_object) | ||||
|     , m_selectors(move(selectors)) | ||||
|     , m_declaration(declaration) | ||||
|  |  | |||
|  | @ -16,18 +16,13 @@ | |||
| namespace Web::CSS { | ||||
| 
 | ||||
| class CSSStyleRule final : public CSSRule { | ||||
|     JS_OBJECT(CSSStyleRule, CSSRule); | ||||
|     AK_MAKE_NONCOPYABLE(CSSStyleRule); | ||||
|     AK_MAKE_NONMOVABLE(CSSStyleRule); | ||||
|     WEB_PLATFORM_OBJECT(CSSStyleRule, CSSRule); | ||||
| 
 | ||||
| public: | ||||
|     static CSSStyleRule* create(Bindings::WindowObject&, NonnullRefPtrVector<Selector>&&, CSSStyleDeclaration&); | ||||
|     CSSStyleRule(Bindings::WindowObject&, NonnullRefPtrVector<Selector>&&, CSSStyleDeclaration&); | ||||
|     static CSSStyleRule* create(HTML::Window&, NonnullRefPtrVector<Selector>&&, CSSStyleDeclaration&); | ||||
| 
 | ||||
|     virtual ~CSSStyleRule() override = default; | ||||
| 
 | ||||
|     CSSStyleRule& impl() { return *this; } | ||||
| 
 | ||||
|     NonnullRefPtrVector<Selector> const& selectors() const { return m_selectors; } | ||||
|     CSSStyleDeclaration const& declaration() const { return m_declaration; } | ||||
| 
 | ||||
|  | @ -39,6 +34,8 @@ public: | |||
|     CSSStyleDeclaration* style(); | ||||
| 
 | ||||
| private: | ||||
|     CSSStyleRule(HTML::Window&, NonnullRefPtrVector<Selector>&&, CSSStyleDeclaration&); | ||||
| 
 | ||||
|     virtual void visit_edges(Cell::Visitor&) override; | ||||
|     virtual String serialized() const override; | ||||
| 
 | ||||
|  | @ -51,7 +48,4 @@ inline bool CSSRule::fast_is<CSSStyleRule>() const { return type() == CSSRule::T | |||
| 
 | ||||
| } | ||||
| 
 | ||||
| namespace Web::Bindings { | ||||
| inline JS::Object* wrap(JS::Realm&, Web::CSS::CSSStyleRule& object) { return &object; } | ||||
| using CSSStyleRuleWrapper = Web::CSS::CSSStyleRule; | ||||
| } | ||||
| WRAPPER_HACK(CSSStyleRule, Web::CSS) | ||||
|  |  | |||
|  | @ -13,12 +13,12 @@ | |||
| 
 | ||||
| namespace Web::CSS { | ||||
| 
 | ||||
| CSSStyleSheet* CSSStyleSheet::create(Bindings::WindowObject& window_object, CSSRuleList& rules, Optional<AK::URL> location) | ||||
| CSSStyleSheet* CSSStyleSheet::create(HTML::Window& window_object, CSSRuleList& rules, Optional<AK::URL> location) | ||||
| { | ||||
|     return window_object.heap().allocate<CSSStyleSheet>(window_object.realm(), window_object, rules, move(location)); | ||||
| } | ||||
| 
 | ||||
| CSSStyleSheet::CSSStyleSheet(Bindings::WindowObject& window_object, CSSRuleList& rules, Optional<AK::URL> location) | ||||
| CSSStyleSheet::CSSStyleSheet(HTML::Window& window_object, CSSRuleList& rules, Optional<AK::URL> location) | ||||
|     : StyleSheet(window_object) | ||||
|     , m_rules(&rules) | ||||
| { | ||||
|  |  | |||
|  | @ -21,16 +21,14 @@ class CSSImportRule; | |||
| class CSSStyleSheet final | ||||
|     : public StyleSheet | ||||
|     , public Weakable<CSSStyleSheet> { | ||||
|     JS_OBJECT(CSSStyleSheet, StyleSheet); | ||||
|     WEB_PLATFORM_OBJECT(CSSStyleSheet, StyleSheet); | ||||
| 
 | ||||
| public: | ||||
|     static CSSStyleSheet* create(Bindings::WindowObject&, CSSRuleList& rules, Optional<AK::URL> location); | ||||
|     static CSSStyleSheet* create(HTML::Window&, CSSRuleList& rules, Optional<AK::URL> location); | ||||
| 
 | ||||
|     explicit CSSStyleSheet(Bindings::WindowObject&, CSSRuleList&, Optional<AK::URL> location); | ||||
|     explicit CSSStyleSheet(HTML::Window&, CSSRuleList&, Optional<AK::URL> location); | ||||
|     virtual ~CSSStyleSheet() override = default; | ||||
| 
 | ||||
|     CSSStyleSheet& impl() { return *this; } | ||||
| 
 | ||||
|     void set_owner_css_rule(CSSRule* rule) { m_owner_css_rule = rule; } | ||||
| 
 | ||||
|     virtual String type() const override { return "text/css"; } | ||||
|  | @ -63,7 +61,4 @@ private: | |||
| 
 | ||||
| } | ||||
| 
 | ||||
| namespace Web::Bindings { | ||||
| inline JS::Object* wrap(JS::Realm&, Web::CSS::CSSStyleSheet& object) { return &object; } | ||||
| using CSSStyleSheetWrapper = Web::CSS::CSSStyleSheet; | ||||
| } | ||||
| WRAPPER_HACK(CSSStyleSheet, Web::CSS) | ||||
|  |  | |||
|  | @ -5,18 +5,18 @@ | |||
|  */ | ||||
| 
 | ||||
| #include <LibWeb/Bindings/CSSSupportsRulePrototype.h> | ||||
| #include <LibWeb/Bindings/WindowObject.h> | ||||
| #include <LibWeb/CSS/CSSSupportsRule.h> | ||||
| #include <LibWeb/CSS/Parser/Parser.h> | ||||
| #include <LibWeb/HTML/Window.h> | ||||
| 
 | ||||
| namespace Web::CSS { | ||||
| 
 | ||||
| CSSSupportsRule* CSSSupportsRule::create(Bindings::WindowObject& window_object, NonnullRefPtr<Supports>&& supports, CSSRuleList& rules) | ||||
| CSSSupportsRule* CSSSupportsRule::create(HTML::Window& window_object, NonnullRefPtr<Supports>&& supports, CSSRuleList& rules) | ||||
| { | ||||
|     return window_object.heap().allocate<CSSSupportsRule>(window_object.realm(), window_object, move(supports), rules); | ||||
| } | ||||
| 
 | ||||
| CSSSupportsRule::CSSSupportsRule(Bindings::WindowObject& window_object, NonnullRefPtr<Supports>&& supports, CSSRuleList& rules) | ||||
| CSSSupportsRule::CSSSupportsRule(HTML::Window& window_object, NonnullRefPtr<Supports>&& supports, CSSRuleList& rules) | ||||
|     : CSSConditionRule(window_object, rules) | ||||
|     , m_supports(move(supports)) | ||||
| { | ||||
|  |  | |||
|  | @ -17,18 +17,13 @@ namespace Web::CSS { | |||
| 
 | ||||
| // https://www.w3.org/TR/css-conditional-3/#the-csssupportsrule-interface
 | ||||
| class CSSSupportsRule final : public CSSConditionRule { | ||||
|     JS_OBJECT(CSSSupportsRule, CSSConditionRule); | ||||
|     AK_MAKE_NONCOPYABLE(CSSSupportsRule); | ||||
|     AK_MAKE_NONMOVABLE(CSSSupportsRule); | ||||
|     WEB_PLATFORM_OBJECT(CSSSupportsRule, CSSConditionRule); | ||||
| 
 | ||||
| public: | ||||
|     static CSSSupportsRule* create(Bindings::WindowObject&, NonnullRefPtr<Supports>&&, CSSRuleList&); | ||||
|     explicit CSSSupportsRule(Bindings::WindowObject&, NonnullRefPtr<Supports>&&, CSSRuleList&); | ||||
|     static CSSSupportsRule* create(HTML::Window&, NonnullRefPtr<Supports>&&, CSSRuleList&); | ||||
| 
 | ||||
|     virtual ~CSSSupportsRule() = default; | ||||
| 
 | ||||
|     CSSSupportsRule& impl() { return *this; } | ||||
| 
 | ||||
|     virtual Type type() const override { return Type::Supports; }; | ||||
| 
 | ||||
|     String condition_text() const override; | ||||
|  | @ -36,6 +31,8 @@ public: | |||
|     virtual bool condition_matches() const override { return m_supports->matches(); } | ||||
| 
 | ||||
| private: | ||||
|     explicit CSSSupportsRule(HTML::Window&, NonnullRefPtr<Supports>&&, CSSRuleList&); | ||||
| 
 | ||||
|     virtual String serialized() const override; | ||||
| 
 | ||||
|     NonnullRefPtr<Supports> m_supports; | ||||
|  | @ -46,7 +43,4 @@ inline bool CSSRule::fast_is<CSSSupportsRule>() const { return type() == CSSRule | |||
| 
 | ||||
| } | ||||
| 
 | ||||
| namespace Web::Bindings { | ||||
| inline JS::Object* wrap(JS::Realm&, Web::CSS::CSSSupportsRule& object) { return &object; } | ||||
| using CSSSupportsRuleWrapper = Web::CSS::CSSSupportsRule; | ||||
| } | ||||
| WRAPPER_HACK(CSSSupportsRule, Web::CSS) | ||||
|  |  | |||
|  | @ -6,18 +6,18 @@ | |||
|  */ | ||||
| 
 | ||||
| #include <LibWeb/Bindings/MediaListPrototype.h> | ||||
| #include <LibWeb/Bindings/WindowObject.h> | ||||
| #include <LibWeb/CSS/MediaList.h> | ||||
| #include <LibWeb/CSS/Parser/Parser.h> | ||||
| #include <LibWeb/HTML/Window.h> | ||||
| 
 | ||||
| namespace Web::CSS { | ||||
| 
 | ||||
| MediaList* MediaList::create(Bindings::WindowObject& window_object, NonnullRefPtrVector<MediaQuery>&& media) | ||||
| MediaList* MediaList::create(HTML::Window& window_object, NonnullRefPtrVector<MediaQuery>&& media) | ||||
| { | ||||
|     return window_object.heap().allocate<MediaList>(window_object.realm(), window_object, move(media)); | ||||
| } | ||||
| 
 | ||||
| MediaList::MediaList(Bindings::WindowObject& window_object, NonnullRefPtrVector<MediaQuery>&& media) | ||||
| MediaList::MediaList(HTML::Window& window_object, NonnullRefPtrVector<MediaQuery>&& media) | ||||
|     : Bindings::LegacyPlatformObject(window_object.ensure_web_prototype<Bindings::MediaListPrototype>("MediaList")) | ||||
|     , m_media(move(media)) | ||||
| { | ||||
|  |  | |||
|  | @ -17,17 +17,12 @@ namespace Web::CSS { | |||
| 
 | ||||
| // https://www.w3.org/TR/cssom-1/#the-medialist-interface
 | ||||
| class MediaList final : public Bindings::LegacyPlatformObject { | ||||
|     AK_MAKE_NONCOPYABLE(MediaList); | ||||
|     AK_MAKE_NONMOVABLE(MediaList); | ||||
|     JS_OBJECT(MediaList, Bindings::LegacyPlatformObject); | ||||
|     WEB_PLATFORM_OBJECT(MediaList, Bindings::LegacyPlatformObject); | ||||
| 
 | ||||
| public: | ||||
|     static MediaList* create(Bindings::WindowObject&, NonnullRefPtrVector<MediaQuery>&& media); | ||||
|     explicit MediaList(Bindings::WindowObject&, NonnullRefPtrVector<MediaQuery>&&); | ||||
|     static MediaList* create(HTML::Window&, NonnullRefPtrVector<MediaQuery>&& media); | ||||
|     ~MediaList() = default; | ||||
| 
 | ||||
|     MediaList& impl() { return *this; } | ||||
| 
 | ||||
|     String media_text() const; | ||||
|     void set_media_text(String const&); | ||||
|     size_t length() const { return m_media.size(); } | ||||
|  | @ -42,12 +37,11 @@ public: | |||
|     bool matches() const; | ||||
| 
 | ||||
| private: | ||||
|     explicit MediaList(HTML::Window&, NonnullRefPtrVector<MediaQuery>&&); | ||||
| 
 | ||||
|     NonnullRefPtrVector<MediaQuery> m_media; | ||||
| }; | ||||
| 
 | ||||
| } | ||||
| 
 | ||||
| namespace Web::Bindings { | ||||
| inline JS::Object* wrap(JS::Realm&, Web::CSS::MediaList& object) { return &object; } | ||||
| using MediaListWrapper = Web::CSS::MediaList; | ||||
| } | ||||
| WRAPPER_HACK(MediaList, Web::CSS) | ||||
|  |  | |||
|  | @ -5,7 +5,7 @@ | |||
|  * SPDX-License-Identifier: BSD-2-Clause | ||||
|  */ | ||||
| 
 | ||||
| #include <LibWeb/Bindings/MediaQueryListWrapper.h> | ||||
| #include <LibWeb/Bindings/MediaQueryListPrototype.h> | ||||
| #include <LibWeb/CSS/MediaQueryList.h> | ||||
| #include <LibWeb/DOM/Document.h> | ||||
| #include <LibWeb/DOM/EventDispatcher.h> | ||||
|  | @ -14,14 +14,26 @@ | |||
| 
 | ||||
| namespace Web::CSS { | ||||
| 
 | ||||
| JS::NonnullGCPtr<MediaQueryList> MediaQueryList::create(DOM::Document& document, NonnullRefPtrVector<MediaQuery>&& media) | ||||
| { | ||||
|     return *document.heap().allocate<MediaQueryList>(document.realm(), document, move(media)); | ||||
| } | ||||
| 
 | ||||
| MediaQueryList::MediaQueryList(DOM::Document& document, NonnullRefPtrVector<MediaQuery>&& media) | ||||
|     : DOM::EventTarget() | ||||
|     : DOM::EventTarget(document.realm()) | ||||
|     , m_document(document) | ||||
|     , m_media(move(media)) | ||||
| { | ||||
|     set_prototype(&document.window().ensure_web_prototype<Bindings::MediaQueryListPrototype>("MediaQueryList")); | ||||
|     evaluate(); | ||||
| } | ||||
| 
 | ||||
| void MediaQueryList::visit_edges(Cell::Visitor& visitor) | ||||
| { | ||||
|     Base::visit_edges(visitor); | ||||
|     visitor.visit(m_document.ptr()); | ||||
| } | ||||
| 
 | ||||
| // https://drafts.csswg.org/cssom-view/#dom-mediaquerylist-media
 | ||||
| String MediaQueryList::media() const | ||||
| { | ||||
|  | @ -40,9 +52,6 @@ bool MediaQueryList::matches() const | |||
| 
 | ||||
| bool MediaQueryList::evaluate() | ||||
| { | ||||
|     if (!m_document) | ||||
|         return false; | ||||
| 
 | ||||
|     bool now_matches = false; | ||||
|     for (auto& media : m_media) { | ||||
|         now_matches = now_matches || media.evaluate(m_document->window()); | ||||
|  | @ -51,11 +60,6 @@ bool MediaQueryList::evaluate() | |||
|     return now_matches; | ||||
| } | ||||
| 
 | ||||
| JS::Object* MediaQueryList::create_wrapper(JS::Realm& realm) | ||||
| { | ||||
|     return wrap(realm, *this); | ||||
| } | ||||
| 
 | ||||
| // https://www.w3.org/TR/cssom-view/#dom-mediaquerylist-addlistener
 | ||||
| void MediaQueryList::add_listener(DOM::IDLEventListener* listener) | ||||
| { | ||||
|  |  | |||
|  | @ -17,22 +17,11 @@ | |||
| namespace Web::CSS { | ||||
| 
 | ||||
| // 4.2. The MediaQueryList Interface, https://drafts.csswg.org/cssom-view/#the-mediaquerylist-interface
 | ||||
| class MediaQueryList final | ||||
|     : public RefCounted<MediaQueryList> | ||||
|     , public Weakable<MediaQueryList> | ||||
|     , public DOM::EventTarget | ||||
|     , public Bindings::Wrappable { | ||||
| class MediaQueryList final : public DOM::EventTarget { | ||||
|     WEB_PLATFORM_OBJECT(MediaQueryList, DOM::EventTarget); | ||||
| 
 | ||||
| public: | ||||
|     using WrapperType = Bindings::MediaQueryListWrapper; | ||||
| 
 | ||||
|     using RefCounted::ref; | ||||
|     using RefCounted::unref; | ||||
| 
 | ||||
|     static NonnullRefPtr<MediaQueryList> create(DOM::Document& document, NonnullRefPtrVector<MediaQuery>&& media_queries) | ||||
|     { | ||||
|         return adopt_ref(*new MediaQueryList(document, move(media_queries))); | ||||
|     } | ||||
|     static JS::NonnullGCPtr<MediaQueryList> create(DOM::Document&, NonnullRefPtrVector<MediaQuery>&&); | ||||
| 
 | ||||
|     virtual ~MediaQueryList() override = default; | ||||
| 
 | ||||
|  | @ -40,11 +29,6 @@ public: | |||
|     bool matches() const; | ||||
|     bool evaluate(); | ||||
| 
 | ||||
|     // ^EventTarget
 | ||||
|     virtual void ref_event_target() override { ref(); } | ||||
|     virtual void unref_event_target() override { unref(); } | ||||
|     virtual JS::Object* create_wrapper(JS::Realm&) override; | ||||
| 
 | ||||
|     void add_listener(DOM::IDLEventListener*); | ||||
|     void remove_listener(DOM::IDLEventListener*); | ||||
| 
 | ||||
|  | @ -54,14 +38,12 @@ public: | |||
| private: | ||||
|     MediaQueryList(DOM::Document&, NonnullRefPtrVector<MediaQuery>&&); | ||||
| 
 | ||||
|     WeakPtr<DOM::Document> m_document; | ||||
|     virtual void visit_edges(Cell::Visitor&) override; | ||||
| 
 | ||||
|     JS::NonnullGCPtr<DOM::Document> m_document; | ||||
|     NonnullRefPtrVector<MediaQuery> m_media; | ||||
| }; | ||||
| 
 | ||||
| } | ||||
| 
 | ||||
| namespace Web::Bindings { | ||||
| 
 | ||||
| MediaQueryListWrapper* wrap(JS::Realm&, CSS::MediaQueryList&); | ||||
| 
 | ||||
| } | ||||
| WRAPPER_HACK(MediaQueryList, Web::CSS) | ||||
|  |  | |||
|  | @ -5,22 +5,22 @@ | |||
|  */ | ||||
| 
 | ||||
| #include <LibWeb/Bindings/MediaQueryListEventPrototype.h> | ||||
| #include <LibWeb/Bindings/WindowObject.h> | ||||
| #include <LibWeb/CSS/MediaQueryListEvent.h> | ||||
| #include <LibWeb/HTML/Window.h> | ||||
| 
 | ||||
| namespace Web::CSS { | ||||
| 
 | ||||
| MediaQueryListEvent* MediaQueryListEvent::create(Bindings::WindowObject& window_object, FlyString const& event_name, MediaQueryListEventInit const& event_init) | ||||
| MediaQueryListEvent* MediaQueryListEvent::create(HTML::Window& window_object, FlyString const& event_name, MediaQueryListEventInit const& event_init) | ||||
| { | ||||
|     return window_object.heap().allocate<MediaQueryListEvent>(window_object.realm(), window_object, event_name, event_init); | ||||
| } | ||||
| 
 | ||||
| MediaQueryListEvent* MediaQueryListEvent::create_with_global_object(Bindings::WindowObject& window_object, FlyString const& event_name, MediaQueryListEventInit const& event_init) | ||||
| MediaQueryListEvent* MediaQueryListEvent::create_with_global_object(HTML::Window& window_object, FlyString const& event_name, MediaQueryListEventInit const& event_init) | ||||
| { | ||||
|     return create(window_object, event_name, event_init); | ||||
| } | ||||
| 
 | ||||
| MediaQueryListEvent::MediaQueryListEvent(Bindings::WindowObject& window_object, FlyString const& event_name, MediaQueryListEventInit const& event_init) | ||||
| MediaQueryListEvent::MediaQueryListEvent(HTML::Window& window_object, FlyString const& event_name, MediaQueryListEventInit const& event_init) | ||||
|     : DOM::Event(window_object, event_name, event_init) | ||||
|     , m_media(event_init.media) | ||||
|     , m_matches(event_init.matches) | ||||
|  |  | |||
|  | @ -16,17 +16,15 @@ struct MediaQueryListEventInit : public DOM::EventInit { | |||
| }; | ||||
| 
 | ||||
| class MediaQueryListEvent final : public DOM::Event { | ||||
|     JS_OBJECT(MediaQueryListEvent, DOM::Event); | ||||
|     WEB_PLATFORM_OBJECT(MediaQueryListEvent, DOM::Event); | ||||
| 
 | ||||
| public: | ||||
|     static MediaQueryListEvent* create(Bindings::WindowObject&, FlyString const& event_name, MediaQueryListEventInit const& event_init = {}); | ||||
|     static MediaQueryListEvent* create_with_global_object(Bindings::WindowObject&, FlyString const& event_name, MediaQueryListEventInit const& event_init); | ||||
|     static MediaQueryListEvent* create(HTML::Window&, FlyString const& event_name, MediaQueryListEventInit const& event_init = {}); | ||||
|     static MediaQueryListEvent* create_with_global_object(HTML::Window&, FlyString const& event_name, MediaQueryListEventInit const& event_init); | ||||
| 
 | ||||
|     MediaQueryListEvent(Bindings::WindowObject&, FlyString const& event_name, MediaQueryListEventInit const& event_init); | ||||
|     MediaQueryListEvent(HTML::Window&, FlyString const& event_name, MediaQueryListEventInit const& event_init); | ||||
|     virtual ~MediaQueryListEvent() override; | ||||
| 
 | ||||
|     MediaQueryListEvent& impl() { return *this; } | ||||
| 
 | ||||
|     String const& media() const { return m_media; } | ||||
|     bool matches() const { return m_matches; } | ||||
| 
 | ||||
|  |  | |||
|  | @ -44,27 +44,27 @@ ParsingContext::ParsingContext() | |||
| { | ||||
| } | ||||
| 
 | ||||
| ParsingContext::ParsingContext(Bindings::WindowObject& window_object) | ||||
| ParsingContext::ParsingContext(HTML::Window& window_object) | ||||
|     : m_window_object(window_object) | ||||
| { | ||||
| } | ||||
| 
 | ||||
| ParsingContext::ParsingContext(DOM::Document const& document, AK::URL url) | ||||
|     : m_window_object(document.preferred_window_object()) | ||||
|     : m_window_object(const_cast<HTML::Window&>(document.window())) | ||||
|     , m_document(&document) | ||||
|     , m_url(move(url)) | ||||
| { | ||||
| } | ||||
| 
 | ||||
| ParsingContext::ParsingContext(DOM::Document const& document) | ||||
|     : m_window_object(document.preferred_window_object()) | ||||
|     : m_window_object(const_cast<HTML::Window&>(document.window())) | ||||
|     , m_document(&document) | ||||
|     , m_url(document.url()) | ||||
| { | ||||
| } | ||||
| 
 | ||||
| ParsingContext::ParsingContext(DOM::ParentNode& parent_node) | ||||
|     : m_window_object(parent_node.document().preferred_window_object()) | ||||
|     : m_window_object(parent_node.document().window()) | ||||
|     , m_document(&parent_node.document()) | ||||
|     , m_url(parent_node.document().url()) | ||||
| { | ||||
|  |  | |||
|  | @ -35,7 +35,7 @@ namespace Web::CSS::Parser { | |||
| class ParsingContext { | ||||
| public: | ||||
|     ParsingContext(); | ||||
|     explicit ParsingContext(Bindings::WindowObject&); | ||||
|     explicit ParsingContext(HTML::Window&); | ||||
|     explicit ParsingContext(DOM::Document const&); | ||||
|     explicit ParsingContext(DOM::Document const&, AK::URL); | ||||
|     explicit ParsingContext(DOM::ParentNode&); | ||||
|  | @ -47,10 +47,10 @@ public: | |||
|     PropertyID current_property_id() const { return m_current_property_id; } | ||||
|     void set_current_property_id(PropertyID property_id) { m_current_property_id = property_id; } | ||||
| 
 | ||||
|     Bindings::WindowObject& window_object() const { return m_window_object; } | ||||
|     HTML::Window& window_object() const { return m_window_object; } | ||||
| 
 | ||||
| private: | ||||
|     Bindings::WindowObject& m_window_object; | ||||
|     HTML::Window& m_window_object; | ||||
|     DOM::Document const* m_document { nullptr }; | ||||
|     PropertyID m_current_property_id { PropertyID::Invalid }; | ||||
|     AK::URL m_url; | ||||
|  |  | |||
|  | @ -21,16 +21,22 @@ namespace Web::CSS { | |||
| 
 | ||||
| ResolvedCSSStyleDeclaration* ResolvedCSSStyleDeclaration::create(DOM::Element& element) | ||||
| { | ||||
|     auto& window_object = element.document().preferred_window_object(); | ||||
|     auto& window_object = element.document().window(); | ||||
|     return window_object.heap().allocate<ResolvedCSSStyleDeclaration>(window_object.realm(), element); | ||||
| } | ||||
| 
 | ||||
| ResolvedCSSStyleDeclaration::ResolvedCSSStyleDeclaration(DOM::Element& element) | ||||
|     : CSSStyleDeclaration(element.document().preferred_window_object()) | ||||
|     : CSSStyleDeclaration(element.document().window()) | ||||
|     , m_element(element) | ||||
| { | ||||
| } | ||||
| 
 | ||||
| void ResolvedCSSStyleDeclaration::visit_edges(Cell::Visitor& visitor) | ||||
| { | ||||
|     Base::visit_edges(visitor); | ||||
|     visitor.visit(m_element.ptr()); | ||||
| } | ||||
| 
 | ||||
| size_t ResolvedCSSStyleDeclaration::length() const | ||||
| { | ||||
|     return 0; | ||||
|  |  | |||
|  | @ -11,7 +11,7 @@ | |||
| namespace Web::CSS { | ||||
| 
 | ||||
| class ResolvedCSSStyleDeclaration final : public CSSStyleDeclaration { | ||||
|     JS_OBJECT(ResolvedCSSStyleDeclaration, CSSStyleDeclaration); | ||||
|     WEB_PLATFORM_OBJECT(ResolvedCSSStyleDeclaration, CSSStyleDeclaration); | ||||
| 
 | ||||
| public: | ||||
|     static ResolvedCSSStyleDeclaration* create(DOM::Element& element); | ||||
|  | @ -28,9 +28,11 @@ public: | |||
|     virtual String serialized() const override; | ||||
| 
 | ||||
| private: | ||||
|     virtual void visit_edges(Cell::Visitor&) override; | ||||
| 
 | ||||
|     RefPtr<StyleValue> style_value_for_property(Layout::NodeWithStyle const&, PropertyID) const; | ||||
| 
 | ||||
|     NonnullRefPtr<DOM::Element> m_element; | ||||
|     JS::NonnullGCPtr<DOM::Element> m_element; | ||||
| }; | ||||
| 
 | ||||
| } | ||||
|  |  | |||
|  | @ -12,7 +12,7 @@ | |||
| namespace Web::CSS { | ||||
| 
 | ||||
| Screen::Screen(HTML::Window& window) | ||||
|     : RefCountForwarder(window) | ||||
|     : m_window(JS::make_handle(window)) | ||||
| { | ||||
| } | ||||
| 
 | ||||
|  |  | |||
|  | @ -15,7 +15,7 @@ | |||
| namespace Web::CSS { | ||||
| 
 | ||||
| class Screen final | ||||
|     : public RefCountForwarder<HTML::Window> | ||||
|     : public RefCounted<Screen> | ||||
|     , public Bindings::Wrappable { | ||||
| 
 | ||||
| public: | ||||
|  | @ -37,9 +37,11 @@ public: | |||
| private: | ||||
|     explicit Screen(HTML::Window&); | ||||
| 
 | ||||
|     HTML::Window const& window() const { return ref_count_target(); } | ||||
|     HTML::Window const& window() const { return *m_window; } | ||||
| 
 | ||||
|     Gfx::IntRect screen_rect() const; | ||||
| 
 | ||||
|     JS::Handle<HTML::Window> m_window; | ||||
| }; | ||||
| 
 | ||||
| } | ||||
|  |  | |||
|  | @ -6,14 +6,14 @@ | |||
|  */ | ||||
| 
 | ||||
| #include <LibWeb/Bindings/StyleSheetPrototype.h> | ||||
| #include <LibWeb/Bindings/WindowObject.h> | ||||
| #include <LibWeb/CSS/CSSStyleSheet.h> | ||||
| #include <LibWeb/CSS/StyleSheet.h> | ||||
| #include <LibWeb/DOM/Element.h> | ||||
| #include <LibWeb/HTML/Window.h> | ||||
| 
 | ||||
| namespace Web::CSS { | ||||
| 
 | ||||
| StyleSheet::StyleSheet(Bindings::WindowObject& window_object) | ||||
| StyleSheet::StyleSheet(HTML::Window& window_object) | ||||
|     : PlatformObject(window_object.ensure_web_prototype<Bindings::StyleSheetPrototype>("StyleSheet")) | ||||
| { | ||||
| } | ||||
|  |  | |||
|  | @ -13,11 +13,9 @@ | |||
| namespace Web::CSS { | ||||
| 
 | ||||
| class StyleSheet : public Bindings::PlatformObject { | ||||
|     JS_OBJECT(StyleSheet, Bindings::PlatformObject); | ||||
|     WEB_PLATFORM_OBJECT(StyleSheet, Bindings::PlatformObject); | ||||
| 
 | ||||
| public: | ||||
|     StyleSheet& impl() { return *this; } | ||||
| 
 | ||||
|     virtual ~StyleSheet() = default; | ||||
| 
 | ||||
|     virtual String type() const = 0; | ||||
|  | @ -48,7 +46,7 @@ public: | |||
|     void set_parent_css_style_sheet(CSSStyleSheet*); | ||||
| 
 | ||||
| protected: | ||||
|     explicit StyleSheet(Bindings::WindowObject&); | ||||
|     explicit StyleSheet(HTML::Window&); | ||||
|     virtual void visit_edges(Cell::Visitor&) override; | ||||
| 
 | ||||
| private: | ||||
|  | @ -68,7 +66,4 @@ private: | |||
| 
 | ||||
| } | ||||
| 
 | ||||
| namespace Web::Bindings { | ||||
| inline JS::Object* wrap(JS::Realm&, Web::CSS::StyleSheet& object) { return &object; } | ||||
| using StyleSheetWrapper = Web::CSS::StyleSheet; | ||||
| } | ||||
| WRAPPER_HACK(StyleSheet, Web::CSS) | ||||
|  |  | |||
|  | @ -31,12 +31,12 @@ void StyleSheetList::remove_sheet(CSSStyleSheet& sheet) | |||
| 
 | ||||
| StyleSheetList* StyleSheetList::create(DOM::Document& document) | ||||
| { | ||||
|     auto& realm = document.preferred_window_object().realm(); | ||||
|     auto& realm = document.window().realm(); | ||||
|     return realm.heap().allocate<StyleSheetList>(realm, document); | ||||
| } | ||||
| 
 | ||||
| StyleSheetList::StyleSheetList(DOM::Document& document) | ||||
|     : Bindings::LegacyPlatformObject(document.preferred_window_object().ensure_web_prototype<Bindings::StyleSheetListPrototype>("StyleSheetList")) | ||||
|     : Bindings::LegacyPlatformObject(document.window().ensure_web_prototype<Bindings::StyleSheetListPrototype>("StyleSheetList")) | ||||
|     , m_document(document) | ||||
| { | ||||
| } | ||||
|  |  | |||
|  | @ -16,12 +16,10 @@ | |||
| namespace Web::CSS { | ||||
| 
 | ||||
| class StyleSheetList : public Bindings::LegacyPlatformObject { | ||||
|     JS_OBJECT(StyleSheetList, Bindings::LegacyPlatformObject); | ||||
|     WEB_PLATFORM_OBJECT(StyleSheetList, Bindings::LegacyPlatformObject); | ||||
| 
 | ||||
| public: | ||||
|     StyleSheetList& impl() { return *this; } | ||||
|     static StyleSheetList* create(DOM::Document& document); | ||||
|     explicit StyleSheetList(DOM::Document&); | ||||
| 
 | ||||
|     void add_sheet(CSSStyleSheet&); | ||||
|     void remove_sheet(CSSStyleSheet&); | ||||
|  | @ -45,6 +43,8 @@ public: | |||
|     DOM::Document const& document() const { return m_document; } | ||||
| 
 | ||||
| private: | ||||
|     explicit StyleSheetList(DOM::Document&); | ||||
| 
 | ||||
|     virtual void visit_edges(Cell::Visitor&) override; | ||||
| 
 | ||||
|     DOM::Document& m_document; | ||||
|  | @ -53,7 +53,4 @@ private: | |||
| 
 | ||||
| } | ||||
| 
 | ||||
| namespace Web::Bindings { | ||||
| inline JS::Object* wrap(JS::Realm&, Web::CSS::StyleSheetList& object) { return &object; } | ||||
| using StyleSheetListWrapper = Web::CSS::StyleSheetList; | ||||
| } | ||||
| WRAPPER_HACK(StyleSheetList, Web::CSS) | ||||
|  |  | |||
|  | @ -10,8 +10,8 @@ | |||
| namespace Web::DOM { | ||||
| 
 | ||||
| // https://dom.spec.whatwg.org/#dom-abortcontroller-abortcontroller
 | ||||
| AbortController::AbortController() | ||||
|     : m_signal(AbortSignal::create()) | ||||
| AbortController::AbortController(HTML::Window& window) | ||||
|     : m_signal(JS::make_handle(*AbortSignal::create_with_global_object(window))) | ||||
| { | ||||
| } | ||||
| 
 | ||||
|  |  | |||
|  | @ -8,7 +8,6 @@ | |||
| 
 | ||||
| #include <AK/RefCounted.h> | ||||
| #include <AK/Weakable.h> | ||||
| #include <LibWeb/Bindings/WindowObject.h> | ||||
| #include <LibWeb/Bindings/Wrappable.h> | ||||
| #include <LibWeb/DOM/AbortSignal.h> | ||||
| #include <LibWeb/Forward.h> | ||||
|  | @ -24,28 +23,23 @@ class AbortController final | |||
| public: | ||||
|     using WrapperType = Bindings::AbortControllerWrapper; | ||||
| 
 | ||||
|     static NonnullRefPtr<AbortController> create() | ||||
|     static NonnullRefPtr<AbortController> create_with_global_object(HTML::Window& window) | ||||
|     { | ||||
|         return adopt_ref(*new AbortController()); | ||||
|     } | ||||
| 
 | ||||
|     static NonnullRefPtr<AbortController> create_with_global_object(Bindings::WindowObject&) | ||||
|     { | ||||
|         return AbortController::create(); | ||||
|         return adopt_ref(*new AbortController(window)); | ||||
|     } | ||||
| 
 | ||||
|     virtual ~AbortController() override = default; | ||||
| 
 | ||||
|     // https://dom.spec.whatwg.org/#dom-abortcontroller-signal
 | ||||
|     NonnullRefPtr<AbortSignal> signal() const { return m_signal; } | ||||
|     JS::NonnullGCPtr<AbortSignal> signal() const { return *m_signal; } | ||||
| 
 | ||||
|     void abort(JS::Value reason); | ||||
| 
 | ||||
| private: | ||||
|     AbortController(); | ||||
|     explicit AbortController(HTML::Window&); | ||||
| 
 | ||||
|     // https://dom.spec.whatwg.org/#abortcontroller-signal
 | ||||
|     NonnullRefPtr<AbortSignal> m_signal; | ||||
|     JS::Handle<AbortSignal> m_signal; | ||||
| }; | ||||
| 
 | ||||
| } | ||||
|  |  | |||
|  | @ -4,7 +4,6 @@ | |||
|  * SPDX-License-Identifier: BSD-2-Clause | ||||
|  */ | ||||
| 
 | ||||
| #include <LibWeb/Bindings/AbortSignalWrapper.h> | ||||
| #include <LibWeb/Bindings/DOMExceptionWrapper.h> | ||||
| #include <LibWeb/Bindings/Wrapper.h> | ||||
| #include <LibWeb/DOM/AbortSignal.h> | ||||
|  | @ -14,14 +13,14 @@ | |||
| 
 | ||||
| namespace Web::DOM { | ||||
| 
 | ||||
| AbortSignal::AbortSignal() | ||||
|     : EventTarget() | ||||
| JS::NonnullGCPtr<AbortSignal> AbortSignal::create_with_global_object(HTML::Window& window) | ||||
| { | ||||
|     return *window.heap().allocate<AbortSignal>(window.realm(), window); | ||||
| } | ||||
| 
 | ||||
| JS::Object* AbortSignal::create_wrapper(JS::Realm& realm) | ||||
| AbortSignal::AbortSignal(HTML::Window& window) | ||||
|     : EventTarget(window.realm()) | ||||
| { | ||||
|     return wrap(realm, *this); | ||||
| } | ||||
| 
 | ||||
| // https://dom.spec.whatwg.org/#abortsignal-add
 | ||||
|  | @ -38,10 +37,6 @@ void AbortSignal::add_abort_algorithm(Function<void()> abort_algorithm) | |||
| // https://dom.spec.whatwg.org/#abortsignal-signal-abort
 | ||||
| void AbortSignal::signal_abort(JS::Value reason) | ||||
| { | ||||
|     VERIFY(wrapper()); | ||||
|     auto& vm = wrapper()->vm(); | ||||
|     auto& realm = *vm.current_realm(); | ||||
| 
 | ||||
|     // 1. If signal is aborted, then return.
 | ||||
|     if (aborted()) | ||||
|         return; | ||||
|  | @ -50,7 +45,7 @@ void AbortSignal::signal_abort(JS::Value reason) | |||
|     if (!reason.is_undefined()) | ||||
|         m_abort_reason = reason; | ||||
|     else | ||||
|         m_abort_reason = wrap(realm, AbortError::create("Aborted without reason")); | ||||
|         m_abort_reason = wrap(realm(), AbortError::create("Aborted without reason")); | ||||
| 
 | ||||
|     // 3. For each algorithm in signal’s abort algorithms: run algorithm.
 | ||||
|     for (auto& algorithm : m_abort_algorithms) | ||||
|  | @ -60,7 +55,7 @@ void AbortSignal::signal_abort(JS::Value reason) | |||
|     m_abort_algorithms.clear(); | ||||
| 
 | ||||
|     // 5. Fire an event named abort at signal.
 | ||||
|     dispatch_event(*Event::create(verify_cast<Bindings::WindowObject>(wrapper()->global_object()), HTML::EventNames::abort)); | ||||
|     dispatch_event(*Event::create(global_object(), HTML::EventNames::abort)); | ||||
| } | ||||
| 
 | ||||
| void AbortSignal::set_onabort(Bindings::CallbackType* event_handler) | ||||
|  | @ -85,6 +80,7 @@ JS::ThrowCompletionOr<void> AbortSignal::throw_if_aborted() const | |||
| 
 | ||||
| void AbortSignal::visit_edges(JS::Cell::Visitor& visitor) | ||||
| { | ||||
|     Base::visit_edges(visitor); | ||||
|     visitor.visit(m_abort_reason); | ||||
| } | ||||
| 
 | ||||
|  |  | |||
|  | @ -16,26 +16,11 @@ | |||
| namespace Web::DOM { | ||||
| 
 | ||||
| // https://dom.spec.whatwg.org/#abortsignal
 | ||||
| class AbortSignal final | ||||
|     : public RefCounted<AbortSignal> | ||||
|     , public Weakable<AbortSignal> | ||||
|     , public EventTarget | ||||
|     , public Bindings::Wrappable { | ||||
| class AbortSignal final : public EventTarget { | ||||
|     WEB_PLATFORM_OBJECT(AbortSignal, EventTarget); | ||||
| 
 | ||||
| public: | ||||
|     using WrapperType = Bindings::AbortSignalWrapper; | ||||
| 
 | ||||
|     using RefCounted::ref; | ||||
|     using RefCounted::unref; | ||||
| 
 | ||||
|     static NonnullRefPtr<AbortSignal> create() | ||||
|     { | ||||
|         return adopt_ref(*new AbortSignal()); | ||||
|     } | ||||
| 
 | ||||
|     static NonnullRefPtr<AbortSignal> create_with_global_object(Bindings::WindowObject&) | ||||
|     { | ||||
|         return AbortSignal::create(); | ||||
|     } | ||||
|     static JS::NonnullGCPtr<AbortSignal> create_with_global_object(HTML::Window&); | ||||
| 
 | ||||
|     virtual ~AbortSignal() override = default; | ||||
| 
 | ||||
|  | @ -55,15 +40,10 @@ public: | |||
| 
 | ||||
|     JS::ThrowCompletionOr<void> throw_if_aborted() const; | ||||
| 
 | ||||
|     void visit_edges(JS::Cell::Visitor&); | ||||
| 
 | ||||
|     // ^EventTarget
 | ||||
|     virtual void ref_event_target() override { ref(); } | ||||
|     virtual void unref_event_target() override { unref(); } | ||||
|     virtual JS::Object* create_wrapper(JS::Realm&) override; | ||||
| 
 | ||||
| private: | ||||
|     AbortSignal(); | ||||
|     explicit AbortSignal(HTML::Window&); | ||||
| 
 | ||||
|     virtual void visit_edges(JS::Cell::Visitor&) override; | ||||
| 
 | ||||
|     // https://dom.spec.whatwg.org/#abortsignal-abort-reason
 | ||||
|     // An AbortSignal object has an associated abort reason, which is a JavaScript value. It is undefined unless specified otherwise.
 | ||||
|  | @ -75,3 +55,5 @@ private: | |||
| }; | ||||
| 
 | ||||
| } | ||||
| 
 | ||||
| WRAPPER_HACK(AbortSignal, Web::DOM) | ||||
|  |  | |||
|  | @ -5,14 +5,14 @@ | |||
|  */ | ||||
| 
 | ||||
| #include <LibWeb/Bindings/AbstractRangePrototype.h> | ||||
| #include <LibWeb/Bindings/WindowObject.h> | ||||
| #include <LibWeb/DOM/AbstractRange.h> | ||||
| #include <LibWeb/DOM/Document.h> | ||||
| #include <LibWeb/HTML/Window.h> | ||||
| 
 | ||||
| namespace Web::DOM { | ||||
| 
 | ||||
| AbstractRange::AbstractRange(Node& start_container, u32 start_offset, Node& end_container, u32 end_offset) | ||||
|     : Bindings::PlatformObject(start_container.document().preferred_window_object().ensure_web_prototype<Bindings::AbstractRangePrototype>("AbstractRange")) | ||||
|     : Bindings::PlatformObject(start_container.document().window().ensure_web_prototype<Bindings::AbstractRangePrototype>("AbstractRange")) | ||||
|     , m_start_container(start_container) | ||||
|     , m_start_offset(start_offset) | ||||
|     , m_end_container(end_container) | ||||
|  | @ -22,4 +22,11 @@ AbstractRange::AbstractRange(Node& start_container, u32 start_offset, Node& end_ | |||
| 
 | ||||
| AbstractRange::~AbstractRange() = default; | ||||
| 
 | ||||
| void AbstractRange::visit_edges(Cell::Visitor& visitor) | ||||
| { | ||||
|     Base::visit_edges(visitor); | ||||
|     visitor.visit(m_start_container.ptr()); | ||||
|     visitor.visit(m_end_container.ptr()); | ||||
| } | ||||
| 
 | ||||
| } | ||||
|  |  | |||
|  | @ -13,19 +13,17 @@ | |||
| namespace Web::DOM { | ||||
| 
 | ||||
| class AbstractRange : public Bindings::PlatformObject { | ||||
|     JS_OBJECT(AbstractRange, Bindings::PlatformObject); | ||||
|     WEB_PLATFORM_OBJECT(AbstractRange, Bindings::PlatformObject); | ||||
| 
 | ||||
| public: | ||||
|     virtual ~AbstractRange() override; | ||||
| 
 | ||||
|     AbstractRange& impl() { return *this; } | ||||
| 
 | ||||
|     Node* start_container() { return m_start_container; } | ||||
|     Node const* start_container() const { return m_start_container; } | ||||
|     Node* start_container() { return m_start_container.ptr(); } | ||||
|     Node const* start_container() const { return m_start_container.ptr(); } | ||||
|     unsigned start_offset() const { return m_start_offset; } | ||||
| 
 | ||||
|     Node* end_container() { return m_end_container; } | ||||
|     Node const* end_container() const { return m_end_container; } | ||||
|     Node* end_container() { return m_end_container.ptr(); } | ||||
|     Node const* end_container() const { return m_end_container.ptr(); } | ||||
|     unsigned end_offset() const { return m_end_offset; } | ||||
| 
 | ||||
|     // https://dom.spec.whatwg.org/#range-collapsed
 | ||||
|  | @ -38,10 +36,12 @@ public: | |||
| protected: | ||||
|     AbstractRange(Node& start_container, u32 start_offset, Node& end_container, u32 end_offset); | ||||
| 
 | ||||
|     NonnullRefPtr<Node> m_start_container; | ||||
|     virtual void visit_edges(Cell::Visitor&) override; | ||||
| 
 | ||||
|     JS::NonnullGCPtr<Node> m_start_container; | ||||
|     u32 m_start_offset; | ||||
| 
 | ||||
|     NonnullRefPtr<Node> m_end_container; | ||||
|     JS::NonnullGCPtr<Node> m_end_container; | ||||
|     u32 m_end_offset; | ||||
| }; | ||||
| 
 | ||||
|  |  | |||
|  | @ -4,6 +4,7 @@ | |||
|  * SPDX-License-Identifier: BSD-2-Clause | ||||
|  */ | ||||
| 
 | ||||
| #include <LibWeb/Bindings/AttributePrototype.h> | ||||
| #include <LibWeb/DOM/Attribute.h> | ||||
| #include <LibWeb/DOM/Document.h> | ||||
| #include <LibWeb/DOM/Element.h> | ||||
|  | @ -12,9 +13,9 @@ | |||
| 
 | ||||
| namespace Web::DOM { | ||||
| 
 | ||||
| NonnullRefPtr<Attribute> Attribute::create(Document& document, FlyString local_name, String value, Element const* owner_element) | ||||
| JS::NonnullGCPtr<Attribute> Attribute::create(Document& document, FlyString local_name, String value, Element const* owner_element) | ||||
| { | ||||
|     return adopt_ref(*new Attribute(document, move(local_name), move(value), owner_element)); | ||||
|     return *document.heap().allocate<Attribute>(document.realm(), document, move(local_name), move(value), owner_element); | ||||
| } | ||||
| 
 | ||||
| Attribute::Attribute(Document& document, FlyString local_name, String value, Element const* owner_element) | ||||
|  | @ -23,16 +24,23 @@ Attribute::Attribute(Document& document, FlyString local_name, String value, Ele | |||
|     , m_value(move(value)) | ||||
|     , m_owner_element(owner_element) | ||||
| { | ||||
|     set_prototype(&window().ensure_web_prototype<Bindings::AttributePrototype>("Attribute")); | ||||
| } | ||||
| 
 | ||||
| void Attribute::visit_edges(Cell::Visitor& visitor) | ||||
| { | ||||
|     Base::visit_edges(visitor); | ||||
|     visitor.visit(m_owner_element.ptr()); | ||||
| } | ||||
| 
 | ||||
| Element* Attribute::owner_element() | ||||
| { | ||||
|     return m_owner_element; | ||||
|     return m_owner_element.ptr(); | ||||
| } | ||||
| 
 | ||||
| Element const* Attribute::owner_element() const | ||||
| { | ||||
|     return m_owner_element; | ||||
|     return m_owner_element.ptr(); | ||||
| } | ||||
| 
 | ||||
| void Attribute::set_owner_element(Element const* owner_element) | ||||
|  |  | |||
|  | @ -15,10 +15,10 @@ namespace Web::DOM { | |||
| 
 | ||||
| // https://dom.spec.whatwg.org/#attr
 | ||||
| class Attribute final : public Node { | ||||
| public: | ||||
|     using WrapperType = Bindings::AttributeWrapper; | ||||
|     WEB_PLATFORM_OBJECT(Attribute, Node); | ||||
| 
 | ||||
|     static NonnullRefPtr<Attribute> create(Document&, FlyString local_name, String value, Element const* = nullptr); | ||||
| public: | ||||
|     static JS::NonnullGCPtr<Attribute> create(Document&, FlyString local_name, String value, Element const* = nullptr); | ||||
| 
 | ||||
|     virtual ~Attribute() override = default; | ||||
| 
 | ||||
|  | @ -44,12 +44,16 @@ public: | |||
| private: | ||||
|     Attribute(Document&, FlyString local_name, String value, Element const*); | ||||
| 
 | ||||
|     virtual void visit_edges(Cell::Visitor&) override; | ||||
| 
 | ||||
|     QualifiedName m_qualified_name; | ||||
|     String m_value; | ||||
|     WeakPtr<Element> m_owner_element; | ||||
|     JS::GCPtr<Element> m_owner_element; | ||||
| }; | ||||
| 
 | ||||
| template<> | ||||
| inline bool Node::fast_is<Attribute>() const { return is_attribute(); } | ||||
| 
 | ||||
| } | ||||
| 
 | ||||
| WRAPPER_HACK(Attribute, Web::DOM) | ||||
|  |  | |||
|  | @ -4,17 +4,18 @@ | |||
|  * SPDX-License-Identifier: BSD-2-Clause | ||||
|  */ | ||||
| 
 | ||||
| #include <LibWeb/Bindings/CDATASectionPrototype.h> | ||||
| #include <LibWeb/DOM/CDATASection.h> | ||||
| #include <LibWeb/HTML/Window.h> | ||||
| 
 | ||||
| namespace Web::DOM { | ||||
| 
 | ||||
| CDATASection::CDATASection(Document& document, String const& data) | ||||
|     : Text(document, NodeType::CDATA_SECTION_NODE, data) | ||||
| { | ||||
|     set_prototype(&window().ensure_web_prototype<Bindings::CDATASectionPrototype>("CDATASection")); | ||||
| } | ||||
| 
 | ||||
| CDATASection::~CDATASection() | ||||
| { | ||||
| } | ||||
| CDATASection::~CDATASection() = default; | ||||
| 
 | ||||
| } | ||||
|  |  | |||
|  | @ -12,17 +12,21 @@ | |||
| namespace Web::DOM { | ||||
| 
 | ||||
| class CDATASection final : public Text { | ||||
| public: | ||||
|     using WrapperType = Bindings::CDATASectionWrapper; | ||||
|     WEB_PLATFORM_OBJECT(Text, CDATASection); | ||||
| 
 | ||||
|     CDATASection(Document&, String const&); | ||||
| public: | ||||
|     virtual ~CDATASection() override; | ||||
| 
 | ||||
|     // ^Node
 | ||||
|     virtual FlyString node_name() const override { return "#cdata-section"; } | ||||
| 
 | ||||
| private: | ||||
|     CDATASection(Document&, String const&); | ||||
| }; | ||||
| 
 | ||||
| template<> | ||||
| inline bool Node::fast_is<CDATASection>() const { return is_cdata_section(); } | ||||
| 
 | ||||
| } | ||||
| 
 | ||||
| WRAPPER_HACK(CDATASection, Web::DOM) | ||||
|  |  | |||
|  | @ -4,6 +4,7 @@ | |||
|  * SPDX-License-Identifier: BSD-2-Clause | ||||
|  */ | ||||
| 
 | ||||
| #include <LibWeb/Bindings/CharacterDataPrototype.h> | ||||
| #include <LibWeb/DOM/CharacterData.h> | ||||
| #include <LibWeb/DOM/Document.h> | ||||
| #include <LibWeb/DOM/MutationType.h> | ||||
|  | @ -16,6 +17,7 @@ CharacterData::CharacterData(Document& document, NodeType type, String const& da | |||
|     : Node(document, type) | ||||
|     , m_data(data) | ||||
| { | ||||
|     set_prototype(&window().ensure_web_prototype<Bindings::CharacterDataPrototype>("CharacterData")); | ||||
| } | ||||
| 
 | ||||
| // https://dom.spec.whatwg.org/#dom-characterdata-data
 | ||||
|  |  | |||
|  | @ -17,9 +17,9 @@ class CharacterData | |||
|     : public Node | ||||
|     , public ChildNode<CharacterData> | ||||
|     , public NonDocumentTypeChildNode<CharacterData> { | ||||
| public: | ||||
|     using WrapperType = Bindings::CharacterDataWrapper; | ||||
|     WEB_PLATFORM_OBJECT(CharacterData, Node); | ||||
| 
 | ||||
| public: | ||||
|     virtual ~CharacterData() override = default; | ||||
| 
 | ||||
|     String const& data() const { return m_data; } | ||||
|  | @ -41,3 +41,4 @@ private: | |||
| }; | ||||
| 
 | ||||
| } | ||||
| WRAPPER_HACK(CharacterData, Web::DOM) | ||||
|  |  | |||
|  | @ -16,7 +16,7 @@ template<typename NodeType> | |||
| class ChildNode { | ||||
| public: | ||||
|     // https://dom.spec.whatwg.org/#dom-childnode-before
 | ||||
|     ExceptionOr<void> before(Vector<Variant<NonnullRefPtr<Node>, String>> const& nodes) | ||||
|     ExceptionOr<void> before(Vector<Variant<JS::Handle<Node>, String>> const& nodes) | ||||
|     { | ||||
|         auto* node = static_cast<NodeType*>(this); | ||||
| 
 | ||||
|  | @ -46,7 +46,7 @@ public: | |||
|     } | ||||
| 
 | ||||
|     // https://dom.spec.whatwg.org/#dom-childnode-after
 | ||||
|     ExceptionOr<void> after(Vector<Variant<NonnullRefPtr<Node>, String>> const& nodes) | ||||
|     ExceptionOr<void> after(Vector<Variant<JS::Handle<Node>, String>> const& nodes) | ||||
|     { | ||||
|         auto* node = static_cast<NodeType*>(this); | ||||
| 
 | ||||
|  | @ -70,7 +70,7 @@ public: | |||
|     } | ||||
| 
 | ||||
|     // https://dom.spec.whatwg.org/#dom-childnode-replacewith
 | ||||
|     ExceptionOr<void> replace_with(Vector<Variant<NonnullRefPtr<Node>, String>> const& nodes) | ||||
|     ExceptionOr<void> replace_with(Vector<Variant<JS::Handle<Node>, String>> const& nodes) | ||||
|     { | ||||
|         auto* node = static_cast<NodeType*>(this); | ||||
| 
 | ||||
|  | @ -117,7 +117,7 @@ protected: | |||
|     ChildNode() = default; | ||||
| 
 | ||||
| private: | ||||
|     RefPtr<Node> viable_previous_sibling_for_insertion(Vector<Variant<NonnullRefPtr<Node>, String>> const& nodes) const | ||||
|     JS::GCPtr<Node> viable_previous_sibling_for_insertion(Vector<Variant<JS::Handle<Node>, String>> const& nodes) const | ||||
|     { | ||||
|         auto* node = static_cast<NodeType const*>(this); | ||||
| 
 | ||||
|  | @ -125,11 +125,11 @@ private: | |||
|             bool contained_in_nodes = false; | ||||
| 
 | ||||
|             for (auto const& node_or_string : nodes) { | ||||
|                 if (!node_or_string.template has<NonnullRefPtr<Node>>()) | ||||
|                 if (!node_or_string.template has<JS::Handle<Node>>()) | ||||
|                     continue; | ||||
| 
 | ||||
|                 auto node_in_vector = node_or_string.template get<NonnullRefPtr<Node>>(); | ||||
|                 if (node_in_vector.ptr() == previous_sibling) { | ||||
|                 auto node_in_vector = node_or_string.template get<JS::Handle<Node>>(); | ||||
|                 if (node_in_vector.cell() == previous_sibling) { | ||||
|                     contained_in_nodes = true; | ||||
|                     break; | ||||
|                 } | ||||
|  | @ -142,7 +142,7 @@ private: | |||
|         return nullptr; | ||||
|     } | ||||
| 
 | ||||
|     RefPtr<Node> viable_nest_sibling_for_insertion(Vector<Variant<NonnullRefPtr<Node>, String>> const& nodes) const | ||||
|     JS::GCPtr<Node> viable_nest_sibling_for_insertion(Vector<Variant<JS::Handle<Node>, String>> const& nodes) const | ||||
|     { | ||||
|         auto* node = static_cast<NodeType const*>(this); | ||||
| 
 | ||||
|  | @ -150,11 +150,11 @@ private: | |||
|             bool contained_in_nodes = false; | ||||
| 
 | ||||
|             for (auto const& node_or_string : nodes) { | ||||
|                 if (!node_or_string.template has<NonnullRefPtr<Node>>()) | ||||
|                 if (!node_or_string.template has<JS::Handle<Node>>()) | ||||
|                     continue; | ||||
| 
 | ||||
|                 auto node_in_vector = node_or_string.template get<NonnullRefPtr<Node>>(); | ||||
|                 if (node_in_vector.ptr() == next_sibling) { | ||||
|                 auto& node_in_vector = node_or_string.template get<JS::Handle<Node>>(); | ||||
|                 if (node_in_vector.cell() == next_sibling) { | ||||
|                     contained_in_nodes = true; | ||||
|                     break; | ||||
|                 } | ||||
|  |  | |||
|  | @ -16,9 +16,9 @@ Comment::Comment(Document& document, String const& data) | |||
| } | ||||
| 
 | ||||
| // https://dom.spec.whatwg.org/#dom-comment-comment
 | ||||
| NonnullRefPtr<Comment> Comment::create_with_global_object(Bindings::WindowObject& window, String const& data) | ||||
| JS::NonnullGCPtr<Comment> Comment::create_with_global_object(HTML::Window& window, String const& data) | ||||
| { | ||||
|     return make_ref_counted<Comment>(window.impl().associated_document(), data); | ||||
|     return *window.heap().allocate<Comment>(window.realm(), window.associated_document(), data); | ||||
| } | ||||
| 
 | ||||
| } | ||||
|  |  | |||
|  | @ -12,18 +12,21 @@ | |||
| namespace Web::DOM { | ||||
| 
 | ||||
| class Comment final : public CharacterData { | ||||
| public: | ||||
|     using WrapperType = Bindings::CommentWrapper; | ||||
|     WEB_PLATFORM_OBJECT(Comment, CharacterData); | ||||
| 
 | ||||
|     explicit Comment(Document&, String const&); | ||||
| public: | ||||
|     static JS::NonnullGCPtr<Comment> create_with_global_object(HTML::Window&, String const& data); | ||||
|     virtual ~Comment() override = default; | ||||
| 
 | ||||
|     virtual FlyString node_name() const override { return "#comment"; } | ||||
| 
 | ||||
|     static NonnullRefPtr<Comment> create_with_global_object(Bindings::WindowObject& window, String const& data); | ||||
| private: | ||||
|     explicit Comment(Document&, String const&); | ||||
| }; | ||||
| 
 | ||||
| template<> | ||||
| inline bool Node::fast_is<Comment>() const { return is_comment(); } | ||||
| 
 | ||||
| } | ||||
| 
 | ||||
| WRAPPER_HACK(Comment, Web::DOM) | ||||
|  |  | |||
|  | @ -6,28 +6,28 @@ | |||
|  */ | ||||
| 
 | ||||
| #include <LibWeb/Bindings/CustomEventPrototype.h> | ||||
| #include <LibWeb/Bindings/WindowObject.h> | ||||
| #include <LibWeb/DOM/CustomEvent.h> | ||||
| #include <LibWeb/HTML/Window.h> | ||||
| 
 | ||||
| namespace Web::DOM { | ||||
| 
 | ||||
| CustomEvent* CustomEvent::create(Bindings::WindowObject& window_object, FlyString const& event_name, CustomEventInit const& event_init) | ||||
| CustomEvent* CustomEvent::create(HTML::Window& window_object, FlyString const& event_name, CustomEventInit const& event_init) | ||||
| { | ||||
|     return window_object.heap().allocate<CustomEvent>(window_object.realm(), window_object, event_name, event_init); | ||||
| } | ||||
| 
 | ||||
| CustomEvent* CustomEvent::create_with_global_object(Bindings::WindowObject& window_object, FlyString const& event_name, CustomEventInit const& event_init) | ||||
| CustomEvent* CustomEvent::create_with_global_object(HTML::Window& window_object, FlyString const& event_name, CustomEventInit const& event_init) | ||||
| { | ||||
|     return create(window_object, event_name, event_init); | ||||
| } | ||||
| 
 | ||||
| CustomEvent::CustomEvent(Bindings::WindowObject& window_object, FlyString const& event_name) | ||||
| CustomEvent::CustomEvent(HTML::Window& window_object, FlyString const& event_name) | ||||
|     : Event(window_object, event_name) | ||||
| { | ||||
|     set_prototype(&window_object.ensure_web_prototype<Bindings::CustomEventPrototype>("CustomEvent")); | ||||
| } | ||||
| 
 | ||||
| CustomEvent::CustomEvent(Bindings::WindowObject& window_object, FlyString const& event_name, CustomEventInit const& event_init) | ||||
| CustomEvent::CustomEvent(HTML::Window& window_object, FlyString const& event_name, CustomEventInit const& event_init) | ||||
|     : Event(window_object, event_name, event_init) | ||||
|     , m_detail(event_init.detail) | ||||
| { | ||||
|  |  | |||
|  | @ -17,19 +17,17 @@ struct CustomEventInit : public EventInit { | |||
| 
 | ||||
| // https://dom.spec.whatwg.org/#customevent
 | ||||
| class CustomEvent : public Event { | ||||
|     JS_OBJECT(CustomEvent, Event); | ||||
|     WEB_PLATFORM_OBJECT(CustomEvent, Event); | ||||
| 
 | ||||
| public: | ||||
|     static CustomEvent* create(Bindings::WindowObject&, FlyString const& event_name, CustomEventInit const& event_init = {}); | ||||
|     static CustomEvent* create_with_global_object(Bindings::WindowObject&, FlyString const& event_name, CustomEventInit const& event_init); | ||||
|     static CustomEvent* create(HTML::Window&, FlyString const& event_name, CustomEventInit const& event_init = {}); | ||||
|     static CustomEvent* create_with_global_object(HTML::Window&, FlyString const& event_name, CustomEventInit const& event_init); | ||||
| 
 | ||||
|     CustomEvent(Bindings::WindowObject&, FlyString const& event_name); | ||||
|     CustomEvent(Bindings::WindowObject&, FlyString const& event_name, CustomEventInit const& event_init); | ||||
|     CustomEvent(HTML::Window&, FlyString const& event_name); | ||||
|     CustomEvent(HTML::Window&, FlyString const& event_name, CustomEventInit const& event_init); | ||||
| 
 | ||||
|     virtual ~CustomEvent() override; | ||||
| 
 | ||||
|     CustomEvent& impl() { return *this; } | ||||
| 
 | ||||
|     // https://dom.spec.whatwg.org/#dom-customevent-detail
 | ||||
|     JS::Value detail() const { return m_detail; } | ||||
| 
 | ||||
|  |  | |||
|  | @ -17,6 +17,7 @@ void DOMEventListener::visit_edges(Cell::Visitor& visitor) | |||
| { | ||||
|     Cell::visit_edges(visitor); | ||||
|     visitor.visit(callback.ptr()); | ||||
|     visitor.visit(signal.ptr()); | ||||
| } | ||||
| 
 | ||||
| } | ||||
|  |  | |||
|  | @ -27,7 +27,7 @@ public: | |||
|     JS::GCPtr<IDLEventListener> callback; | ||||
| 
 | ||||
|     // signal (null or an AbortSignal object)
 | ||||
|     RefPtr<DOM::AbortSignal> signal; | ||||
|     JS::GCPtr<DOM::AbortSignal> signal; | ||||
| 
 | ||||
|     // capture (a boolean, initially false)
 | ||||
|     bool capture { false }; | ||||
|  |  | |||
|  | @ -111,7 +111,7 @@ public: | |||
|     } | ||||
| 
 | ||||
|     // JS constructor has message first, name second
 | ||||
|     static NonnullRefPtr<DOMException> create_with_global_object(Bindings::WindowObject&, FlyString const& message, FlyString const& name) | ||||
|     static NonnullRefPtr<DOMException> create_with_global_object(HTML::Window&, FlyString const& message, FlyString const& name) | ||||
|     { | ||||
|         return adopt_ref(*new DOMException(name, message)); | ||||
|     } | ||||
|  |  | |||
|  | @ -6,25 +6,26 @@ | |||
|  */ | ||||
| 
 | ||||
| #include <LibWeb/Bindings/DOMImplementationPrototype.h> | ||||
| #include <LibWeb/Bindings/WindowObject.h> | ||||
| #include <LibWeb/Bindings/MainThreadVM.h> | ||||
| #include <LibWeb/DOM/DOMImplementation.h> | ||||
| #include <LibWeb/DOM/Document.h> | ||||
| #include <LibWeb/DOM/DocumentType.h> | ||||
| #include <LibWeb/DOM/ElementFactory.h> | ||||
| #include <LibWeb/DOM/Text.h> | ||||
| #include <LibWeb/HTML/Origin.h> | ||||
| #include <LibWeb/HTML/Window.h> | ||||
| #include <LibWeb/Namespace.h> | ||||
| 
 | ||||
| namespace Web::DOM { | ||||
| 
 | ||||
| JS::NonnullGCPtr<DOMImplementation> DOMImplementation::create(Document& document) | ||||
| { | ||||
|     auto& window_object = document.preferred_window_object(); | ||||
|     return *window_object.heap().allocate<DOMImplementation>(window_object.realm(), document); | ||||
|     auto& window = document.window(); | ||||
|     return *window.heap().allocate<DOMImplementation>(document.realm(), document); | ||||
| } | ||||
| 
 | ||||
| DOMImplementation::DOMImplementation(Document& document) | ||||
|     : PlatformObject(document.preferred_window_object().ensure_web_prototype<Bindings::DOMImplementationPrototype>("DOMImplementation")) | ||||
|     : PlatformObject(document.window().ensure_web_prototype<Bindings::DOMImplementationPrototype>("DOMImplementation")) | ||||
|     , m_document(document) | ||||
| { | ||||
| } | ||||
|  | @ -38,23 +39,23 @@ void DOMImplementation::visit_edges(Cell::Visitor& visitor) | |||
| } | ||||
| 
 | ||||
| // https://dom.spec.whatwg.org/#dom-domimplementation-createdocument
 | ||||
| ExceptionOr<NonnullRefPtr<Document>> DOMImplementation::create_document(String const& namespace_, String const& qualified_name, RefPtr<DocumentType> doctype) const | ||||
| ExceptionOr<JS::NonnullGCPtr<Document>> DOMImplementation::create_document(String const& namespace_, String const& qualified_name, JS::GCPtr<DocumentType> doctype) const | ||||
| { | ||||
|     // FIXME: This should specifically be an XML document.
 | ||||
|     auto xml_document = Document::create(); | ||||
|     auto xml_document = Document::create(Bindings::main_thread_internal_window_object()); | ||||
| 
 | ||||
|     xml_document->set_ready_for_post_load_tasks(true); | ||||
| 
 | ||||
|     RefPtr<Element> element; | ||||
|     JS::GCPtr<Element> element; | ||||
| 
 | ||||
|     if (!qualified_name.is_empty()) | ||||
|         element = TRY(xml_document->create_element_ns(namespace_, qualified_name /* FIXME: and an empty dictionary */)); | ||||
| 
 | ||||
|     if (doctype) | ||||
|         xml_document->append_child(doctype.release_nonnull()); | ||||
|         xml_document->append_child(*doctype); | ||||
| 
 | ||||
|     if (element) | ||||
|         xml_document->append_child(element.release_nonnull()); | ||||
|         xml_document->append_child(*element); | ||||
| 
 | ||||
|     xml_document->set_origin(document().origin()); | ||||
| 
 | ||||
|  | @ -69,16 +70,16 @@ ExceptionOr<NonnullRefPtr<Document>> DOMImplementation::create_document(String c | |||
| } | ||||
| 
 | ||||
| // https://dom.spec.whatwg.org/#dom-domimplementation-createhtmldocument
 | ||||
| NonnullRefPtr<Document> DOMImplementation::create_html_document(String const& title) const | ||||
| JS::NonnullGCPtr<Document> DOMImplementation::create_html_document(String const& title) const | ||||
| { | ||||
|     auto html_document = Document::create(); | ||||
|     auto html_document = Document::create(Bindings::main_thread_internal_window_object()); | ||||
| 
 | ||||
|     html_document->set_content_type("text/html"); | ||||
|     html_document->set_ready_for_post_load_tasks(true); | ||||
| 
 | ||||
|     auto doctype = adopt_ref(*new DocumentType(html_document)); | ||||
|     auto doctype = heap().allocate<DocumentType>(realm(), html_document); | ||||
|     doctype->set_name("html"); | ||||
|     html_document->append_child(doctype); | ||||
|     html_document->append_child(*doctype); | ||||
| 
 | ||||
|     auto html_element = create_element(html_document, HTML::TagNames::html, Namespace::HTML); | ||||
|     html_document->append_child(html_element); | ||||
|  | @ -90,8 +91,8 @@ NonnullRefPtr<Document> DOMImplementation::create_html_document(String const& ti | |||
|         auto title_element = create_element(html_document, HTML::TagNames::title, Namespace::HTML); | ||||
|         head_element->append_child(title_element); | ||||
| 
 | ||||
|         auto text_node = adopt_ref(*new Text(html_document, title)); | ||||
|         title_element->append_child(text_node); | ||||
|         auto text_node = heap().allocate<Text>(realm(), html_document, title); | ||||
|         title_element->append_child(*text_node); | ||||
|     } | ||||
| 
 | ||||
|     auto body_element = create_element(html_document, HTML::TagNames::body, Namespace::HTML); | ||||
|  | @ -103,7 +104,7 @@ NonnullRefPtr<Document> DOMImplementation::create_html_document(String const& ti | |||
| } | ||||
| 
 | ||||
| // https://dom.spec.whatwg.org/#dom-domimplementation-createdocumenttype
 | ||||
| ExceptionOr<NonnullRefPtr<DocumentType>> DOMImplementation::create_document_type(String const& qualified_name, String const& public_id, String const& system_id) | ||||
| ExceptionOr<JS::NonnullGCPtr<DocumentType>> DOMImplementation::create_document_type(String const& qualified_name, String const& public_id, String const& system_id) | ||||
| { | ||||
|     TRY(Document::validate_qualified_name(qualified_name)); | ||||
|     auto document_type = DocumentType::create(document()); | ||||
|  |  | |||
|  | @ -7,30 +7,29 @@ | |||
| 
 | ||||
| #pragma once | ||||
| 
 | ||||
| #include <AK/NonnullRefPtr.h> | ||||
| #include <LibJS/Heap/GCPtr.h> | ||||
| #include <LibWeb/Bindings/PlatformObject.h> | ||||
| #include <LibWeb/DOM/Document.h> | ||||
| 
 | ||||
| namespace Web::DOM { | ||||
| 
 | ||||
| class DOMImplementation final : public Bindings::PlatformObject { | ||||
|     JS_OBJECT(DOMImplementation, Bindings::PlatformObject); | ||||
|     WEB_PLATFORM_OBJECT(DOMImplementation, Bindings::PlatformObject); | ||||
| 
 | ||||
| public: | ||||
|     static JS::NonnullGCPtr<DOMImplementation> create(Document&); | ||||
|     explicit DOMImplementation(Document&); | ||||
|     virtual ~DOMImplementation(); | ||||
| 
 | ||||
|     DOMImplementation& impl() { return *this; } | ||||
| 
 | ||||
|     ExceptionOr<NonnullRefPtr<Document>> create_document(String const&, String const&, RefPtr<DocumentType>) const; | ||||
|     NonnullRefPtr<Document> create_html_document(String const& title) const; | ||||
|     ExceptionOr<NonnullRefPtr<DocumentType>> create_document_type(String const& qualified_name, String const& public_id, String const& system_id); | ||||
|     ExceptionOr<JS::NonnullGCPtr<Document>> create_document(String const&, String const&, JS::GCPtr<DocumentType>) const; | ||||
|     JS::NonnullGCPtr<Document> create_html_document(String const& title) const; | ||||
|     ExceptionOr<JS::NonnullGCPtr<DocumentType>> create_document_type(String const& qualified_name, String const& public_id, String const& system_id); | ||||
| 
 | ||||
|     // https://dom.spec.whatwg.org/#dom-domimplementation-hasfeature
 | ||||
|     bool has_feature() const { return true; } | ||||
| 
 | ||||
| private: | ||||
|     explicit DOMImplementation(Document&); | ||||
| 
 | ||||
|     virtual void visit_edges(Cell::Visitor&) override; | ||||
| 
 | ||||
|     Document& document() { return m_document; } | ||||
|  | @ -41,7 +40,4 @@ private: | |||
| 
 | ||||
| } | ||||
| 
 | ||||
| namespace Web::Bindings { | ||||
| inline JS::Object* wrap(JS::Realm&, Web::DOM::DOMImplementation& object) { return &object; } | ||||
| using DOMImplementationWrapper = Web::DOM::DOMImplementation; | ||||
| } | ||||
| WRAPPER_HACK(DOMImplementation, Web::DOM) | ||||
|  |  | |||
|  | @ -8,11 +8,11 @@ | |||
| #include <AK/CharacterTypes.h> | ||||
| #include <AK/StringBuilder.h> | ||||
| #include <LibWeb/Bindings/DOMTokenListPrototype.h> | ||||
| #include <LibWeb/Bindings/WindowObject.h> | ||||
| #include <LibWeb/DOM/DOMException.h> | ||||
| #include <LibWeb/DOM/DOMTokenList.h> | ||||
| #include <LibWeb/DOM/Document.h> | ||||
| #include <LibWeb/DOM/Element.h> | ||||
| #include <LibWeb/HTML/Window.h> | ||||
| 
 | ||||
| namespace { | ||||
| 
 | ||||
|  | @ -56,13 +56,13 @@ namespace Web::DOM { | |||
| 
 | ||||
| DOMTokenList* DOMTokenList::create(Element const& associated_element, FlyString associated_attribute) | ||||
| { | ||||
|     auto& realm = associated_element.document().preferred_window_object().realm(); | ||||
|     auto& realm = associated_element.document().window().realm(); | ||||
|     return realm.heap().allocate<DOMTokenList>(realm, associated_element, move(associated_attribute)); | ||||
| } | ||||
| 
 | ||||
| // https://dom.spec.whatwg.org/#ref-for-domtokenlist%E2%91%A0%E2%91%A2
 | ||||
| DOMTokenList::DOMTokenList(Element const& associated_element, FlyString associated_attribute) | ||||
|     : Bindings::LegacyPlatformObject(associated_element.document().preferred_window_object().ensure_web_prototype<Bindings::DOMTokenListPrototype>("DOMTokenList")) | ||||
|     : Bindings::LegacyPlatformObject(associated_element.document().window().ensure_web_prototype<Bindings::DOMTokenListPrototype>("DOMTokenList")) | ||||
|     , m_associated_element(associated_element) | ||||
|     , m_associated_attribute(move(associated_attribute)) | ||||
| { | ||||
|  | @ -225,7 +225,7 @@ String DOMTokenList::value() const | |||
| // https://dom.spec.whatwg.org/#ref-for-concept-element-attributes-set-value%E2%91%A2
 | ||||
| void DOMTokenList::set_value(String value) | ||||
| { | ||||
|     auto associated_element = m_associated_element.strong_ref(); | ||||
|     JS::GCPtr<DOM::Element> associated_element = m_associated_element.ptr(); | ||||
|     if (!associated_element) | ||||
|         return; | ||||
| 
 | ||||
|  | @ -244,7 +244,7 @@ ExceptionOr<void> DOMTokenList::validate_token(StringView token) const | |||
| // https://dom.spec.whatwg.org/#concept-dtl-update
 | ||||
| void DOMTokenList::run_update_steps() | ||||
| { | ||||
|     auto associated_element = m_associated_element.strong_ref(); | ||||
|     JS::GCPtr<DOM::Element> associated_element = m_associated_element.ptr(); | ||||
|     if (!associated_element) | ||||
|         return; | ||||
| 
 | ||||
|  |  | |||
|  | @ -20,15 +20,12 @@ namespace Web::DOM { | |||
| 
 | ||||
| // https://dom.spec.whatwg.org/#domtokenlist
 | ||||
| class DOMTokenList final : public Bindings::LegacyPlatformObject { | ||||
|     JS_OBJECT(DOMTokenList, Bindings::LegacyPlatformObject); | ||||
|     WEB_PLATFORM_OBJECT(DOMTokenList, Bindings::LegacyPlatformObject); | ||||
| 
 | ||||
| public: | ||||
|     static DOMTokenList* create(Element const& associated_element, FlyString associated_attribute); | ||||
|     DOMTokenList(Element const& associated_element, FlyString associated_attribute); | ||||
|     ~DOMTokenList() = default; | ||||
| 
 | ||||
|     DOMTokenList& impl() { return *this; } | ||||
| 
 | ||||
|     void associated_attribute_changed(StringView value); | ||||
| 
 | ||||
|     virtual bool is_supported_property_index(u32 index) const override; | ||||
|  | @ -46,6 +43,8 @@ public: | |||
|     void set_value(String value); | ||||
| 
 | ||||
| private: | ||||
|     DOMTokenList(Element const& associated_element, FlyString associated_attribute); | ||||
| 
 | ||||
|     ExceptionOr<void> validate_token(StringView token) const; | ||||
|     void run_update_steps(); | ||||
| 
 | ||||
|  | @ -56,7 +55,4 @@ private: | |||
| 
 | ||||
| } | ||||
| 
 | ||||
| namespace Web::Bindings { | ||||
| inline JS::Object* wrap(JS::Realm&, Web::DOM::DOMTokenList& object) { return &object; } | ||||
| using DOMTokenListWrapper = Web::DOM::DOMTokenList; | ||||
| } | ||||
| WRAPPER_HACK(DOMTokenList, Web::DOM) | ||||
|  |  | |||
|  | @ -14,8 +14,9 @@ | |||
| #include <LibJS/Interpreter.h> | ||||
| #include <LibJS/Parser.h> | ||||
| #include <LibJS/Runtime/FunctionObject.h> | ||||
| #include <LibWeb/Bindings/DocumentPrototype.h> | ||||
| #include <LibWeb/Bindings/MainThreadVM.h> | ||||
| #include <LibWeb/Bindings/WindowObject.h> | ||||
| #include <LibWeb/CSS/MediaQueryList.h> | ||||
| #include <LibWeb/CSS/MediaQueryListEvent.h> | ||||
| #include <LibWeb/CSS/StyleComputer.h> | ||||
| #include <LibWeb/Cookie/ParsedCookie.h> | ||||
|  | @ -100,7 +101,7 @@ static NonnullRefPtr<HTML::BrowsingContext> obtain_a_browsing_context_to_use_for | |||
|     VERIFY(browsing_context.page()); | ||||
|     auto new_browsing_context = HTML::BrowsingContext::create_a_new_browsing_context(*browsing_context.page(), nullptr, nullptr); | ||||
| 
 | ||||
|     // FIXME: 4. If navigationCOOP's value is "same-origin-plus-COEP", then set newBrowsingContext's group's
 | ||||
|     // FIXME: 4. If navigationCOOP's value is "same-origin-plurs-COEP", then set newBrowsingContext's group's
 | ||||
|     //           cross-origin isolation mode to either "logical" or "concrete". The choice of which is implementation-defined.
 | ||||
| 
 | ||||
|     // 5. If sandboxFlags is not empty, then:
 | ||||
|  | @ -120,7 +121,7 @@ static NonnullRefPtr<HTML::BrowsingContext> obtain_a_browsing_context_to_use_for | |||
| } | ||||
| 
 | ||||
| // https://html.spec.whatwg.org/multipage/browsing-the-web.html#initialise-the-document-object
 | ||||
| NonnullRefPtr<Document> Document::create_and_initialize(Type type, String content_type, HTML::NavigationParams navigation_params) | ||||
| JS::NonnullGCPtr<Document> Document::create_and_initialize(Type type, String content_type, HTML::NavigationParams navigation_params) | ||||
| { | ||||
|     // 1. Let browsingContext be the result of the obtaining a browsing context to use for a navigation response
 | ||||
|     //    given navigationParams's browsing context, navigationParams's final sandboxing flag set,
 | ||||
|  | @ -142,7 +143,7 @@ NonnullRefPtr<Document> Document::create_and_initialize(Type type, String conten | |||
|         creation_url = navigation_params.request->current_url(); | ||||
|     } | ||||
| 
 | ||||
|     RefPtr<HTML::Window> window; | ||||
|     JS::GCPtr<HTML::Window> window; | ||||
| 
 | ||||
|     // 5. If browsingContext is still on its initial about:blank Document,
 | ||||
|     //    and navigationParams's history handling is "replace",
 | ||||
|  | @ -168,14 +169,12 @@ NonnullRefPtr<Document> Document::create_and_initialize(Type type, String conten | |||
|         // 5. Let realm execution context be the result of creating a new JavaScript realm given agent and the following customizations:
 | ||||
|         auto realm_execution_context = Bindings::create_a_new_javascript_realm( | ||||
|             Bindings::main_thread_vm(), | ||||
|             [&](JS::Realm& realm) -> JS::GlobalObject* { | ||||
|             [&](JS::Realm& realm) -> JS::Object* { | ||||
|                 // - For the global object, create a new Window object.
 | ||||
|                 window = HTML::Window::create(); | ||||
|                 auto* global_object = realm.heap().allocate_without_realm<Bindings::WindowObject>(realm, *window); | ||||
|                 VERIFY(window->wrapper() == global_object); | ||||
|                 return global_object; | ||||
|                 window = HTML::Window::create(realm); | ||||
|                 return window; | ||||
|             }, | ||||
|             [](JS::Realm&) -> JS::GlobalObject* { | ||||
|             [](JS::Realm&) -> JS::Object* { | ||||
|                 // FIXME: - For the global this binding, use browsingContext's WindowProxy object.
 | ||||
|                 return nullptr; | ||||
|             }); | ||||
|  | @ -223,7 +222,7 @@ NonnullRefPtr<Document> Document::create_and_initialize(Type type, String conten | |||
|     //    FIXME: and cross-origin opener policy is navigationParams's cross-origin opener policy,
 | ||||
|     //    FIXME: load timing info is loadTimingInfo,
 | ||||
|     //    FIXME: and navigation id is navigationParams's id.
 | ||||
|     auto document = Document::create(); | ||||
|     auto document = Document::create(*window); | ||||
|     document->m_type = type; | ||||
|     document->m_content_type = content_type; | ||||
|     document->set_origin(navigation_params.origin); | ||||
|  | @ -266,24 +265,25 @@ NonnullRefPtr<Document> Document::create_and_initialize(Type type, String conten | |||
|     return document; | ||||
| } | ||||
| 
 | ||||
| NonnullRefPtr<Document> Document::create_with_global_object(Bindings::WindowObject&) | ||||
| JS::NonnullGCPtr<Document> Document::create_with_global_object(HTML::Window& window) | ||||
| { | ||||
|     return Document::create(); | ||||
|     return Document::create(window); | ||||
| } | ||||
| 
 | ||||
| NonnullRefPtr<Document> Document::create(AK::URL const& url) | ||||
| JS::NonnullGCPtr<Document> Document::create(HTML::Window& window, AK::URL const& url) | ||||
| { | ||||
|     return adopt_ref(*new Document(url)); | ||||
|     auto& realm = window.realm(); | ||||
|     return *realm.heap().allocate<Document>(realm, window, url); | ||||
| } | ||||
| 
 | ||||
| Document::Document(const AK::URL& url) | ||||
|     : ParentNode(*this, NodeType::DOCUMENT_NODE) | ||||
| Document::Document(HTML::Window& window, const AK::URL& url) | ||||
|     : ParentNode(window.realm(), *this, NodeType::DOCUMENT_NODE) | ||||
|     , m_style_computer(make<CSS::StyleComputer>(*this)) | ||||
|     , m_url(url) | ||||
|     , m_window(HTML::Window::create_with_document(*this)) | ||||
|     , m_window(window) | ||||
|     , m_history(HTML::History::create(*this)) | ||||
| { | ||||
|     m_style_sheets = JS::make_handle(CSS::StyleSheetList::create(*this)); | ||||
|     set_prototype(&window.ensure_web_prototype<Bindings::DocumentPrototype>("Document")); | ||||
| 
 | ||||
|     HTML::main_thread_event_loop().register_document({}, *this); | ||||
| 
 | ||||
|  | @ -296,63 +296,33 @@ Document::Document(const AK::URL& url) | |||
|     }); | ||||
| } | ||||
| 
 | ||||
| Document::~Document() = default; | ||||
| 
 | ||||
| void Document::removed_last_ref() | ||||
| Document::~Document() | ||||
| { | ||||
|     VERIFY(!ref_count()); | ||||
|     VERIFY(!m_deletion_has_begun); | ||||
| 
 | ||||
|     if (m_referencing_node_count) { | ||||
|         // The document has reached ref_count==0 but still has nodes keeping it alive.
 | ||||
|         // At this point, sever all the node links we control.
 | ||||
|         // If nodes remain elsewhere (e.g JS wrappers), they will keep the document alive.
 | ||||
| 
 | ||||
|         // NOTE: This makes sure we stay alive across for the duration of the cleanup below.
 | ||||
|         increment_referencing_node_count(); | ||||
| 
 | ||||
|         m_focused_element = nullptr; | ||||
|         m_hovered_node = nullptr; | ||||
|         m_pending_parsing_blocking_script = nullptr; | ||||
|         m_inspected_node = nullptr; | ||||
|         m_scripts_to_execute_when_parsing_has_finished.clear(); | ||||
|         m_scripts_to_execute_as_soon_as_possible.clear(); | ||||
|         m_associated_inert_template_document = nullptr; | ||||
| 
 | ||||
|         m_interpreter = nullptr; | ||||
| 
 | ||||
|         { | ||||
|             // Gather up all the descendants of this document and prune them from the tree.
 | ||||
|             // FIXME: This could definitely be more elegant.
 | ||||
|             NonnullRefPtrVector<Node> descendants; | ||||
|             for_each_in_inclusive_subtree([&](auto& node) { | ||||
|                 if (&node != this) | ||||
|                     descendants.append(node); | ||||
|                 return IterationDecision::Continue; | ||||
|             }); | ||||
| 
 | ||||
|             for (auto& node : descendants) { | ||||
|                 VERIFY(&node.document() == this); | ||||
|                 VERIFY(!node.is_document()); | ||||
|                 if (node.parent()) { | ||||
|                     // We need to suppress mutation observers so that they don't try and queue a microtask for this Document which is in the process of dying,
 | ||||
|                     // which will cause an `!m_in_removed_last_ref` assertion failure when it tries to ref this Document.
 | ||||
|                     node.remove(true); | ||||
|                 } | ||||
|             } | ||||
|         } | ||||
| 
 | ||||
|         m_in_removed_last_ref = false; | ||||
|         decrement_referencing_node_count(); | ||||
|         return; | ||||
|     } | ||||
| 
 | ||||
|     m_in_removed_last_ref = false; | ||||
|     m_deletion_has_begun = true; | ||||
| 
 | ||||
|     HTML::main_thread_event_loop().unregister_document({}, *this); | ||||
| } | ||||
| 
 | ||||
|     delete this; | ||||
| void Document::visit_edges(Cell::Visitor& visitor) | ||||
| { | ||||
|     Base::visit_edges(visitor); | ||||
|     visitor.visit(m_window.ptr()); | ||||
|     visitor.visit(m_style_sheets.ptr()); | ||||
|     visitor.visit(m_hovered_node.ptr()); | ||||
|     visitor.visit(m_inspected_node.ptr()); | ||||
|     visitor.visit(m_active_favicon.ptr()); | ||||
|     visitor.visit(m_focused_element.ptr()); | ||||
|     visitor.visit(m_active_element.ptr()); | ||||
|     visitor.visit(m_implementation.ptr()); | ||||
|     visitor.visit(m_current_script.ptr()); | ||||
|     visitor.visit(m_associated_inert_template_document.ptr()); | ||||
|     visitor.visit(m_pending_parsing_blocking_script.ptr()); | ||||
| 
 | ||||
|     for (auto& script : m_scripts_to_execute_when_parsing_has_finished) | ||||
|         visitor.visit(script.ptr()); | ||||
|     for (auto& script : m_scripts_to_execute_as_soon_as_possible) | ||||
|         visitor.visit(script.ptr()); | ||||
| 
 | ||||
|     for (auto& node_iterator : m_node_iterators) | ||||
|         visitor.visit(node_iterator); | ||||
| } | ||||
| 
 | ||||
| // https://html.spec.whatwg.org/multipage/dynamic-markup-insertion.html#dom-document-write
 | ||||
|  | @ -642,14 +612,14 @@ void Document::set_title(String const& title) | |||
|     if (!head_element) | ||||
|         return; | ||||
| 
 | ||||
|     RefPtr<HTML::HTMLTitleElement> title_element = head_element->first_child_of_type<HTML::HTMLTitleElement>(); | ||||
|     JS::GCPtr<HTML::HTMLTitleElement> title_element = head_element->first_child_of_type<HTML::HTMLTitleElement>(); | ||||
|     if (!title_element) { | ||||
|         title_element = static_ptr_cast<HTML::HTMLTitleElement>(create_element(HTML::TagNames::title).release_value()); | ||||
|         title_element = &static_cast<HTML::HTMLTitleElement&>(*create_element(HTML::TagNames::title).release_value()); | ||||
|         head_element->append_child(*title_element); | ||||
|     } | ||||
| 
 | ||||
|     title_element->remove_all_children(true); | ||||
|     title_element->append_child(adopt_ref(*new Text(*this, title))); | ||||
|     title_element->append_child(*heap().allocate<Text>(realm(), *this, title)); | ||||
| 
 | ||||
|     if (auto* page = this->page()) { | ||||
|         if (browsing_context() == &page->top_level_browsing_context()) | ||||
|  | @ -725,13 +695,13 @@ Vector<CSS::BackgroundLayerData> const* Document::background_layers() const | |||
|     return &body_layout_node->background_layers(); | ||||
| } | ||||
| 
 | ||||
| RefPtr<HTML::HTMLBaseElement> Document::first_base_element_with_href_in_tree_order() const | ||||
| JS::GCPtr<HTML::HTMLBaseElement> Document::first_base_element_with_href_in_tree_order() const | ||||
| { | ||||
|     RefPtr<HTML::HTMLBaseElement> base_element; | ||||
|     JS::GCPtr<HTML::HTMLBaseElement> base_element; | ||||
| 
 | ||||
|     for_each_in_subtree_of_type<HTML::HTMLBaseElement>([&base_element](HTML::HTMLBaseElement const& base_element_in_tree) { | ||||
|         if (base_element_in_tree.has_attribute(HTML::AttributeNames::href)) { | ||||
|             base_element = base_element_in_tree; | ||||
|             base_element = &base_element_in_tree; | ||||
|             return IterationDecision::Break; | ||||
|         } | ||||
| 
 | ||||
|  | @ -909,7 +879,7 @@ Layout::InitialContainingBlock* Document::layout_node() | |||
| 
 | ||||
| void Document::set_inspected_node(Node* node) | ||||
| { | ||||
|     if (m_inspected_node == node) | ||||
|     if (m_inspected_node.ptr() == node) | ||||
|         return; | ||||
| 
 | ||||
|     if (m_inspected_node && m_inspected_node->layout_node()) | ||||
|  | @ -943,10 +913,10 @@ static Node* find_common_ancestor(Node* a, Node* b) | |||
| 
 | ||||
| void Document::set_hovered_node(Node* node) | ||||
| { | ||||
|     if (m_hovered_node == node) | ||||
|     if (m_hovered_node.ptr() == node) | ||||
|         return; | ||||
| 
 | ||||
|     RefPtr<Node> old_hovered_node = move(m_hovered_node); | ||||
|     JS::GCPtr<Node> old_hovered_node = move(m_hovered_node); | ||||
|     m_hovered_node = node; | ||||
| 
 | ||||
|     if (auto* common_ancestor = find_common_ancestor(old_hovered_node, m_hovered_node)) | ||||
|  | @ -1077,13 +1047,6 @@ HTML::EnvironmentSettingsObject& Document::relevant_settings_object() | |||
|     return verify_cast<HTML::EnvironmentSettingsObject>(*realm().host_defined()); | ||||
| } | ||||
| 
 | ||||
| JS::Realm& Document::realm() | ||||
| { | ||||
|     VERIFY(m_window); | ||||
|     VERIFY(m_window->wrapper()); | ||||
|     return m_window->wrapper()->shape().realm(); | ||||
| } | ||||
| 
 | ||||
| JS::Interpreter& Document::interpreter() | ||||
| { | ||||
|     if (!m_interpreter) { | ||||
|  | @ -1115,7 +1078,7 @@ JS::Value Document::run_javascript(StringView source, StringView filename) | |||
| 
 | ||||
| // https://dom.spec.whatwg.org/#dom-document-createelement
 | ||||
| // FIXME: This only implements step 6 of the algorithm and does not take in options.
 | ||||
| DOM::ExceptionOr<NonnullRefPtr<Element>> Document::create_element(String const& tag_name) | ||||
| DOM::ExceptionOr<JS::NonnullGCPtr<Element>> Document::create_element(String const& tag_name) | ||||
| { | ||||
|     if (!is_valid_name(tag_name)) | ||||
|         return DOM::InvalidCharacterError::create("Invalid character in tag name."); | ||||
|  | @ -1127,7 +1090,7 @@ DOM::ExceptionOr<NonnullRefPtr<Element>> Document::create_element(String const& | |||
| // https://dom.spec.whatwg.org/#dom-document-createelementns
 | ||||
| // https://dom.spec.whatwg.org/#internal-createelementns-steps
 | ||||
| // FIXME: This only implements step 4 of the algorithm and does not take in options.
 | ||||
| DOM::ExceptionOr<NonnullRefPtr<Element>> Document::create_element_ns(String const& namespace_, String const& qualified_name) | ||||
| DOM::ExceptionOr<JS::NonnullGCPtr<Element>> Document::create_element_ns(String const& namespace_, String const& qualified_name) | ||||
| { | ||||
|     // 1. Let namespace, prefix, and localName be the result of passing namespace and qualifiedName to validate and extract.
 | ||||
|     auto extracted_qualified_name = TRY(validate_and_extract(namespace_, qualified_name)); | ||||
|  | @ -1139,19 +1102,19 @@ DOM::ExceptionOr<NonnullRefPtr<Element>> Document::create_element_ns(String cons | |||
|     return DOM::create_element(*this, extracted_qualified_name.local_name(), extracted_qualified_name.namespace_(), extracted_qualified_name.prefix()); | ||||
| } | ||||
| 
 | ||||
| NonnullRefPtr<DocumentFragment> Document::create_document_fragment() | ||||
| JS::NonnullGCPtr<DocumentFragment> Document::create_document_fragment() | ||||
| { | ||||
|     return adopt_ref(*new DocumentFragment(*this)); | ||||
|     return *heap().allocate<DocumentFragment>(realm(), *this); | ||||
| } | ||||
| 
 | ||||
| NonnullRefPtr<Text> Document::create_text_node(String const& data) | ||||
| JS::NonnullGCPtr<Text> Document::create_text_node(String const& data) | ||||
| { | ||||
|     return adopt_ref(*new Text(*this, data)); | ||||
|     return *heap().allocate<Text>(realm(), *this, data); | ||||
| } | ||||
| 
 | ||||
| NonnullRefPtr<Comment> Document::create_comment(String const& data) | ||||
| JS::NonnullGCPtr<Comment> Document::create_comment(String const& data) | ||||
| { | ||||
|     return adopt_ref(*new Comment(*this, data)); | ||||
|     return *heap().allocate<Comment>(realm(), *this, data); | ||||
| } | ||||
| 
 | ||||
| JS::NonnullGCPtr<Range> Document::create_range() | ||||
|  | @ -1162,7 +1125,7 @@ JS::NonnullGCPtr<Range> Document::create_range() | |||
| // https://dom.spec.whatwg.org/#dom-document-createevent
 | ||||
| DOM::ExceptionOr<JS::NonnullGCPtr<Event>> Document::create_event(String const& interface) | ||||
| { | ||||
|     auto& window_object = preferred_window_object(); | ||||
|     auto& window_object = window(); | ||||
| 
 | ||||
|     // 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.
 | ||||
|  | @ -1238,33 +1201,36 @@ void Document::set_pending_parsing_blocking_script(Badge<HTML::HTMLScriptElement | |||
|     m_pending_parsing_blocking_script = script; | ||||
| } | ||||
| 
 | ||||
| NonnullRefPtr<HTML::HTMLScriptElement> Document::take_pending_parsing_blocking_script(Badge<HTML::HTMLParser>) | ||||
| JS::NonnullGCPtr<HTML::HTMLScriptElement> Document::take_pending_parsing_blocking_script(Badge<HTML::HTMLParser>) | ||||
| { | ||||
|     return m_pending_parsing_blocking_script.release_nonnull(); | ||||
|     VERIFY(m_pending_parsing_blocking_script); | ||||
|     auto script = m_pending_parsing_blocking_script; | ||||
|     m_pending_parsing_blocking_script = nullptr; | ||||
|     return *script; | ||||
| } | ||||
| 
 | ||||
| void Document::add_script_to_execute_when_parsing_has_finished(Badge<HTML::HTMLScriptElement>, HTML::HTMLScriptElement& script) | ||||
| { | ||||
|     m_scripts_to_execute_when_parsing_has_finished.append(script); | ||||
|     m_scripts_to_execute_when_parsing_has_finished.append(JS::make_handle(script)); | ||||
| } | ||||
| 
 | ||||
| NonnullRefPtrVector<HTML::HTMLScriptElement> Document::take_scripts_to_execute_when_parsing_has_finished(Badge<HTML::HTMLParser>) | ||||
| Vector<JS::Handle<HTML::HTMLScriptElement>> Document::take_scripts_to_execute_when_parsing_has_finished(Badge<HTML::HTMLParser>) | ||||
| { | ||||
|     return move(m_scripts_to_execute_when_parsing_has_finished); | ||||
| } | ||||
| 
 | ||||
| void Document::add_script_to_execute_as_soon_as_possible(Badge<HTML::HTMLScriptElement>, HTML::HTMLScriptElement& script) | ||||
| { | ||||
|     m_scripts_to_execute_as_soon_as_possible.append(script); | ||||
|     m_scripts_to_execute_as_soon_as_possible.append(JS::make_handle(script)); | ||||
| } | ||||
| 
 | ||||
| NonnullRefPtrVector<HTML::HTMLScriptElement> Document::take_scripts_to_execute_as_soon_as_possible(Badge<HTML::HTMLParser>) | ||||
| Vector<JS::Handle<HTML::HTMLScriptElement>> Document::take_scripts_to_execute_as_soon_as_possible(Badge<HTML::HTMLParser>) | ||||
| { | ||||
|     return move(m_scripts_to_execute_as_soon_as_possible); | ||||
| } | ||||
| 
 | ||||
| // https://dom.spec.whatwg.org/#dom-document-importnode
 | ||||
| ExceptionOr<NonnullRefPtr<Node>> Document::import_node(NonnullRefPtr<Node> node, bool deep) | ||||
| ExceptionOr<JS::NonnullGCPtr<Node>> Document::import_node(JS::NonnullGCPtr<Node> node, bool deep) | ||||
| { | ||||
|     // 1. If node is a document or shadow root, then throw a "NotSupportedError" DOMException.
 | ||||
|     if (is<Document>(*node) || is<ShadowRoot>(*node)) | ||||
|  | @ -1299,10 +1265,11 @@ void Document::adopt_node(Node& node) | |||
| 
 | ||||
|         // Transfer NodeIterators rooted at `node` from old_document to this document.
 | ||||
|         Vector<NodeIterator&> node_iterators_to_transfer; | ||||
|         for (auto* node_iterator : old_document.m_node_iterators) { | ||||
|             if (node_iterator->root() == &node) | ||||
|         for (auto node_iterator : old_document.m_node_iterators) { | ||||
|             if (node_iterator->root().ptr() == &node) | ||||
|                 node_iterators_to_transfer.append(*node_iterator); | ||||
|         } | ||||
| 
 | ||||
|         for (auto& node_iterator : node_iterators_to_transfer) { | ||||
|             old_document.m_node_iterators.remove(&node_iterator); | ||||
|             m_node_iterators.set(&node_iterator); | ||||
|  | @ -1311,7 +1278,7 @@ void Document::adopt_node(Node& node) | |||
| } | ||||
| 
 | ||||
| // https://dom.spec.whatwg.org/#dom-document-adoptnode
 | ||||
| ExceptionOr<NonnullRefPtr<Node>> Document::adopt_node_binding(NonnullRefPtr<Node> node) | ||||
| ExceptionOr<JS::NonnullGCPtr<Node>> Document::adopt_node_binding(JS::NonnullGCPtr<Node> node) | ||||
| { | ||||
|     if (is<Document>(*node)) | ||||
|         return DOM::NotSupportedError::create("Cannot adopt a document into a document"); | ||||
|  | @ -1350,7 +1317,7 @@ bool Document::is_editable() const | |||
| 
 | ||||
| void Document::set_focused_element(Element* element) | ||||
| { | ||||
|     if (m_focused_element == element) | ||||
|     if (m_focused_element.ptr() == element) | ||||
|         return; | ||||
| 
 | ||||
|     if (m_focused_element) { | ||||
|  | @ -1371,7 +1338,7 @@ void Document::set_focused_element(Element* element) | |||
| 
 | ||||
| void Document::set_active_element(Element* element) | ||||
| { | ||||
|     if (m_active_element == element) | ||||
|     if (m_active_element.ptr() == element) | ||||
|         return; | ||||
| 
 | ||||
|     m_active_element = element; | ||||
|  | @ -1410,7 +1377,7 @@ void Document::update_readiness(HTML::DocumentReadyState readiness_value) | |||
|     // FIXME:    3. Otherwise, if readinessValue is "interactive", and document's load timing info's DOM interactive time is 0, then set document's load timing info's DOM interactive time to now.
 | ||||
| 
 | ||||
|     // 3. Fire an event named readystatechange at document.
 | ||||
|     dispatch_event(*Event::create(preferred_window_object(), HTML::EventNames::readystatechange)); | ||||
|     dispatch_event(*Event::create(window(), HTML::EventNames::readystatechange)); | ||||
| } | ||||
| 
 | ||||
| Page* Document::page() | ||||
|  | @ -1451,7 +1418,7 @@ void Document::completely_finish_loading() | |||
|     // Otherwise, if container is non-null, then queue an element task on the DOM manipulation task source given container to fire an event named load at container.
 | ||||
|     else if (container) { | ||||
|         container->queue_an_element_task(HTML::Task::Source::DOMManipulation, [container, this]() mutable { | ||||
|             container->dispatch_event(*DOM::Event::create(preferred_window_object(), HTML::EventNames::load)); | ||||
|             container->dispatch_event(*DOM::Event::create(window(), HTML::EventNames::load)); | ||||
|         }); | ||||
|     } | ||||
| } | ||||
|  | @ -1531,7 +1498,7 @@ Bindings::LocationObject* Document::location() | |||
|     if (!is_fully_active()) | ||||
|         return nullptr; | ||||
| 
 | ||||
|     return window().wrapper()->location_object(); | ||||
|     return window().location_object(); | ||||
| } | ||||
| 
 | ||||
| // https://html.spec.whatwg.org/multipage/interaction.html#dom-document-hidden
 | ||||
|  | @ -1562,14 +1529,14 @@ void Document::run_the_resize_steps() | |||
|         return; | ||||
|     m_last_viewport_size = viewport_size; | ||||
| 
 | ||||
|     window().dispatch_event(*DOM::Event::create(preferred_window_object(), UIEvents::EventNames::resize)); | ||||
|     window().dispatch_event(*DOM::Event::create(window(), UIEvents::EventNames::resize)); | ||||
| 
 | ||||
|     update_layout(); | ||||
| } | ||||
| 
 | ||||
| void Document::add_media_query_list(NonnullRefPtr<CSS::MediaQueryList>& media_query_list) | ||||
| void Document::add_media_query_list(JS::NonnullGCPtr<CSS::MediaQueryList> media_query_list) | ||||
| { | ||||
|     m_media_query_lists.append(media_query_list); | ||||
|     m_media_query_lists.append(*media_query_list); | ||||
| } | ||||
| 
 | ||||
| // https://drafts.csswg.org/cssom-view/#evaluate-media-queries-and-report-changes
 | ||||
|  | @ -1590,7 +1557,7 @@ void Document::evaluate_media_queries_and_report_changes() | |||
|         //    and its matches attribute initialized to target’s matches state.
 | ||||
|         if (media_query_list_ptr.is_null()) | ||||
|             continue; | ||||
|         auto media_query_list = media_query_list_ptr.strong_ref(); | ||||
|         JS::GCPtr<CSS::MediaQueryList> media_query_list = media_query_list_ptr.ptr(); | ||||
|         bool did_match = media_query_list->matches(); | ||||
|         bool now_matches = media_query_list->evaluate(); | ||||
| 
 | ||||
|  | @ -1598,7 +1565,7 @@ void Document::evaluate_media_queries_and_report_changes() | |||
|             CSS::MediaQueryListEventInit init; | ||||
|             init.media = media_query_list->media(); | ||||
|             init.matches = now_matches; | ||||
|             auto event = CSS::MediaQueryListEvent::create(preferred_window_object(), HTML::EventNames::change, init); | ||||
|             auto event = CSS::MediaQueryListEvent::create(window(), HTML::EventNames::change, init); | ||||
|             event->set_is_trusted(true); | ||||
|             media_query_list->dispatch_event(*event); | ||||
|         } | ||||
|  | @ -1624,9 +1591,9 @@ void Document::evaluate_media_rules() | |||
| 
 | ||||
| DOMImplementation* Document::implementation() | ||||
| { | ||||
|     if (!m_implementation.cell()) | ||||
|         m_implementation = JS::make_handle(*DOMImplementation::create(*this)); | ||||
|     return m_implementation.cell(); | ||||
|     if (!m_implementation) | ||||
|         m_implementation = DOMImplementation::create(*this); | ||||
|     return m_implementation; | ||||
| } | ||||
| 
 | ||||
| bool Document::has_focus() const | ||||
|  | @ -1821,7 +1788,7 @@ void Document::check_favicon_after_loading_link_resource() | |||
|     for (auto i = favicon_link_elements->length(); i-- > 0;) { | ||||
|         auto favicon_element = favicon_link_elements->item(i); | ||||
| 
 | ||||
|         if (favicon_element == m_active_element) | ||||
|         if (favicon_element == m_active_element.ptr()) | ||||
|             return; | ||||
| 
 | ||||
|         // If the user agent tries to use an icon but that icon is determined, upon closer examination,
 | ||||
|  | @ -1838,14 +1805,19 @@ void Document::check_favicon_after_loading_link_resource() | |||
| 
 | ||||
| void Document::set_window(Badge<HTML::BrowsingContext>, HTML::Window& window) | ||||
| { | ||||
|     m_window = window; | ||||
|     m_window = &window; | ||||
| } | ||||
| 
 | ||||
| Bindings::WindowObject& Document::preferred_window_object() const | ||||
| CSS::StyleSheetList& Document::style_sheets() | ||||
| { | ||||
|     if (m_window && m_window->wrapper()) | ||||
|         return const_cast<Bindings::WindowObject&>(*m_window->wrapper()); | ||||
|     return Bindings::main_thread_internal_window_object(); | ||||
|     if (!m_style_sheets) | ||||
|         m_style_sheets = CSS::StyleSheetList::create(*this); | ||||
|     return *m_style_sheets; | ||||
| } | ||||
| 
 | ||||
| CSS::StyleSheetList const& Document::style_sheets() const | ||||
| { | ||||
|     return const_cast<Document*>(this)->style_sheets(); | ||||
| } | ||||
| 
 | ||||
| } | ||||
|  |  | |||
|  | @ -17,7 +17,6 @@ | |||
| #include <AK/WeakPtr.h> | ||||
| #include <LibCore/Forward.h> | ||||
| #include <LibJS/Forward.h> | ||||
| #include <LibWeb/Bindings/WindowObject.h> | ||||
| #include <LibWeb/CSS/CSSStyleSheet.h> | ||||
| #include <LibWeb/CSS/StyleComputer.h> | ||||
| #include <LibWeb/CSS/StyleSheetList.h> | ||||
|  | @ -31,6 +30,7 @@ | |||
| #include <LibWeb/HTML/History.h> | ||||
| #include <LibWeb/HTML/Origin.h> | ||||
| #include <LibWeb/HTML/Scripting/Environments.h> | ||||
| #include <LibWeb/HTML/Window.h> | ||||
| 
 | ||||
| namespace Web::DOM { | ||||
| 
 | ||||
|  | @ -44,25 +44,20 @@ class Document | |||
|     : public ParentNode | ||||
|     , public NonElementParentNode<Document> | ||||
|     , public HTML::GlobalEventHandlers { | ||||
| public: | ||||
|     using WrapperType = Bindings::DocumentWrapper; | ||||
|     WEB_PLATFORM_OBJECT(Document, ParentNode); | ||||
| 
 | ||||
| public: | ||||
|     enum class Type { | ||||
|         XML, | ||||
|         HTML | ||||
|     }; | ||||
| 
 | ||||
|     static NonnullRefPtr<Document> create_and_initialize(Type, String content_type, HTML::NavigationParams); | ||||
|     static JS::NonnullGCPtr<Document> create_and_initialize(Type, String content_type, HTML::NavigationParams); | ||||
| 
 | ||||
|     static NonnullRefPtr<Document> create(AK::URL const& url = "about:blank"sv); | ||||
|     static NonnullRefPtr<Document> create_with_global_object(Bindings::WindowObject&); | ||||
|     static JS::NonnullGCPtr<Document> create(HTML::Window&, AK::URL const& url = "about:blank"sv); | ||||
|     static JS::NonnullGCPtr<Document> create_with_global_object(HTML::Window&); | ||||
|     virtual ~Document() override; | ||||
| 
 | ||||
|     // NOTE: This returns the web-facing window object if there is one,
 | ||||
|     //       otherwise it returns the internal window object.
 | ||||
|     // FIXME: Remove this when Document is a JS::Object.
 | ||||
|     Bindings::WindowObject& preferred_window_object() const; | ||||
| 
 | ||||
|     size_t next_layout_node_serial_id(Badge<Layout::Node>) { return m_next_layout_node_serial_id++; } | ||||
|     size_t layout_node_count() const { return m_next_layout_node_serial_id; } | ||||
| 
 | ||||
|  | @ -80,7 +75,7 @@ public: | |||
|     AK::URL fallback_base_url() const; | ||||
|     AK::URL base_url() const; | ||||
| 
 | ||||
|     RefPtr<HTML::HTMLBaseElement> first_base_element_with_href_in_tree_order() const; | ||||
|     JS::GCPtr<HTML::HTMLBaseElement> first_base_element_with_href_in_tree_order() const; | ||||
| 
 | ||||
|     String url_string() const { return m_url.to_string(); } | ||||
|     String document_uri() const { return m_url.to_string(); } | ||||
|  | @ -96,20 +91,20 @@ public: | |||
|     CSS::StyleComputer& style_computer() { return *m_style_computer; } | ||||
|     const CSS::StyleComputer& style_computer() const { return *m_style_computer; } | ||||
| 
 | ||||
|     CSS::StyleSheetList& style_sheets() { return *m_style_sheets; } | ||||
|     const CSS::StyleSheetList& style_sheets() const { return *m_style_sheets; } | ||||
|     CSS::StyleSheetList& style_sheets(); | ||||
|     CSS::StyleSheetList const& style_sheets() const; | ||||
| 
 | ||||
|     CSS::StyleSheetList* style_sheets_for_bindings() { return m_style_sheets.cell(); } | ||||
|     CSS::StyleSheetList* style_sheets_for_bindings() { return &style_sheets(); } | ||||
| 
 | ||||
|     virtual FlyString node_name() const override { return "#document"; } | ||||
| 
 | ||||
|     void set_hovered_node(Node*); | ||||
|     Node* hovered_node() { return m_hovered_node; } | ||||
|     Node const* hovered_node() const { return m_hovered_node; } | ||||
|     Node* hovered_node() { return m_hovered_node.ptr(); } | ||||
|     Node const* hovered_node() const { return m_hovered_node.ptr(); } | ||||
| 
 | ||||
|     void set_inspected_node(Node*); | ||||
|     Node* inspected_node() { return m_inspected_node; } | ||||
|     Node const* inspected_node() const { return m_inspected_node; } | ||||
|     Node* inspected_node() { return m_inspected_node.ptr(); } | ||||
|     Node const* inspected_node() const { return m_inspected_node.ptr(); } | ||||
| 
 | ||||
|     Element* document_element(); | ||||
|     Element const* document_element() const; | ||||
|  | @ -193,30 +188,29 @@ public: | |||
|     void set_source(String const& source) { m_source = source; } | ||||
| 
 | ||||
|     HTML::EnvironmentSettingsObject& relevant_settings_object(); | ||||
|     JS::Realm& realm(); | ||||
|     JS::Interpreter& interpreter(); | ||||
| 
 | ||||
|     JS::Value run_javascript(StringView source, StringView filename = "(unknown)"sv); | ||||
| 
 | ||||
|     ExceptionOr<NonnullRefPtr<Element>> create_element(String const& tag_name); | ||||
|     ExceptionOr<NonnullRefPtr<Element>> create_element_ns(String const& namespace_, String const& qualified_name); | ||||
|     NonnullRefPtr<DocumentFragment> create_document_fragment(); | ||||
|     NonnullRefPtr<Text> create_text_node(String const& data); | ||||
|     NonnullRefPtr<Comment> create_comment(String const& data); | ||||
|     ExceptionOr<JS::NonnullGCPtr<Element>> create_element(String const& tag_name); | ||||
|     ExceptionOr<JS::NonnullGCPtr<Element>> create_element_ns(String const& namespace_, String const& qualified_name); | ||||
|     JS::NonnullGCPtr<DocumentFragment> create_document_fragment(); | ||||
|     JS::NonnullGCPtr<Text> create_text_node(String const& data); | ||||
|     JS::NonnullGCPtr<Comment> create_comment(String const& data); | ||||
|     ExceptionOr<JS::NonnullGCPtr<Event>> create_event(String const& interface); | ||||
|     JS::NonnullGCPtr<Range> create_range(); | ||||
| 
 | ||||
|     void set_pending_parsing_blocking_script(Badge<HTML::HTMLScriptElement>, HTML::HTMLScriptElement*); | ||||
|     HTML::HTMLScriptElement* pending_parsing_blocking_script() { return m_pending_parsing_blocking_script; } | ||||
|     NonnullRefPtr<HTML::HTMLScriptElement> take_pending_parsing_blocking_script(Badge<HTML::HTMLParser>); | ||||
|     HTML::HTMLScriptElement* pending_parsing_blocking_script() { return m_pending_parsing_blocking_script.ptr(); } | ||||
|     JS::NonnullGCPtr<HTML::HTMLScriptElement> take_pending_parsing_blocking_script(Badge<HTML::HTMLParser>); | ||||
| 
 | ||||
|     void add_script_to_execute_when_parsing_has_finished(Badge<HTML::HTMLScriptElement>, HTML::HTMLScriptElement&); | ||||
|     NonnullRefPtrVector<HTML::HTMLScriptElement> take_scripts_to_execute_when_parsing_has_finished(Badge<HTML::HTMLParser>); | ||||
|     NonnullRefPtrVector<HTML::HTMLScriptElement>& scripts_to_execute_when_parsing_has_finished() { return m_scripts_to_execute_when_parsing_has_finished; } | ||||
|     Vector<JS::Handle<HTML::HTMLScriptElement>> take_scripts_to_execute_when_parsing_has_finished(Badge<HTML::HTMLParser>); | ||||
|     Vector<JS::Handle<HTML::HTMLScriptElement>>& scripts_to_execute_when_parsing_has_finished() { return m_scripts_to_execute_when_parsing_has_finished; } | ||||
| 
 | ||||
|     void add_script_to_execute_as_soon_as_possible(Badge<HTML::HTMLScriptElement>, HTML::HTMLScriptElement&); | ||||
|     NonnullRefPtrVector<HTML::HTMLScriptElement> take_scripts_to_execute_as_soon_as_possible(Badge<HTML::HTMLParser>); | ||||
|     NonnullRefPtrVector<HTML::HTMLScriptElement>& scripts_to_execute_as_soon_as_possible() { return m_scripts_to_execute_as_soon_as_possible; } | ||||
|     Vector<JS::Handle<HTML::HTMLScriptElement>> take_scripts_to_execute_as_soon_as_possible(Badge<HTML::HTMLParser>); | ||||
|     Vector<JS::Handle<HTML::HTMLScriptElement>>& scripts_to_execute_as_soon_as_possible() { return m_scripts_to_execute_as_soon_as_possible; } | ||||
| 
 | ||||
|     QuirksMode mode() const { return m_quirks_mode; } | ||||
|     bool in_quirks_mode() const { return m_quirks_mode == QuirksMode::Yes; } | ||||
|  | @ -228,9 +222,9 @@ public: | |||
|     // https://dom.spec.whatwg.org/#xml-document
 | ||||
|     bool is_xml_document() const { return m_type == Type::XML; } | ||||
| 
 | ||||
|     ExceptionOr<NonnullRefPtr<Node>> import_node(NonnullRefPtr<Node> node, bool deep); | ||||
|     ExceptionOr<JS::NonnullGCPtr<Node>> import_node(JS::NonnullGCPtr<Node> node, bool deep); | ||||
|     void adopt_node(Node&); | ||||
|     ExceptionOr<NonnullRefPtr<Node>> adopt_node_binding(NonnullRefPtr<Node>); | ||||
|     ExceptionOr<JS::NonnullGCPtr<Node>> adopt_node_binding(JS::NonnullGCPtr<Node>); | ||||
| 
 | ||||
|     DocumentType const* doctype() const; | ||||
|     String const& compat_mode() const; | ||||
|  | @ -238,39 +232,26 @@ public: | |||
|     void set_editable(bool editable) { m_editable = editable; } | ||||
|     virtual bool is_editable() const final; | ||||
| 
 | ||||
|     Element* focused_element() { return m_focused_element; } | ||||
|     Element const* focused_element() const { return m_focused_element; } | ||||
|     Element* focused_element() { return m_focused_element.ptr(); } | ||||
|     Element const* focused_element() const { return m_focused_element.ptr(); } | ||||
| 
 | ||||
|     void set_focused_element(Element*); | ||||
| 
 | ||||
|     Element const* active_element() const { return m_active_element; } | ||||
|     Element const* active_element() const { return m_active_element.ptr(); } | ||||
| 
 | ||||
|     void set_active_element(Element*); | ||||
| 
 | ||||
|     bool created_for_appropriate_template_contents() const { return m_created_for_appropriate_template_contents; } | ||||
|     void set_created_for_appropriate_template_contents(bool value) { m_created_for_appropriate_template_contents = value; } | ||||
| 
 | ||||
|     Document* associated_inert_template_document() { return m_associated_inert_template_document; } | ||||
|     Document const* associated_inert_template_document() const { return m_associated_inert_template_document; } | ||||
|     void set_associated_inert_template_document(Document& document) { m_associated_inert_template_document = document; } | ||||
|     Document* associated_inert_template_document() { return m_associated_inert_template_document.ptr(); } | ||||
|     Document const* associated_inert_template_document() const { return m_associated_inert_template_document.ptr(); } | ||||
|     void set_associated_inert_template_document(Document& document) { m_associated_inert_template_document = &document; } | ||||
| 
 | ||||
|     String ready_state() const; | ||||
|     void update_readiness(HTML::DocumentReadyState); | ||||
| 
 | ||||
|     void ref_from_node(Badge<Node>) | ||||
|     { | ||||
|         increment_referencing_node_count(); | ||||
|     } | ||||
| 
 | ||||
|     void unref_from_node(Badge<Node>) | ||||
|     { | ||||
|         decrement_referencing_node_count(); | ||||
|     } | ||||
| 
 | ||||
|     void removed_last_ref(); | ||||
| 
 | ||||
|     HTML::Window& window() { return *m_window; } | ||||
|     HTML::Window const& window() const { return *m_window; } | ||||
|     HTML::Window& window() const { return const_cast<HTML::Window&>(*m_window); } | ||||
| 
 | ||||
|     void set_window(Badge<HTML::BrowsingContext>, HTML::Window&); | ||||
| 
 | ||||
|  | @ -280,7 +261,7 @@ public: | |||
|     ExceptionOr<Document*> open(String const& = "", String const& = ""); | ||||
|     ExceptionOr<void> close(); | ||||
| 
 | ||||
|     HTML::Window* default_view() { return m_window; } | ||||
|     HTML::Window* default_view() { return m_window.ptr(); } | ||||
| 
 | ||||
|     String const& content_type() const { return m_content_type; } | ||||
|     void set_content_type(String const& content_type) { m_content_type = content_type; } | ||||
|  | @ -302,8 +283,8 @@ public: | |||
| 
 | ||||
|     DOMImplementation* implementation(); | ||||
| 
 | ||||
|     RefPtr<HTML::HTMLScriptElement> current_script() const { return m_current_script; } | ||||
|     void set_current_script(Badge<HTML::HTMLScriptElement>, RefPtr<HTML::HTMLScriptElement> script) { m_current_script = move(script); } | ||||
|     JS::GCPtr<HTML::HTMLScriptElement> current_script() const { return m_current_script.ptr(); } | ||||
|     void set_current_script(Badge<HTML::HTMLScriptElement>, JS::GCPtr<HTML::HTMLScriptElement> script) { m_current_script = move(script); } | ||||
| 
 | ||||
|     u32 ignore_destructive_writes_counter() const { return m_ignore_destructive_writes_counter; } | ||||
|     void increment_ignore_destructive_writes_counter() { m_ignore_destructive_writes_counter++; } | ||||
|  | @ -335,7 +316,7 @@ public: | |||
|     void run_the_resize_steps(); | ||||
| 
 | ||||
|     void evaluate_media_queries_and_report_changes(); | ||||
|     void add_media_query_list(NonnullRefPtr<CSS::MediaQueryList>&); | ||||
|     void add_media_query_list(JS::NonnullGCPtr<CSS::MediaQueryList>); | ||||
| 
 | ||||
|     bool has_focus() const; | ||||
| 
 | ||||
|  | @ -359,15 +340,13 @@ public: | |||
|     template<typename Callback> | ||||
|     void for_each_node_iterator(Callback callback) | ||||
|     { | ||||
|         for (auto* node_iterator : m_node_iterators) | ||||
|         for (auto& node_iterator : m_node_iterators) | ||||
|             callback(*node_iterator); | ||||
|     } | ||||
| 
 | ||||
|     bool needs_full_style_update() const { return m_needs_full_style_update; } | ||||
|     void set_needs_full_style_update(bool b) { m_needs_full_style_update = b; } | ||||
| 
 | ||||
|     bool in_removed_last_ref() const { return m_in_removed_last_ref; } | ||||
| 
 | ||||
|     bool has_active_favicon() const { return m_active_favicon; } | ||||
|     void check_favicon_after_loading_link_resource(); | ||||
| 
 | ||||
|  | @ -375,8 +354,11 @@ public: | |||
|     bool is_initial_about_blank() const { return m_is_initial_about_blank; } | ||||
|     void set_is_initial_about_blank(bool b) { m_is_initial_about_blank = b; } | ||||
| 
 | ||||
| protected: | ||||
|     virtual void visit_edges(Cell::Visitor&) override; | ||||
| 
 | ||||
| private: | ||||
|     explicit Document(const AK::URL&); | ||||
|     Document(HTML::Window&, AK::URL const&); | ||||
| 
 | ||||
|     // ^HTML::GlobalEventHandlers
 | ||||
|     virtual EventTarget& global_event_handlers_to_event_target(FlyString const&) final { return *this; } | ||||
|  | @ -387,36 +369,17 @@ private: | |||
| 
 | ||||
|     ExceptionOr<void> run_the_document_write_steps(String); | ||||
| 
 | ||||
|     void increment_referencing_node_count() | ||||
|     { | ||||
|         VERIFY(!m_deletion_has_begun); | ||||
|         ++m_referencing_node_count; | ||||
|     } | ||||
| 
 | ||||
|     void decrement_referencing_node_count() | ||||
|     { | ||||
|         VERIFY(!m_deletion_has_begun); | ||||
|         VERIFY(m_referencing_node_count); | ||||
|         --m_referencing_node_count; | ||||
|         if (!m_referencing_node_count && !ref_count()) { | ||||
|             m_deletion_has_begun = true; | ||||
|             delete this; | ||||
|         } | ||||
|     } | ||||
| 
 | ||||
|     unsigned m_referencing_node_count { 0 }; | ||||
| 
 | ||||
|     size_t m_next_layout_node_serial_id { 0 }; | ||||
| 
 | ||||
|     OwnPtr<CSS::StyleComputer> m_style_computer; | ||||
|     JS::Handle<CSS::StyleSheetList> m_style_sheets; | ||||
|     RefPtr<Node> m_hovered_node; | ||||
|     RefPtr<Node> m_inspected_node; | ||||
|     RefPtr<Node> m_active_favicon; | ||||
|     JS::GCPtr<CSS::StyleSheetList> m_style_sheets; | ||||
|     JS::GCPtr<Node> m_hovered_node; | ||||
|     JS::GCPtr<Node> m_inspected_node; | ||||
|     JS::GCPtr<Node> m_active_favicon; | ||||
|     WeakPtr<HTML::BrowsingContext> m_browsing_context; | ||||
|     AK::URL m_url; | ||||
| 
 | ||||
|     RefPtr<HTML::Window> m_window; | ||||
|     JS::GCPtr<HTML::Window> m_window; | ||||
| 
 | ||||
|     RefPtr<Layout::InitialContainingBlock> m_layout_root; | ||||
| 
 | ||||
|  | @ -434,9 +397,9 @@ private: | |||
| 
 | ||||
|     OwnPtr<JS::Interpreter> m_interpreter; | ||||
| 
 | ||||
|     RefPtr<HTML::HTMLScriptElement> m_pending_parsing_blocking_script; | ||||
|     NonnullRefPtrVector<HTML::HTMLScriptElement> m_scripts_to_execute_when_parsing_has_finished; | ||||
|     NonnullRefPtrVector<HTML::HTMLScriptElement> m_scripts_to_execute_as_soon_as_possible; | ||||
|     JS::GCPtr<HTML::HTMLScriptElement> m_pending_parsing_blocking_script; | ||||
|     Vector<JS::Handle<HTML::HTMLScriptElement>> m_scripts_to_execute_when_parsing_has_finished; | ||||
|     Vector<JS::Handle<HTML::HTMLScriptElement>> m_scripts_to_execute_as_soon_as_possible; | ||||
| 
 | ||||
|     QuirksMode m_quirks_mode { QuirksMode::No }; | ||||
| 
 | ||||
|  | @ -445,11 +408,11 @@ private: | |||
| 
 | ||||
|     bool m_editable { false }; | ||||
| 
 | ||||
|     WeakPtr<Element> m_focused_element; | ||||
|     WeakPtr<Element> m_active_element; | ||||
|     JS::GCPtr<Element> m_focused_element; | ||||
|     JS::GCPtr<Element> m_active_element; | ||||
| 
 | ||||
|     bool m_created_for_appropriate_template_contents { false }; | ||||
|     RefPtr<Document> m_associated_inert_template_document; | ||||
|     JS::GCPtr<Document> m_associated_inert_template_document; | ||||
| 
 | ||||
|     HTML::DocumentReadyState m_readiness { HTML::DocumentReadyState::Loading }; | ||||
|     String m_content_type { "application/xml" }; | ||||
|  | @ -457,8 +420,8 @@ private: | |||
| 
 | ||||
|     bool m_ready_for_post_load_tasks { false }; | ||||
| 
 | ||||
|     JS::Handle<DOMImplementation> m_implementation; | ||||
|     RefPtr<HTML::HTMLScriptElement> m_current_script; | ||||
|     JS::GCPtr<DOMImplementation> m_implementation; | ||||
|     JS::GCPtr<HTML::HTMLScriptElement> m_current_script; | ||||
| 
 | ||||
|     bool m_should_invalidate_styles_on_attribute_changes { true }; | ||||
| 
 | ||||
|  | @ -506,3 +469,5 @@ private: | |||
| }; | ||||
| 
 | ||||
| } | ||||
| 
 | ||||
| WRAPPER_HACK(Document, Web::DOM) | ||||
|  |  | |||
|  | @ -4,6 +4,7 @@ | |||
|  * SPDX-License-Identifier: BSD-2-Clause | ||||
|  */ | ||||
| 
 | ||||
| #include <LibWeb/Bindings/DocumentFragmentPrototype.h> | ||||
| #include <LibWeb/DOM/DocumentFragment.h> | ||||
| #include <LibWeb/HTML/Window.h> | ||||
| 
 | ||||
|  | @ -12,12 +13,24 @@ namespace Web::DOM { | |||
| DocumentFragment::DocumentFragment(Document& document) | ||||
|     : ParentNode(document, NodeType::DOCUMENT_FRAGMENT_NODE) | ||||
| { | ||||
|     set_prototype(&window().ensure_web_prototype<Bindings::DocumentFragmentPrototype>("DocumentFragment")); | ||||
| } | ||||
| 
 | ||||
| void DocumentFragment::visit_edges(Cell::Visitor& visitor) | ||||
| { | ||||
|     Base::visit_edges(visitor); | ||||
|     visitor.visit(m_host.ptr()); | ||||
| } | ||||
| 
 | ||||
| void DocumentFragment::set_host(Web::DOM::Element* element) | ||||
| { | ||||
|     m_host = element; | ||||
| } | ||||
| 
 | ||||
| // https://dom.spec.whatwg.org/#dom-documentfragment-documentfragment
 | ||||
| NonnullRefPtr<DocumentFragment> DocumentFragment::create_with_global_object(Bindings::WindowObject& window) | ||||
| JS::NonnullGCPtr<DocumentFragment> DocumentFragment::create_with_global_object(HTML::Window& window) | ||||
| { | ||||
|     return make_ref_counted<DocumentFragment>(window.impl().associated_document()); | ||||
|     return *window.heap().allocate<DocumentFragment>(window.realm(), window.associated_document()); | ||||
| } | ||||
| 
 | ||||
| } | ||||
|  |  | |||
|  | @ -16,27 +16,33 @@ namespace Web::DOM { | |||
| class DocumentFragment | ||||
|     : public ParentNode | ||||
|     , public NonElementParentNode<DocumentFragment> { | ||||
|     WEB_PLATFORM_OBJECT(DocumentFragment, ParentNode); | ||||
| 
 | ||||
| public: | ||||
|     using WrapperType = Bindings::DocumentFragmentWrapper; | ||||
|     static JS::NonnullGCPtr<DocumentFragment> create_with_global_object(HTML::Window& window); | ||||
| 
 | ||||
|     static NonnullRefPtr<DocumentFragment> create_with_global_object(Bindings::WindowObject& window); | ||||
| 
 | ||||
|     explicit DocumentFragment(Document& document); | ||||
|     virtual ~DocumentFragment() override = default; | ||||
| 
 | ||||
|     virtual FlyString node_name() const override { return "#document-fragment"; } | ||||
| 
 | ||||
|     Element* host() { return m_host; } | ||||
|     Element const* host() const { return m_host; } | ||||
|     Element* host() { return m_host.ptr(); } | ||||
|     Element const* host() const { return m_host.ptr(); } | ||||
| 
 | ||||
|     void set_host(Element* host) { m_host = host; } | ||||
|     void set_host(Element*); | ||||
| 
 | ||||
| protected: | ||||
|     explicit DocumentFragment(Document& document); | ||||
| 
 | ||||
|     virtual void visit_edges(Cell::Visitor&) override; | ||||
| 
 | ||||
| private: | ||||
|     // https://dom.spec.whatwg.org/#concept-documentfragment-host
 | ||||
|     WeakPtr<Element> m_host; | ||||
|     JS::GCPtr<Element> m_host; | ||||
| }; | ||||
| 
 | ||||
| template<> | ||||
| inline bool Node::fast_is<DocumentFragment>() const { return is_document_fragment(); } | ||||
| 
 | ||||
| } | ||||
| 
 | ||||
| WRAPPER_HACK(DocumentFragment, Web::DOM) | ||||
|  |  | |||
Some files were not shown because too many files have changed in this diff Show more
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Andreas Kling
						Andreas Kling