1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-28 03:47:34 +00:00

LibWeb+LibJS: Make the EventTarget hierarchy (incl. DOM) GC-allocated

This is a monster patch that turns all EventTargets into GC-allocated
PlatformObjects. Their C++ wrapper classes are removed, and the LibJS
garbage collector is now responsible for their lifetimes.

There's a fair amount of hacks and band-aids in this patch, and we'll
have a lot of cleanup to do after this.
This commit is contained in:
Andreas Kling 2022-08-28 13:42:07 +02:00
parent bb547ce1c4
commit 6f433c8656
445 changed files with 4797 additions and 4268 deletions

View file

@ -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();
}
}

View file

@ -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();

View file

@ -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&);
}

View file

@ -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);
}
}

View file

@ -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&);
}

View file

@ -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));

View file

@ -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();
}
}

View file

@ -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;

View file

@ -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);

View file

@ -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));

View file

@ -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 {

View file

@ -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.

View file

@ -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);
}

View file

@ -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);

View file

@ -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"))
{
}

View file

@ -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 {

View file

@ -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));
}
}

View file

@ -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&);
}
}

View file

@ -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();
}
}

View file

@ -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());
}
}

View file

@ -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);
};

View file

@ -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);

View file

@ -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
}

View file

@ -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;
};
}

View file

@ -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); \
}

View file

@ -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"))
{
}
};

View file

@ -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());
}
}

View file

@ -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;
};
}

View file

@ -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>();
}
}

View file

@ -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;