LibWeb: Remove unecessary dependence on Window from HTML classes

These classes only needed Window to get at its realm. Pass a realm
directly to construct HTML classes.
This commit is contained in:
Andrew Kaster 2022-09-25 16:38:21 -06:00 committed by Linus Groh
parent a2ccb00e1d
commit f0c5f77f99
Notes: sideshowbarker 2024-07-17 06:28:27 +09:00
122 changed files with 334 additions and 317 deletions

View file

@ -134,7 +134,7 @@ JS::VM& main_thread_vm()
/* .promise = */ promise,
/* .reason = */ promise.result(),
};
auto promise_rejection_event = HTML::PromiseRejectionEvent::create(window, HTML::EventNames::rejectionhandled, event_init);
auto promise_rejection_event = HTML::PromiseRejectionEvent::create(HTML::relevant_realm(global), HTML::EventNames::rejectionhandled, event_init);
window.dispatch_event(*promise_rejection_event);
});
break;

View file

@ -1210,7 +1210,7 @@ WebIDL::ExceptionOr<JS::NonnullGCPtr<Event>> Document::create_event(String const
} else if (interface_lowercase == "keyboardevent") {
event = UIEvents::KeyboardEvent::create(window, "");
} else if (interface_lowercase == "messageevent") {
event = HTML::MessageEvent::create(window, "");
event = HTML::MessageEvent::create(realm, "");
} else if (interface_lowercase.is_one_of("mouseevent", "mouseevents")) {
event = UIEvents::MouseEvent::create(window, "");
} else if (interface_lowercase == "storageevent") {
@ -1967,7 +1967,7 @@ CSS::StyleSheetList const& Document::style_sheets() const
JS::NonnullGCPtr<HTML::History> Document::history()
{
if (!m_history)
m_history = HTML::History::create(window(), *this);
m_history = HTML::History::create(realm(), *this);
return *m_history;
}

View file

@ -187,7 +187,7 @@ NonnullRefPtr<BrowsingContext> BrowsingContext::create_a_new_browsing_context(Pa
// load timing info is loadTimingInfo,
// FIXME: navigation id is null,
// and which is ready for post-load tasks.
auto document = DOM::Document::create(*window);
auto document = DOM::Document::create(window->realm());
// Non-standard
document->set_window({}, *window);
@ -885,7 +885,7 @@ WebIDL::ExceptionOr<void> BrowsingContext::navigate(
// 1. If exceptionsEnabled is given and is true, then throw a "SecurityError" DOMException.
if (exceptions_enabled) {
VERIFY(source_browsing_context.active_document());
return WebIDL::SecurityError::create(source_browsing_context.active_document()->global_object(), "Source browsing context not allowed to navigate"sv);
return WebIDL::SecurityError::create(source_browsing_context.active_document()->realm(), "Source browsing context not allowed to navigate"sv);
}
// FIXME: 2. Otherwise, the user agent may instead offer to open resource in a new top-level browsing context
@ -1184,7 +1184,7 @@ WebIDL::ExceptionOr<void> BrowsingContext::traverse_the_history(size_t entry_ind
// and the newURL attribute initialized to newURL.
// FIXME: Implement a proper HashChangeEvent class.
auto event = DOM::Event::create(verify_cast<HTML::Window>(relevant_global_object(*new_document)), HTML::EventNames::hashchange);
auto event = DOM::Event::create(verify_cast<HTML::Window>(relevant_global_object(*new_document)).realm(), HTML::EventNames::hashchange);
new_document->dispatch_event(event);
});
}

View file

@ -44,20 +44,20 @@ public:
JS::NonnullGCPtr<CanvasGradient> create_radial_gradient(double x0, double y0, double r0, double x1, double y1, double r1)
{
auto& window = static_cast<IncludingClass&>(*this).global_object();
return CanvasGradient::create_radial(window, x0, y0, r0, x1, y1, r1);
auto& realm = static_cast<IncludingClass&>(*this).realm();
return CanvasGradient::create_radial(realm, x0, y0, r0, x1, y1, r1);
}
JS::NonnullGCPtr<CanvasGradient> create_linear_gradient(double x0, double y0, double x1, double y1)
{
auto& window = static_cast<IncludingClass&>(*this).global_object();
return CanvasGradient::create_linear(window, x0, y0, x1, y1);
auto& realm = static_cast<IncludingClass&>(*this).realm();
return CanvasGradient::create_linear(realm, x0, y0, x1, y1);
}
JS::NonnullGCPtr<CanvasGradient> create_conic_gradient(double start_angle, double x, double y)
{
auto& window = static_cast<IncludingClass&>(*this).global_object();
return CanvasGradient::create_conic(window, start_angle, x, y);
auto& realm = static_cast<IncludingClass&>(*this).realm();
return CanvasGradient::create_conic(realm, start_angle, x, y);
}
protected:

View file

@ -7,7 +7,6 @@
#include <AK/ExtraMathConstants.h>
#include <LibWeb/HTML/Canvas/CanvasPath.h>
#include <LibWeb/HTML/Window.h>
namespace Web::HTML {
@ -39,17 +38,17 @@ void CanvasPath::bezier_curve_to(double cp1x, double cp1y, double cp2x, double c
WebIDL::ExceptionOr<void> CanvasPath::arc(float x, float y, float radius, float start_angle, float end_angle, bool counter_clockwise)
{
if (radius < 0)
return WebIDL::IndexSizeError::create(m_self.global_object(), String::formatted("The radius provided ({}) is negative.", radius));
return WebIDL::IndexSizeError::create(m_self.realm(), String::formatted("The radius provided ({}) is negative.", radius));
return ellipse(x, y, radius, radius, 0, start_angle, end_angle, counter_clockwise);
}
WebIDL::ExceptionOr<void> CanvasPath::ellipse(float x, float y, float radius_x, float radius_y, float rotation, float start_angle, float end_angle, bool counter_clockwise)
{
if (radius_x < 0)
return WebIDL::IndexSizeError::create(m_self.global_object(), String::formatted("The major-axis radius provided ({}) is negative.", radius_x));
return WebIDL::IndexSizeError::create(m_self.realm(), String::formatted("The major-axis radius provided ({}) is negative.", radius_x));
if (radius_y < 0)
return WebIDL::IndexSizeError::create(m_self.global_object(), String::formatted("The minor-axis radius provided ({}) is negative.", radius_y));
return WebIDL::IndexSizeError::create(m_self.realm(), String::formatted("The minor-axis radius provided ({}) is negative.", radius_y));
if (constexpr float tau = M_TAU; (!counter_clockwise && (end_angle - start_angle) >= tau)
|| (counter_clockwise && (start_angle - end_angle) >= tau)) {

View file

@ -5,13 +5,13 @@
*/
#include <AK/QuickSort.h>
#include <LibWeb/Bindings/Intrinsics.h>
#include <LibWeb/HTML/CanvasGradient.h>
#include <LibWeb/HTML/Window.h>
#include <LibWeb/WebIDL/ExceptionOr.h>
namespace Web::HTML {
JS::NonnullGCPtr<CanvasGradient> CanvasGradient::create_radial(HTML::Window& window, double x0, double y0, double r0, double x1, double y1, double r1)
JS::NonnullGCPtr<CanvasGradient> CanvasGradient::create_radial(JS::Realm& realm, double x0, double y0, double r0, double x1, double y1, double r1)
{
(void)x0;
(void)y0;
@ -19,31 +19,31 @@ JS::NonnullGCPtr<CanvasGradient> CanvasGradient::create_radial(HTML::Window& win
(void)x1;
(void)y1;
(void)r1;
return *window.heap().allocate<CanvasGradient>(window.realm(), window, Type::Radial);
return *realm.heap().allocate<CanvasGradient>(realm, realm, Type::Radial);
}
JS::NonnullGCPtr<CanvasGradient> CanvasGradient::create_linear(HTML::Window& window, double x0, double y0, double x1, double y1)
JS::NonnullGCPtr<CanvasGradient> CanvasGradient::create_linear(JS::Realm& realm, double x0, double y0, double x1, double y1)
{
(void)x0;
(void)y0;
(void)x1;
(void)y1;
return *window.heap().allocate<CanvasGradient>(window.realm(), window, Type::Linear);
return *realm.heap().allocate<CanvasGradient>(realm, realm, Type::Linear);
}
JS::NonnullGCPtr<CanvasGradient> CanvasGradient::create_conic(HTML::Window& window, double start_angle, double x, double y)
JS::NonnullGCPtr<CanvasGradient> CanvasGradient::create_conic(JS::Realm& realm, double start_angle, double x, double y)
{
(void)start_angle;
(void)x;
(void)y;
return *window.heap().allocate<CanvasGradient>(window.realm(), window, Type::Conic);
return *realm.heap().allocate<CanvasGradient>(realm, realm, Type::Conic);
}
CanvasGradient::CanvasGradient(HTML::Window& window, Type type)
: PlatformObject(window.realm())
CanvasGradient::CanvasGradient(JS::Realm& realm, Type type)
: PlatformObject(realm)
, m_type(type)
{
set_prototype(&window.cached_web_prototype("CanvasGradient"));
set_prototype(&Bindings::cached_web_prototype(realm, "CanvasGradient"));
}
CanvasGradient::~CanvasGradient() = default;
@ -53,14 +53,14 @@ WebIDL::ExceptionOr<void> CanvasGradient::add_color_stop(double offset, String c
{
// 1. If the offset is less than 0 or greater than 1, then throw an "IndexSizeError" DOMException.
if (offset < 0 || offset > 1)
return WebIDL::IndexSizeError::create(global_object(), "CanvasGradient color stop offset out of bounds");
return WebIDL::IndexSizeError::create(realm(), "CanvasGradient color stop offset out of bounds");
// 2. Let parsed color be the result of parsing color.
auto parsed_color = Color::from_string(color);
// 3. If parsed color is failure, throw a "SyntaxError" DOMException.
if (!parsed_color.has_value())
return WebIDL::SyntaxError::create(global_object(), "Could not parse color for CanvasGradient");
return WebIDL::SyntaxError::create(realm(), "Could not parse color for CanvasGradient");
// 4. Place a new stop on the gradient, at offset offset relative to the whole gradient, and with the color parsed color.
m_color_stops.append(ColorStop { offset, parsed_color.value() });

View file

@ -21,16 +21,16 @@ public:
Conic,
};
static JS::NonnullGCPtr<CanvasGradient> create_radial(HTML::Window&, double x0, double y0, double r0, double x1, double y1, double r1);
static JS::NonnullGCPtr<CanvasGradient> create_linear(HTML::Window&, double x0, double y0, double x1, double y1);
static JS::NonnullGCPtr<CanvasGradient> create_conic(HTML::Window&, double start_angle, double x, double y);
static JS::NonnullGCPtr<CanvasGradient> create_radial(JS::Realm&, double x0, double y0, double r0, double x1, double y1, double r1);
static JS::NonnullGCPtr<CanvasGradient> create_linear(JS::Realm&, double x0, double y0, double x1, double y1);
static JS::NonnullGCPtr<CanvasGradient> create_conic(JS::Realm&, double start_angle, double x, double y);
WebIDL::ExceptionOr<void> add_color_stop(double offset, String const& color);
~CanvasGradient();
private:
CanvasGradient(HTML::Window&, Type);
CanvasGradient(JS::Realm&, Type);
Type m_type {};

View file

@ -10,30 +10,30 @@
#include <LibGfx/Painter.h>
#include <LibGfx/Quad.h>
#include <LibGfx/Rect.h>
#include <LibWeb/Bindings/Intrinsics.h>
#include <LibWeb/HTML/CanvasRenderingContext2D.h>
#include <LibWeb/HTML/HTMLCanvasElement.h>
#include <LibWeb/HTML/HTMLImageElement.h>
#include <LibWeb/HTML/ImageData.h>
#include <LibWeb/HTML/Path2D.h>
#include <LibWeb/HTML/TextMetrics.h>
#include <LibWeb/HTML/Window.h>
#include <LibWeb/Layout/TextNode.h>
#include <LibWeb/Platform/FontPlugin.h>
#include <LibWeb/WebIDL/ExceptionOr.h>
namespace Web::HTML {
JS::NonnullGCPtr<CanvasRenderingContext2D> CanvasRenderingContext2D::create(HTML::Window& window, HTMLCanvasElement& element)
JS::NonnullGCPtr<CanvasRenderingContext2D> CanvasRenderingContext2D::create(JS::Realm& realm, HTMLCanvasElement& element)
{
return *window.heap().allocate<CanvasRenderingContext2D>(window.realm(), window, element);
return *realm.heap().allocate<CanvasRenderingContext2D>(realm, realm, element);
}
CanvasRenderingContext2D::CanvasRenderingContext2D(HTML::Window& window, HTMLCanvasElement& element)
: PlatformObject(window.realm())
CanvasRenderingContext2D::CanvasRenderingContext2D(JS::Realm& realm, HTMLCanvasElement& element)
: PlatformObject(realm)
, CanvasPath(static_cast<Bindings::PlatformObject&>(*this))
, m_element(element)
{
set_prototype(&window.cached_web_prototype("CanvasRenderingContext2D"));
set_prototype(&Bindings::cached_web_prototype(realm, "CanvasRenderingContext2D"));
}
CanvasRenderingContext2D::~CanvasRenderingContext2D() = default;
@ -267,7 +267,7 @@ void CanvasRenderingContext2D::fill(Path2D& path, String const& fill_rule)
JS::GCPtr<ImageData> CanvasRenderingContext2D::create_image_data(int width, int height) const
{
return ImageData::create_with_size(global_object(), width, height);
return ImageData::create_with_size(realm(), width, height);
}
// https://html.spec.whatwg.org/multipage/canvas.html#dom-context-2d-getimagedata
@ -275,15 +275,15 @@ WebIDL::ExceptionOr<JS::GCPtr<ImageData>> CanvasRenderingContext2D::get_image_da
{
// 1. If either the sw or sh arguments are zero, then throw an "IndexSizeError" DOMException.
if (width == 0 || height == 0)
return WebIDL::IndexSizeError::create(global_object(), "Width and height must not be zero");
return WebIDL::IndexSizeError::create(realm(), "Width and height must not be zero");
// 2. If the CanvasRenderingContext2D's origin-clean flag is set to false, then throw a "SecurityError" DOMException.
if (!m_origin_clean)
return WebIDL::SecurityError::create(global_object(), "CanvasRenderingContext2D is not origin-clean");
return WebIDL::SecurityError::create(realm(), "CanvasRenderingContext2D is not origin-clean");
// 3. Let imageData be a new ImageData object.
// 4. Initialize imageData given sw, sh, settings set to settings, and defaultColorSpace set to this's color space.
auto image_data = ImageData::create_with_size(global_object(), width, height);
auto image_data = ImageData::create_with_size(realm(), width, height);
// NOTE: We don't attempt to create the underlying bitmap here; if it doesn't exist, it's like copying only transparent black pixels (which is a no-op).
if (!canvas_element().bitmap())
@ -352,7 +352,7 @@ JS::NonnullGCPtr<TextMetrics> CanvasRenderingContext2D::measure_text(String cons
// TextMetrics object with members behaving as described in the following
// list:
auto prepared_text = prepare_text(text);
auto metrics = TextMetrics::create(global_object());
auto metrics = TextMetrics::create(realm());
// FIXME: Use the font that was used to create the glyphs in prepared_text.
auto& font = Platform::FontPlugin::the().default_font();
@ -497,7 +497,7 @@ WebIDL::ExceptionOr<CanvasImageSourceUsability> check_usability_of_image(CanvasI
[](JS::Handle<HTMLCanvasElement> const& canvas_element) -> WebIDL::ExceptionOr<Optional<CanvasImageSourceUsability>> {
// If image has either a horizontal dimension or a vertical dimension equal to zero, then throw an "InvalidStateError" DOMException.
if (canvas_element->width() == 0 || canvas_element->height() == 0)
return WebIDL::InvalidStateError::create(canvas_element->global_object(), "Canvas width or height is zero");
return WebIDL::InvalidStateError::create(canvas_element->realm(), "Canvas width or height is zero");
return Optional<CanvasImageSourceUsability> {};
}));
if (usability.has_value())

View file

@ -51,7 +51,7 @@ class CanvasRenderingContext2D
WEB_PLATFORM_OBJECT(CanvasRenderingContext2D, Bindings::PlatformObject);
public:
static JS::NonnullGCPtr<CanvasRenderingContext2D> create(HTML::Window&, HTMLCanvasElement&);
static JS::NonnullGCPtr<CanvasRenderingContext2D> create(JS::Realm&, HTMLCanvasElement&);
virtual ~CanvasRenderingContext2D() override;
virtual void fill_rect(float x, float y, float width, float height) override;
@ -83,7 +83,7 @@ public:
virtual void clip() override;
private:
explicit CanvasRenderingContext2D(HTML::Window&, HTMLCanvasElement&);
explicit CanvasRenderingContext2D(JS::Realm&, HTMLCanvasElement&);
virtual void visit_edges(Cell::Visitor&) override;

View file

@ -4,28 +4,34 @@
* SPDX-License-Identifier: BSD-2-Clause
*/
#include <LibWeb/Bindings/Intrinsics.h>
#include <LibWeb/HTML/CloseEvent.h>
#include <LibWeb/HTML/Window.h>
namespace Web::HTML {
CloseEvent* CloseEvent::create(HTML::Window& window_object, FlyString const& event_name, CloseEventInit const& event_init)
CloseEvent* CloseEvent::create(JS::Realm& realm, FlyString const& event_name, CloseEventInit const& event_init)
{
return window_object.heap().allocate<CloseEvent>(window_object.realm(), window_object, event_name, event_init);
return realm.heap().allocate<CloseEvent>(realm, realm, event_name, event_init);
}
CloseEvent* CloseEvent::create_with_global_object(HTML::Window& window_object, FlyString const& event_name, CloseEventInit const& event_init)
CloseEvent* CloseEvent::create(HTML::Window& window, FlyString const& event_name, CloseEventInit const& event_init)
{
return create(window_object, event_name, event_init);
return create(window.realm(), event_name, event_init);
}
CloseEvent::CloseEvent(HTML::Window& window_object, FlyString const& event_name, CloseEventInit const& event_init)
: DOM::Event(window_object, event_name, event_init)
CloseEvent* CloseEvent::construct_impl(JS::Realm& realm, FlyString const& event_name, CloseEventInit const& event_init)
{
return create(realm, event_name, event_init);
}
CloseEvent::CloseEvent(JS::Realm& realm, FlyString const& event_name, CloseEventInit const& event_init)
: DOM::Event(realm, event_name, event_init)
, m_was_clean(event_init.was_clean)
, m_code(event_init.code)
, m_reason(event_init.reason)
{
set_prototype(&window_object.cached_web_prototype("CloseEvent"));
set_prototype(&Bindings::cached_web_prototype(realm, "CloseEvent"));
}
CloseEvent::~CloseEvent() = default;

View file

@ -21,10 +21,9 @@ class CloseEvent : public DOM::Event {
WEB_PLATFORM_OBJECT(CloseEvent, DOM::Event);
public:
static CloseEvent* create(JS::Realm&, FlyString const& event_name, CloseEventInit const& event_init = {});
static CloseEvent* create(HTML::Window&, FlyString const& event_name, CloseEventInit const& event_init = {});
static CloseEvent* create_with_global_object(HTML::Window&, FlyString const& event_name, CloseEventInit const& event_init);
CloseEvent(HTML::Window&, FlyString const& event_name, CloseEventInit const& event_init);
static CloseEvent* construct_impl(JS::Realm&, FlyString const& event_name, CloseEventInit const& event_init);
virtual ~CloseEvent() override;
@ -33,6 +32,8 @@ public:
String reason() const { return m_reason; }
private:
CloseEvent(JS::Realm&, FlyString const& event_name, CloseEventInit const& event_init);
bool m_was_clean { false };
u16 m_code { 0 };
String m_reason;

View file

@ -78,7 +78,7 @@ JS::ThrowCompletionOr<JS::PropertyDescriptor> cross_origin_property_fallback(JS:
return JS::PropertyDescriptor { .value = JS::js_undefined(), .writable = false, .enumerable = false, .configurable = true };
// 2. Throw a "SecurityError" DOMException.
return throw_completion(WebIDL::SecurityError::create(vm.current_realm()->global_object(), String::formatted("Can't access property '{}' on cross-origin object", property_key)));
return throw_completion(WebIDL::SecurityError::create(*vm.current_realm(), String::formatted("Can't access property '{}' on cross-origin object", property_key)));
}
// 7.2.3.3 IsPlatformObjectSameOrigin ( O ), https://html.spec.whatwg.org/multipage/browsers.html#isplatformobjectsameorigin-(-o-)
@ -196,7 +196,7 @@ JS::ThrowCompletionOr<JS::Value> cross_origin_get(JS::VM& vm, JS::Object const&
// 6. If getter is undefined, then throw a "SecurityError" DOMException.
if (!getter.has_value())
return throw_completion(WebIDL::SecurityError::create(vm.current_realm()->global_object(), String::formatted("Can't get property '{}' on cross-origin object", property_key)));
return throw_completion(WebIDL::SecurityError::create(*vm.current_realm(), String::formatted("Can't get property '{}' on cross-origin object", property_key)));
// 7. Return ? Call(getter, Receiver).
return JS::call(vm, *getter, receiver);
@ -222,7 +222,7 @@ JS::ThrowCompletionOr<bool> cross_origin_set(JS::VM& vm, JS::Object& object, JS:
}
// 4. Throw a "SecurityError" DOMException.
return throw_completion(WebIDL::SecurityError::create(vm.current_realm()->global_object(), String::formatted("Can't set property '{}' on cross-origin object", property_key)));
return throw_completion(WebIDL::SecurityError::create(*vm.current_realm(), String::formatted("Can't set property '{}' on cross-origin object", property_key)));
}
// 7.2.3.7 CrossOriginOwnPropertyKeys ( O ), https://html.spec.whatwg.org/multipage/browsers.html#crossoriginownpropertykeys-(-o-)

View file

@ -13,15 +13,15 @@
namespace Web::HTML {
WebIDL::ExceptionOr<JS::NonnullGCPtr<DOMParser>> DOMParser::create_with_global_object(HTML::Window& window)
WebIDL::ExceptionOr<JS::NonnullGCPtr<DOMParser>> DOMParser::construct_impl(JS::Realm& realm)
{
return JS::NonnullGCPtr(*window.heap().allocate<DOMParser>(window.realm(), window));
return JS::NonnullGCPtr(*realm.heap().allocate<DOMParser>(realm, realm));
}
DOMParser::DOMParser(HTML::Window& window)
: PlatformObject(window.realm())
DOMParser::DOMParser(JS::Realm& realm)
: PlatformObject(realm)
{
set_prototype(&window.cached_web_prototype("DOMParser"));
set_prototype(&Bindings::cached_web_prototype(realm, "DOMParser"));
}
DOMParser::~DOMParser() = default;
@ -30,7 +30,7 @@ DOMParser::~DOMParser() = default;
JS::NonnullGCPtr<DOM::Document> DOMParser::parse_from_string(String const& string, Bindings::DOMParserSupportedType type)
{
// 1. Let document be a new Document, whose content type is type and url is this's relevant global object's associated Document's URL.
auto document = DOM::Document::create(Bindings::main_thread_internal_window_object(), verify_cast<HTML::Window>(relevant_global_object(*this)).associated_document().url());
auto document = DOM::Document::create(realm(), verify_cast<HTML::Window>(relevant_global_object(*this)).associated_document().url());
document->set_content_type(Bindings::idl_enum_to_string(type));
// 2. Switch on type:

View file

@ -6,6 +6,7 @@
#pragma once
#include <LibJS/Heap/GCPtr.h>
#include <LibWeb/Bindings/PlatformObject.h>
#include <LibWeb/DOM/Document.h>
#include <LibWeb/Forward.h>
@ -18,14 +19,14 @@ class DOMParser final : public Bindings::PlatformObject {
WEB_PLATFORM_OBJECT(DOMParser, Bindings::PlatformObject);
public:
static WebIDL::ExceptionOr<JS::NonnullGCPtr<DOMParser>> create_with_global_object(HTML::Window&);
static WebIDL::ExceptionOr<JS::NonnullGCPtr<DOMParser>> construct_impl(JS::Realm&);
virtual ~DOMParser() override;
JS::NonnullGCPtr<DOM::Document> parse_from_string(String const&, Bindings::DOMParserSupportedType type);
private:
explicit DOMParser(HTML::Window&);
explicit DOMParser(JS::Realm&);
};
}

View file

@ -5,21 +5,21 @@
*/
#include <AK/CharacterTypes.h>
#include <LibWeb/Bindings/Intrinsics.h>
#include <LibWeb/DOM/Document.h>
#include <LibWeb/DOM/Element.h>
#include <LibWeb/HTML/DOMStringMap.h>
#include <LibWeb/HTML/Window.h>
namespace Web::HTML {
JS::NonnullGCPtr<DOMStringMap> DOMStringMap::create(DOM::Element& element)
{
auto& realm = element.document().window().realm();
auto& realm = element.realm();
return *realm.heap().allocate<DOMStringMap>(realm, element);
}
DOMStringMap::DOMStringMap(DOM::Element& element)
: PlatformObject(element.window().cached_web_prototype("DOMStringMap"))
: PlatformObject(Bindings::cached_web_prototype(element.realm(), "DOMStringMap"))
, m_associated_element(element)
{
}
@ -126,7 +126,7 @@ WebIDL::ExceptionOr<void> DOMStringMap::set_value_of_new_named_property(String c
if (current_character == '-' && character_index + 1 < name.length()) {
auto next_character = name[character_index + 1];
if (is_ascii_lower_alpha(next_character))
return WebIDL::SyntaxError::create(global_object(), "Name cannot contain a '-' followed by a lowercase character.");
return WebIDL::SyntaxError::create(realm(), "Name cannot contain a '-' followed by a lowercase character.");
}
// 2. For each ASCII upper alpha in name, insert a U+002D HYPHEN-MINUS character (-) before the character and replace the character with the same character converted to ASCII lowercase.

View file

@ -4,30 +4,30 @@
* SPDX-License-Identifier: BSD-2-Clause
*/
#include <LibWeb/Bindings/Intrinsics.h>
#include <LibWeb/HTML/ErrorEvent.h>
#include <LibWeb/HTML/Window.h>
namespace Web::HTML {
ErrorEvent* ErrorEvent::create(HTML::Window& window_object, FlyString const& event_name, ErrorEventInit const& event_init)
ErrorEvent* ErrorEvent::create(JS::Realm& realm, FlyString const& event_name, ErrorEventInit const& event_init)
{
return window_object.heap().allocate<ErrorEvent>(window_object.realm(), window_object, event_name, event_init);
return realm.heap().allocate<ErrorEvent>(realm, realm, event_name, event_init);
}
ErrorEvent* ErrorEvent::create_with_global_object(HTML::Window& window_object, FlyString const& event_name, ErrorEventInit const& event_init)
ErrorEvent* ErrorEvent::construct_impl(JS::Realm& realm, FlyString const& event_name, ErrorEventInit const& event_init)
{
return create(window_object, event_name, event_init);
return create(realm, event_name, event_init);
}
ErrorEvent::ErrorEvent(HTML::Window& window_object, FlyString const& event_name, ErrorEventInit const& event_init)
: DOM::Event(window_object, event_name)
ErrorEvent::ErrorEvent(JS::Realm& realm, FlyString const& event_name, ErrorEventInit const& event_init)
: DOM::Event(realm, event_name)
, m_message(event_init.message)
, m_filename(event_init.filename)
, m_lineno(event_init.lineno)
, m_colno(event_init.colno)
, m_error(event_init.error)
{
set_prototype(&window_object.cached_web_prototype("ErrorEvent"));
set_prototype(&Bindings::cached_web_prototype(realm, "ErrorEvent"));
}
ErrorEvent::~ErrorEvent() = default;

View file

@ -24,10 +24,8 @@ class ErrorEvent final : public DOM::Event {
WEB_PLATFORM_OBJECT(ErrorEvent, DOM::Event);
public:
static ErrorEvent* create(HTML::Window&, FlyString const& event_name, ErrorEventInit const& event_init = {});
static ErrorEvent* create_with_global_object(HTML::Window&, FlyString const& event_name, ErrorEventInit const& event_init);
ErrorEvent(HTML::Window&, FlyString const& event_name, ErrorEventInit const& event_init);
static ErrorEvent* create(JS::Realm&, FlyString const& event_name, ErrorEventInit const& event_init = {});
static ErrorEvent* construct_impl(JS::Realm&, FlyString const& event_name, ErrorEventInit const& event_init);
virtual ~ErrorEvent() override;
@ -47,6 +45,8 @@ public:
JS::Value error() const { return m_error; }
private:
ErrorEvent(JS::Realm&, FlyString const& event_name, ErrorEventInit const& event_init);
virtual void visit_edges(Cell::Visitor&) override;
String m_message { "" };

View file

@ -6,7 +6,6 @@
#include <LibWeb/DOM/DOMEventListener.h>
#include <LibWeb/HTML/EventHandler.h>
#include <LibWeb/HTML/Window.h>
namespace Web::HTML {

View file

@ -368,8 +368,10 @@ void EventLoop::unregister_environment_settings_object(Badge<EnvironmentSettings
Vector<JS::Handle<HTML::Window>> EventLoop::same_loop_windows() const
{
Vector<JS::Handle<HTML::Window>> windows;
for (auto& document : documents_in_this_event_loop())
windows.append(JS::make_handle(document->window()));
for (auto& document : documents_in_this_event_loop()) {
if (document->is_fully_active())
windows.append(JS::make_handle(document->window()));
}
return windows;
}

View file

@ -12,7 +12,7 @@ namespace Web::HTML {
HTMLAnchorElement::HTMLAnchorElement(DOM::Document& document, DOM::QualifiedName qualified_name)
: HTMLElement(document, move(qualified_name))
{
set_prototype(&window().cached_web_prototype("HTMLAnchorElement"));
set_prototype(&Bindings::cached_web_prototype(realm(), "HTMLAnchorElement"));
activation_behavior = [this](auto const& event) {
run_activation_behavior(event);

View file

@ -12,7 +12,7 @@ namespace Web::HTML {
HTMLAreaElement::HTMLAreaElement(DOM::Document& document, DOM::QualifiedName qualified_name)
: HTMLElement(document, move(qualified_name))
{
set_prototype(&window().cached_web_prototype("HTMLAreaElement"));
set_prototype(&Bindings::cached_web_prototype(realm(), "HTMLAreaElement"));
}
HTMLAreaElement::~HTMLAreaElement() = default;

View file

@ -12,7 +12,7 @@ namespace Web::HTML {
HTMLAudioElement::HTMLAudioElement(DOM::Document& document, DOM::QualifiedName qualified_name)
: HTMLMediaElement(document, move(qualified_name))
{
set_prototype(&window().cached_web_prototype("HTMLAudioElement"));
set_prototype(&Bindings::cached_web_prototype(realm(), "HTMLAudioElement"));
}
HTMLAudioElement::~HTMLAudioElement() = default;

View file

@ -13,7 +13,7 @@ namespace Web::HTML {
HTMLBRElement::HTMLBRElement(DOM::Document& document, DOM::QualifiedName qualified_name)
: HTMLElement(document, move(qualified_name))
{
set_prototype(&window().cached_web_prototype("HTMLBRElement"));
set_prototype(&Bindings::cached_web_prototype(realm(), "HTMLBRElement"));
}
HTMLBRElement::~HTMLBRElement() = default;

View file

@ -12,7 +12,7 @@ namespace Web::HTML {
HTMLBaseElement::HTMLBaseElement(DOM::Document& document, DOM::QualifiedName qualified_name)
: HTMLElement(document, move(qualified_name))
{
set_prototype(&window().cached_web_prototype("HTMLBaseElement"));
set_prototype(&Bindings::cached_web_prototype(realm(), "HTMLBaseElement"));
}
HTMLBaseElement::~HTMLBaseElement() = default;

View file

@ -15,7 +15,7 @@ namespace Web::HTML {
HTMLBodyElement::HTMLBodyElement(DOM::Document& document, DOM::QualifiedName qualified_name)
: HTMLElement(document, move(qualified_name))
{
set_prototype(&window().cached_web_prototype("HTMLBodyElement"));
set_prototype(&Bindings::cached_web_prototype(realm(), "HTMLBodyElement"));
}
HTMLBodyElement::~HTMLBodyElement() = default;

View file

@ -13,7 +13,7 @@ namespace Web::HTML {
HTMLButtonElement::HTMLButtonElement(DOM::Document& document, DOM::QualifiedName qualified_name)
: HTMLElement(document, move(qualified_name))
{
set_prototype(&window().cached_web_prototype("HTMLButtonElement"));
set_prototype(&Bindings::cached_web_prototype(realm(), "HTMLButtonElement"));
// https://html.spec.whatwg.org/multipage/form-elements.html#the-button-element:activation-behaviour
activation_behavior = [this](auto&) {

View file

@ -21,7 +21,7 @@ static constexpr auto max_canvas_area = 16384 * 16384;
HTMLCanvasElement::HTMLCanvasElement(DOM::Document& document, DOM::QualifiedName qualified_name)
: HTMLElement(document, move(qualified_name))
{
set_prototype(&document.window().cached_web_prototype("HTMLCanvasElement"));
set_prototype(&Bindings::cached_web_prototype(realm(), "HTMLCanvasElement"));
}
HTMLCanvasElement::~HTMLCanvasElement() = default;
@ -88,7 +88,7 @@ HTMLCanvasElement::HasOrCreatedContext HTMLCanvasElement::create_2d_context()
if (!m_context.has<Empty>())
return m_context.has<JS::NonnullGCPtr<CanvasRenderingContext2D>>() ? HasOrCreatedContext::Yes : HasOrCreatedContext::No;
m_context = CanvasRenderingContext2D::create(window(), *this);
m_context = CanvasRenderingContext2D::create(realm(), *this);
return HasOrCreatedContext::Yes;
}

View file

@ -12,7 +12,7 @@ namespace Web::HTML {
HTMLDListElement::HTMLDListElement(DOM::Document& document, DOM::QualifiedName qualified_name)
: HTMLElement(document, move(qualified_name))
{
set_prototype(&window().cached_web_prototype("HTMLDListElement"));
set_prototype(&Bindings::cached_web_prototype(realm(), "HTMLDListElement"));
}
HTMLDListElement::~HTMLDListElement() = default;

View file

@ -12,7 +12,7 @@ namespace Web::HTML {
HTMLDataElement::HTMLDataElement(DOM::Document& document, DOM::QualifiedName qualified_name)
: HTMLElement(document, move(qualified_name))
{
set_prototype(&window().cached_web_prototype("HTMLDataElement"));
set_prototype(&Bindings::cached_web_prototype(realm(), "HTMLDataElement"));
}
HTMLDataElement::~HTMLDataElement() = default;

View file

@ -12,7 +12,7 @@ namespace Web::HTML {
HTMLDataListElement::HTMLDataListElement(DOM::Document& document, DOM::QualifiedName qualified_name)
: HTMLElement(document, move(qualified_name))
{
set_prototype(&window().cached_web_prototype("HTMLDataListElement"));
set_prototype(&Bindings::cached_web_prototype(realm(), "HTMLDataListElement"));
}
HTMLDataListElement::~HTMLDataListElement() = default;

View file

@ -12,7 +12,7 @@ namespace Web::HTML {
HTMLDetailsElement::HTMLDetailsElement(DOM::Document& document, DOM::QualifiedName qualified_name)
: HTMLElement(document, move(qualified_name))
{
set_prototype(&window().cached_web_prototype("HTMLDetailsElement"));
set_prototype(&Bindings::cached_web_prototype(realm(), "HTMLDetailsElement"));
}
HTMLDetailsElement::~HTMLDetailsElement() = default;

View file

@ -12,7 +12,7 @@ namespace Web::HTML {
HTMLDialogElement::HTMLDialogElement(DOM::Document& document, DOM::QualifiedName qualified_name)
: HTMLElement(document, move(qualified_name))
{
set_prototype(&window().cached_web_prototype("HTMLDialogElement"));
set_prototype(&Bindings::cached_web_prototype(realm(), "HTMLDialogElement"));
}
HTMLDialogElement::~HTMLDialogElement() = default;

View file

@ -12,7 +12,7 @@ namespace Web::HTML {
HTMLDirectoryElement::HTMLDirectoryElement(DOM::Document& document, DOM::QualifiedName qualified_name)
: HTMLElement(document, move(qualified_name))
{
set_prototype(&window().cached_web_prototype("HTMLDirectoryElement"));
set_prototype(&Bindings::cached_web_prototype(realm(), "HTMLDirectoryElement"));
}
HTMLDirectoryElement::~HTMLDirectoryElement() = default;

View file

@ -12,7 +12,7 @@ namespace Web::HTML {
HTMLDivElement::HTMLDivElement(DOM::Document& document, DOM::QualifiedName qualified_name)
: HTMLElement(document, move(qualified_name))
{
set_prototype(&window().cached_web_prototype("HTMLDivElement"));
set_prototype(&Bindings::cached_web_prototype(realm(), "HTMLDivElement"));
}
HTMLDivElement::~HTMLDivElement() = default;

View file

@ -31,7 +31,7 @@ namespace Web::HTML {
HTMLElement::HTMLElement(DOM::Document& document, DOM::QualifiedName qualified_name)
: Element(document, move(qualified_name))
{
set_prototype(&window().cached_web_prototype("HTMLElement"));
set_prototype(&Bindings::cached_web_prototype(realm(), "HTMLElement"));
}
HTMLElement::~HTMLElement() = default;
@ -104,7 +104,7 @@ WebIDL::ExceptionOr<void> HTMLElement::set_content_editable(String const& conten
set_attribute(HTML::AttributeNames::contenteditable, "false");
return {};
}
return WebIDL::SyntaxError::create(global_object(), "Invalid contentEditable value, must be 'true', 'false', or 'inherit'");
return WebIDL::SyntaxError::create(realm(), "Invalid contentEditable value, must be 'true', 'false', or 'inherit'");
}
void HTMLElement::set_inner_text(StringView text)
@ -436,7 +436,7 @@ bool HTMLElement::fire_a_synthetic_pointer_event(FlyString const& type, DOM::Ele
// 1. Let event be the result of creating an event using PointerEvent.
// 2. Initialize event's type attribute to e.
// FIXME: Actually create a PointerEvent!
auto event = UIEvents::MouseEvent::create(document().window(), type);
auto event = UIEvents::MouseEvent::create(window(), type);
// 3. Initialize event's bubbles and cancelable attributes to true.
event->set_bubbles(true);

View file

@ -12,7 +12,7 @@ namespace Web::HTML {
HTMLEmbedElement::HTMLEmbedElement(DOM::Document& document, DOM::QualifiedName qualified_name)
: HTMLElement(document, move(qualified_name))
{
set_prototype(&window().cached_web_prototype("HTMLEmbedElement"));
set_prototype(&Bindings::cached_web_prototype(realm(), "HTMLEmbedElement"));
}
HTMLEmbedElement::~HTMLEmbedElement() = default;

View file

@ -13,7 +13,7 @@ namespace Web::HTML {
HTMLFieldSetElement::HTMLFieldSetElement(DOM::Document& document, DOM::QualifiedName qualified_name)
: HTMLElement(document, move(qualified_name))
{
set_prototype(&window().cached_web_prototype("HTMLFieldSetElement"));
set_prototype(&Bindings::cached_web_prototype(realm(), "HTMLFieldSetElement"));
}
HTMLFieldSetElement::~HTMLFieldSetElement() = default;

View file

@ -14,7 +14,7 @@ namespace Web::HTML {
HTMLFontElement::HTMLFontElement(DOM::Document& document, DOM::QualifiedName qualified_name)
: HTMLElement(document, move(qualified_name))
{
set_prototype(&window().cached_web_prototype("HTMLFontElement"));
set_prototype(&Bindings::cached_web_prototype(realm(), "HTMLFontElement"));
}
HTMLFontElement::~HTMLFontElement() = default;

View file

@ -25,7 +25,7 @@ namespace Web::HTML {
HTMLFormElement::HTMLFormElement(DOM::Document& document, DOM::QualifiedName qualified_name)
: HTMLElement(document, move(qualified_name))
{
set_prototype(&window().cached_web_prototype("HTMLFormElement"));
set_prototype(&Bindings::cached_web_prototype(realm(), "HTMLFormElement"));
}
HTMLFormElement::~HTMLFormElement() = default;
@ -73,7 +73,7 @@ void HTMLFormElement::submit_form(JS::GCPtr<HTMLElement> submitter, bool from_su
SubmitEventInit event_init {};
event_init.submitter = submitter_button;
auto submit_event = SubmitEvent::create(document().window(), EventNames::submit, event_init);
auto submit_event = SubmitEvent::create(realm(), EventNames::submit, event_init);
submit_event->set_bubbles(true);
submit_event->set_cancelable(true);
bool continue_ = dispatch_event(*submit_event);

View file

@ -12,7 +12,7 @@ namespace Web::HTML {
HTMLFrameElement::HTMLFrameElement(DOM::Document& document, DOM::QualifiedName qualified_name)
: HTMLElement(document, move(qualified_name))
{
set_prototype(&window().cached_web_prototype("HTMLFrameElement"));
set_prototype(&Bindings::cached_web_prototype(realm(), "HTMLFrameElement"));
}
HTMLFrameElement::~HTMLFrameElement() = default;

View file

@ -13,7 +13,7 @@ namespace Web::HTML {
HTMLFrameSetElement::HTMLFrameSetElement(DOM::Document& document, DOM::QualifiedName qualified_name)
: HTMLElement(document, move(qualified_name))
{
set_prototype(&window().cached_web_prototype("HTMLFrameSetElement"));
set_prototype(&Bindings::cached_web_prototype(realm(), "HTMLFrameSetElement"));
}
HTMLFrameSetElement::~HTMLFrameSetElement() = default;

View file

@ -12,7 +12,7 @@ namespace Web::HTML {
HTMLHRElement::HTMLHRElement(DOM::Document& document, DOM::QualifiedName qualified_name)
: HTMLElement(document, move(qualified_name))
{
set_prototype(&window().cached_web_prototype("HTMLHRElement"));
set_prototype(&Bindings::cached_web_prototype(realm(), "HTMLHRElement"));
}
HTMLHRElement::~HTMLHRElement() = default;

View file

@ -12,7 +12,7 @@ namespace Web::HTML {
HTMLHeadElement::HTMLHeadElement(DOM::Document& document, DOM::QualifiedName qualified_name)
: HTMLElement(document, move(qualified_name))
{
set_prototype(&window().cached_web_prototype("HTMLHeadElement"));
set_prototype(&Bindings::cached_web_prototype(realm(), "HTMLHeadElement"));
}
HTMLHeadElement::~HTMLHeadElement() = default;

View file

@ -12,7 +12,7 @@ namespace Web::HTML {
HTMLHeadingElement::HTMLHeadingElement(DOM::Document& document, DOM::QualifiedName qualified_name)
: HTMLElement(document, move(qualified_name))
{
set_prototype(&window().cached_web_prototype("HTMLHeadingElement"));
set_prototype(&Bindings::cached_web_prototype(realm(), "HTMLHeadingElement"));
}
HTMLHeadingElement::~HTMLHeadingElement() = default;

View file

@ -12,7 +12,7 @@ namespace Web::HTML {
HTMLHtmlElement::HTMLHtmlElement(DOM::Document& document, DOM::QualifiedName qualified_name)
: HTMLElement(document, move(qualified_name))
{
set_prototype(&window().cached_web_prototype("HTMLHtmlElement"));
set_prototype(&Bindings::cached_web_prototype(realm(), "HTMLHtmlElement"));
}
HTMLHtmlElement::~HTMLHtmlElement() = default;

View file

@ -16,7 +16,7 @@ namespace Web::HTML {
HTMLIFrameElement::HTMLIFrameElement(DOM::Document& document, DOM::QualifiedName qualified_name)
: BrowsingContextContainer(document, move(qualified_name))
{
set_prototype(&document.window().cached_web_prototype("HTMLIFrameElement"));
set_prototype(&Bindings::cached_web_prototype(realm(), "HTMLIFrameElement"));
}
HTMLIFrameElement::~HTMLIFrameElement() = default;
@ -144,7 +144,7 @@ void run_iframe_load_event_steps(HTML::HTMLIFrameElement& element)
// FIXME: 4. Set childDocument's iframe load in progress flag.
// 5. Fire an event named load at element.
element.dispatch_event(*DOM::Event::create(element.document().window(), HTML::EventNames::load));
element.dispatch_event(*DOM::Event::create(element.realm(), HTML::EventNames::load));
// FIXME: 6. Unset childDocument's iframe load in progress flag.
}

View file

@ -22,13 +22,13 @@ HTMLImageElement::HTMLImageElement(DOM::Document& document, DOM::QualifiedName q
: HTMLElement(document, move(qualified_name))
, m_image_loader(*this)
{
set_prototype(&window().cached_web_prototype("HTMLImageElement"));
set_prototype(&Bindings::cached_web_prototype(realm(), "HTMLImageElement"));
m_image_loader.on_load = [this] {
set_needs_style_update(true);
this->document().set_needs_layout();
queue_an_element_task(HTML::Task::Source::DOMManipulation, [this] {
dispatch_event(*DOM::Event::create(this->document().window(), EventNames::load));
dispatch_event(*DOM::Event::create(this->realm(), EventNames::load));
});
};
@ -37,7 +37,7 @@ HTMLImageElement::HTMLImageElement(DOM::Document& document, DOM::QualifiedName q
set_needs_style_update(true);
this->document().set_needs_layout();
queue_an_element_task(HTML::Task::Source::DOMManipulation, [this] {
dispatch_event(*DOM::Event::create(this->document().window(), EventNames::error));
dispatch_event(*DOM::Event::create(this->realm(), EventNames::error));
});
};

View file

@ -24,7 +24,7 @@ HTMLInputElement::HTMLInputElement(DOM::Document& document, DOM::QualifiedName q
: HTMLElement(document, move(qualified_name))
, m_value(String::empty())
{
set_prototype(&window().cached_web_prototype("HTMLInputElement"));
set_prototype(&Bindings::cached_web_prototype(realm(), "HTMLInputElement"));
activation_behavior = [this](auto&) {
// The activation behavior for input elements are these steps:
@ -99,13 +99,13 @@ void HTMLInputElement::run_input_activation_behavior()
return;
// 2. Fire an event named input at the element with the bubbles and composed attributes initialized to true.
auto input_event = DOM::Event::create(document().window(), HTML::EventNames::input);
auto input_event = DOM::Event::create(realm(), HTML::EventNames::input);
input_event->set_bubbles(true);
input_event->set_composed(true);
dispatch_event(*input_event);
// 3. Fire an event named change at the element with the bubbles attribute initialized to true.
auto change_event = DOM::Event::create(document().window(), HTML::EventNames::change);
auto change_event = DOM::Event::create(realm(), HTML::EventNames::change);
change_event->set_bubbles(true);
dispatch_event(*change_event);
} else if (type_state() == TypeAttributeState::SubmitButton) {
@ -121,7 +121,7 @@ void HTMLInputElement::run_input_activation_behavior()
// 3. Submit the form owner from the element.
form->submit_form(this);
} else {
dispatch_event(*DOM::Event::create(document().window(), EventNames::change));
dispatch_event(*DOM::Event::create(realm(), EventNames::change));
}
}
@ -134,13 +134,13 @@ void HTMLInputElement::did_edit_text_node(Badge<BrowsingContext>)
// NOTE: This is a bit ad-hoc, but basically implements part of "4.10.5.5 Common event behaviors"
// https://html.spec.whatwg.org/multipage/input.html#common-input-element-events
queue_an_element_task(HTML::Task::Source::UserInteraction, [this] {
auto input_event = DOM::Event::create(document().window(), HTML::EventNames::input);
auto input_event = DOM::Event::create(realm(), HTML::EventNames::input);
input_event->set_bubbles(true);
input_event->set_composed(true);
dispatch_event(*input_event);
// FIXME: This should only fire when the input is "committed", whatever that means.
auto change_event = DOM::Event::create(document().window(), HTML::EventNames::change);
auto change_event = DOM::Event::create(realm(), HTML::EventNames::change);
change_event->set_bubbles(true);
dispatch_event(*change_event);
});

View file

@ -12,7 +12,7 @@ namespace Web::HTML {
HTMLLIElement::HTMLLIElement(DOM::Document& document, DOM::QualifiedName qualified_name)
: HTMLElement(document, move(qualified_name))
{
set_prototype(&window().cached_web_prototype("HTMLLIElement"));
set_prototype(&Bindings::cached_web_prototype(realm(), "HTMLLIElement"));
}
HTMLLIElement::~HTMLLIElement() = default;

View file

@ -13,7 +13,7 @@ namespace Web::HTML {
HTMLLabelElement::HTMLLabelElement(DOM::Document& document, DOM::QualifiedName qualified_name)
: HTMLElement(document, move(qualified_name))
{
set_prototype(&window().cached_web_prototype("HTMLLabelElement"));
set_prototype(&Bindings::cached_web_prototype(realm(), "HTMLLabelElement"));
}
HTMLLabelElement::~HTMLLabelElement() = default;

View file

@ -13,7 +13,7 @@ namespace Web::HTML {
HTMLLegendElement::HTMLLegendElement(DOM::Document& document, DOM::QualifiedName qualified_name)
: HTMLElement(document, move(qualified_name))
{
set_prototype(&window().cached_web_prototype("HTMLLegendElement"));
set_prototype(&Bindings::cached_web_prototype(realm(), "HTMLLegendElement"));
}
HTMLLegendElement::~HTMLLegendElement() = default;

View file

@ -21,7 +21,7 @@ namespace Web::HTML {
HTMLLinkElement::HTMLLinkElement(DOM::Document& document, DOM::QualifiedName qualified_name)
: HTMLElement(document, move(qualified_name))
{
set_prototype(&window().cached_web_prototype("HTMLLinkElement"));
set_prototype(&Bindings::cached_web_prototype(realm(), "HTMLLinkElement"));
}
HTMLLinkElement::~HTMLLinkElement() = default;

View file

@ -12,7 +12,7 @@ namespace Web::HTML {
HTMLMapElement::HTMLMapElement(DOM::Document& document, DOM::QualifiedName qualified_name)
: HTMLElement(document, move(qualified_name))
{
set_prototype(&window().cached_web_prototype("HTMLMapElement"));
set_prototype(&Bindings::cached_web_prototype(realm(), "HTMLMapElement"));
}
HTMLMapElement::~HTMLMapElement() = default;

View file

@ -12,7 +12,7 @@ namespace Web::HTML {
HTMLMarqueeElement::HTMLMarqueeElement(DOM::Document& document, DOM::QualifiedName qualified_name)
: HTMLElement(document, move(qualified_name))
{
set_prototype(&window().cached_web_prototype("HTMLMarqueeElement"));
set_prototype(&Bindings::cached_web_prototype(realm(), "HTMLMarqueeElement"));
}
HTMLMarqueeElement::~HTMLMarqueeElement() = default;

View file

@ -13,7 +13,7 @@ namespace Web::HTML {
HTMLMediaElement::HTMLMediaElement(DOM::Document& document, DOM::QualifiedName qualified_name)
: HTMLElement(document, move(qualified_name))
{
set_prototype(&window().cached_web_prototype("HTMLMediaElement"));
set_prototype(&Bindings::cached_web_prototype(realm(), "HTMLMediaElement"));
}
HTMLMediaElement::~HTMLMediaElement() = default;

View file

@ -12,7 +12,7 @@ namespace Web::HTML {
HTMLMenuElement::HTMLMenuElement(DOM::Document& document, DOM::QualifiedName qualified_name)
: HTMLElement(document, move(qualified_name))
{
set_prototype(&window().cached_web_prototype("HTMLMenuElement"));
set_prototype(&Bindings::cached_web_prototype(realm(), "HTMLMenuElement"));
}
HTMLMenuElement::~HTMLMenuElement() = default;

View file

@ -12,7 +12,7 @@ namespace Web::HTML {
HTMLMetaElement::HTMLMetaElement(DOM::Document& document, DOM::QualifiedName qualified_name)
: HTMLElement(document, move(qualified_name))
{
set_prototype(&window().cached_web_prototype("HTMLMetaElement"));
set_prototype(&Bindings::cached_web_prototype(realm(), "HTMLMetaElement"));
}
HTMLMetaElement::~HTMLMetaElement() = default;

View file

@ -12,7 +12,7 @@ namespace Web::HTML {
HTMLMeterElement::HTMLMeterElement(DOM::Document& document, DOM::QualifiedName qualified_name)
: HTMLElement(document, move(qualified_name))
{
set_prototype(&window().cached_web_prototype("HTMLMeterElement"));
set_prototype(&Bindings::cached_web_prototype(realm(), "HTMLMeterElement"));
}
HTMLMeterElement::~HTMLMeterElement() = default;

View file

@ -12,7 +12,7 @@ namespace Web::HTML {
HTMLModElement::HTMLModElement(DOM::Document& document, DOM::QualifiedName qualified_name)
: HTMLElement(document, move(qualified_name))
{
set_prototype(&window().cached_web_prototype("HTMLModElement"));
set_prototype(&Bindings::cached_web_prototype(realm(), "HTMLModElement"));
}
HTMLModElement::~HTMLModElement() = default;

View file

@ -12,7 +12,7 @@ namespace Web::HTML {
HTMLOListElement::HTMLOListElement(DOM::Document& document, DOM::QualifiedName qualified_name)
: HTMLElement(document, move(qualified_name))
{
set_prototype(&window().cached_web_prototype("HTMLOListElement"));
set_prototype(&Bindings::cached_web_prototype(realm(), "HTMLOListElement"));
}
HTMLOListElement::~HTMLOListElement() = default;

View file

@ -19,7 +19,7 @@ namespace Web::HTML {
HTMLObjectElement::HTMLObjectElement(DOM::Document& document, DOM::QualifiedName qualified_name)
: BrowsingContextContainer(document, move(qualified_name))
{
set_prototype(&window().cached_web_prototype("HTMLObjectElement"));
set_prototype(&Bindings::cached_web_prototype(realm(), "HTMLObjectElement"));
}
HTMLObjectElement::~HTMLObjectElement() = default;
@ -97,7 +97,7 @@ void HTMLObjectElement::queue_element_task_to_run_object_representation_steps()
// 3. If that failed, fire an event named error at the element, then jump to the step below labeled fallback.
if (!url.is_valid()) {
dispatch_event(*DOM::Event::create(document().window(), HTML::EventNames::error));
dispatch_event(*DOM::Event::create(realm(), HTML::EventNames::error));
return run_object_representation_fallback_steps();
}
@ -124,7 +124,7 @@ void HTMLObjectElement::queue_element_task_to_run_object_representation_steps()
void HTMLObjectElement::resource_did_fail()
{
// 4.7. If the load failed (e.g. there was an HTTP 404 error, there was a DNS error), fire an event named error at the element, then jump to the step below labeled fallback.
dispatch_event(*DOM::Event::create(document().window(), HTML::EventNames::error));
dispatch_event(*DOM::Event::create(realm(), HTML::EventNames::error));
run_object_representation_fallback_steps();
}
@ -262,7 +262,7 @@ void HTMLObjectElement::run_object_representation_completed_steps(Representation
// 4.11. If the object element does not represent its nested browsing context, then once the resource is completely loaded, queue an element task on the DOM manipulation task source given the object element to fire an event named load at the element.
if (representation != Representation::NestedBrowsingContext) {
queue_an_element_task(HTML::Task::Source::DOMManipulation, [&]() {
dispatch_event(*DOM::Event::create(document().window(), HTML::EventNames::load));
dispatch_event(*DOM::Event::create(realm(), HTML::EventNames::load));
});
}

View file

@ -12,7 +12,7 @@ namespace Web::HTML {
HTMLOptGroupElement::HTMLOptGroupElement(DOM::Document& document, DOM::QualifiedName qualified_name)
: HTMLElement(document, move(qualified_name))
{
set_prototype(&window().cached_web_prototype("HTMLOptGroupElement"));
set_prototype(&Bindings::cached_web_prototype(realm(), "HTMLOptGroupElement"));
}
HTMLOptGroupElement::~HTMLOptGroupElement() = default;

View file

@ -20,7 +20,7 @@ namespace Web::HTML {
HTMLOptionElement::HTMLOptionElement(DOM::Document& document, DOM::QualifiedName qualified_name)
: HTMLElement(document, move(qualified_name))
{
set_prototype(&window().cached_web_prototype("HTMLOptionElement"));
set_prototype(&Bindings::cached_web_prototype(realm(), "HTMLOptionElement"));
}
HTMLOptionElement::~HTMLOptionElement() = default;

View file

@ -4,11 +4,11 @@
* SPDX-License-Identifier: BSD-2-Clause
*/
#include <LibWeb/Bindings/Intrinsics.h>
#include <LibWeb/HTML/HTMLOptGroupElement.h>
#include <LibWeb/HTML/HTMLOptionElement.h>
#include <LibWeb/HTML/HTMLOptionsCollection.h>
#include <LibWeb/HTML/HTMLSelectElement.h>
#include <LibWeb/HTML/Window.h>
#include <LibWeb/WebIDL/DOMException.h>
namespace Web::HTML {
@ -21,7 +21,7 @@ JS::NonnullGCPtr<HTMLOptionsCollection> HTMLOptionsCollection::create(DOM::Paren
HTMLOptionsCollection::HTMLOptionsCollection(DOM::ParentNode& root, Function<bool(DOM::Element const&)> filter)
: DOM::HTMLCollection(root, move(filter))
{
set_prototype(&root.window().cached_web_prototype("HTMLOptionsCollection"));
set_prototype(&Bindings::cached_web_prototype(realm(), "HTMLOptionsCollection"));
}
HTMLOptionsCollection::~HTMLOptionsCollection() = default;
@ -40,11 +40,11 @@ WebIDL::ExceptionOr<void> HTMLOptionsCollection::add(HTMLOptionOrOptGroupElement
// 1. If element is an ancestor of the select element on which the HTMLOptionsCollection is rooted, then throw a "HierarchyRequestError" DOMException.
if (resolved_element->is_ancestor_of(root()))
return WebIDL::HierarchyRequestError::create(global_object(), "The provided element is an ancestor of the root select element.");
return WebIDL::HierarchyRequestError::create(realm(), "The provided element is an ancestor of the root select element.");
// 2. If before is an element, but that element isn't a descendant of the select element on which the HTMLOptionsCollection is rooted, then throw a "NotFoundError" DOMException.
if (before_element && !before_element->is_descendant_of(root()))
return WebIDL::NotFoundError::create(global_object(), "The 'before' element is not a descendant of the root select element.");
return WebIDL::NotFoundError::create(realm(), "The 'before' element is not a descendant of the root select element.");
// 3. If element and before are the same element, then return.
if (before_element && (resolved_element.ptr() == before_element.ptr()))

View file

@ -12,7 +12,7 @@ namespace Web::HTML {
HTMLOutputElement::HTMLOutputElement(DOM::Document& document, DOM::QualifiedName qualified_name)
: HTMLElement(document, move(qualified_name))
{
set_prototype(&window().cached_web_prototype("HTMLOutputElement"));
set_prototype(&Bindings::cached_web_prototype(realm(), "HTMLOutputElement"));
}
HTMLOutputElement::~HTMLOutputElement() = default;

View file

@ -12,7 +12,7 @@ namespace Web::HTML {
HTMLParagraphElement::HTMLParagraphElement(DOM::Document& document, DOM::QualifiedName qualified_name)
: HTMLElement(document, move(qualified_name))
{
set_prototype(&window().cached_web_prototype("HTMLParagraphElement"));
set_prototype(&Bindings::cached_web_prototype(realm(), "HTMLParagraphElement"));
}
HTMLParagraphElement::~HTMLParagraphElement() = default;

View file

@ -12,7 +12,7 @@ namespace Web::HTML {
HTMLParamElement::HTMLParamElement(DOM::Document& document, DOM::QualifiedName qualified_name)
: HTMLElement(document, move(qualified_name))
{
set_prototype(&window().cached_web_prototype("HTMLParamElement"));
set_prototype(&Bindings::cached_web_prototype(realm(), "HTMLParamElement"));
}
HTMLParamElement::~HTMLParamElement() = default;

View file

@ -12,7 +12,7 @@ namespace Web::HTML {
HTMLPictureElement::HTMLPictureElement(DOM::Document& document, DOM::QualifiedName qualified_name)
: HTMLElement(document, move(qualified_name))
{
set_prototype(&window().cached_web_prototype("HTMLPictureElement"));
set_prototype(&Bindings::cached_web_prototype(realm(), "HTMLPictureElement"));
}
HTMLPictureElement::~HTMLPictureElement() = default;

View file

@ -12,7 +12,7 @@ namespace Web::HTML {
HTMLPreElement::HTMLPreElement(DOM::Document& document, DOM::QualifiedName qualified_name)
: HTMLElement(document, move(qualified_name))
{
set_prototype(&window().cached_web_prototype("HTMLPreElement"));
set_prototype(&Bindings::cached_web_prototype(realm(), "HTMLPreElement"));
}
HTMLPreElement::~HTMLPreElement() = default;

View file

@ -18,7 +18,7 @@ namespace Web::HTML {
HTMLProgressElement::HTMLProgressElement(DOM::Document& document, DOM::QualifiedName qualified_name)
: HTMLElement(document, move(qualified_name))
{
set_prototype(&window().cached_web_prototype("HTMLProgressElement"));
set_prototype(&Bindings::cached_web_prototype(realm(), "HTMLProgressElement"));
}
HTMLProgressElement::~HTMLProgressElement() = default;

View file

@ -12,7 +12,7 @@ namespace Web::HTML {
HTMLQuoteElement::HTMLQuoteElement(DOM::Document& document, DOM::QualifiedName qualified_name)
: HTMLElement(document, move(qualified_name))
{
set_prototype(&window().cached_web_prototype("HTMLQuoteElement"));
set_prototype(&Bindings::cached_web_prototype(realm(), "HTMLQuoteElement"));
}
HTMLQuoteElement::~HTMLQuoteElement() = default;

View file

@ -22,7 +22,7 @@ namespace Web::HTML {
HTMLScriptElement::HTMLScriptElement(DOM::Document& document, DOM::QualifiedName qualified_name)
: HTMLElement(document, move(qualified_name))
{
set_prototype(&window().cached_web_prototype("HTMLScriptElement"));
set_prototype(&Bindings::cached_web_prototype(realm(), "HTMLScriptElement"));
}
HTMLScriptElement::~HTMLScriptElement() = default;
@ -57,7 +57,7 @@ void HTMLScriptElement::execute_script()
// 3. If the script's script is null for scriptElement, then fire an event named error at scriptElement, and return.
if (!m_script) {
dbgln("HTMLScriptElement: Refusing to run script because the script's script is null.");
dispatch_event(*DOM::Event::create(document().window(), HTML::EventNames::error));
dispatch_event(*DOM::Event::create(realm(), HTML::EventNames::error));
return;
}
@ -104,7 +104,7 @@ void HTMLScriptElement::execute_script()
// 7. If scriptElement is from an external file, then fire an event named load at scriptElement.
if (m_from_an_external_file)
dispatch_event(*DOM::Event::create(document().window(), HTML::EventNames::load));
dispatch_event(*DOM::Event::create(realm(), HTML::EventNames::load));
}
// https://mimesniff.spec.whatwg.org/#javascript-mime-type-essence-match
@ -268,7 +268,7 @@ void HTMLScriptElement::prepare_script()
if (src.is_empty()) {
dbgln("HTMLScriptElement: Refusing to run script because the src attribute is empty.");
queue_an_element_task(HTML::Task::Source::Unspecified, [this] {
dispatch_event(*DOM::Event::create(document().window(), HTML::EventNames::error));
dispatch_event(*DOM::Event::create(realm(), HTML::EventNames::error));
});
return;
}
@ -281,7 +281,7 @@ void HTMLScriptElement::prepare_script()
if (!url.is_valid()) {
dbgln("HTMLScriptElement: Refusing to run script because the src URL '{}' is invalid.", url);
queue_an_element_task(HTML::Task::Source::Unspecified, [this] {
dispatch_event(*DOM::Event::create(document().window(), HTML::EventNames::error));
dispatch_event(*DOM::Event::create(realm(), HTML::EventNames::error));
});
return;
}

View file

@ -16,7 +16,7 @@ namespace Web::HTML {
HTMLSelectElement::HTMLSelectElement(DOM::Document& document, DOM::QualifiedName qualified_name)
: HTMLElement(document, move(qualified_name))
{
set_prototype(&window().cached_web_prototype("HTMLSelectElement"));
set_prototype(&Bindings::cached_web_prototype(realm(), "HTMLSelectElement"));
}
HTMLSelectElement::~HTMLSelectElement() = default;

View file

@ -12,7 +12,7 @@ namespace Web::HTML {
HTMLSlotElement::HTMLSlotElement(DOM::Document& document, DOM::QualifiedName qualified_name)
: HTMLElement(document, move(qualified_name))
{
set_prototype(&window().cached_web_prototype("HTMLSlotElement"));
set_prototype(&Bindings::cached_web_prototype(realm(), "HTMLSlotElement"));
}
HTMLSlotElement::~HTMLSlotElement() = default;

View file

@ -12,7 +12,7 @@ namespace Web::HTML {
HTMLSourceElement::HTMLSourceElement(DOM::Document& document, DOM::QualifiedName qualified_name)
: HTMLElement(document, move(qualified_name))
{
set_prototype(&window().cached_web_prototype("HTMLSourceElement"));
set_prototype(&Bindings::cached_web_prototype(realm(), "HTMLSourceElement"));
}
HTMLSourceElement::~HTMLSourceElement() = default;

View file

@ -12,7 +12,7 @@ namespace Web::HTML {
HTMLSpanElement::HTMLSpanElement(DOM::Document& document, DOM::QualifiedName qualified_name)
: HTMLElement(document, move(qualified_name))
{
set_prototype(&window().cached_web_prototype("HTMLSpanElement"));
set_prototype(&Bindings::cached_web_prototype(realm(), "HTMLSpanElement"));
}
HTMLSpanElement::~HTMLSpanElement() = default;

View file

@ -14,7 +14,7 @@ namespace Web::HTML {
HTMLStyleElement::HTMLStyleElement(DOM::Document& document, DOM::QualifiedName qualified_name)
: HTMLElement(document, move(qualified_name))
{
set_prototype(&window().cached_web_prototype("HTMLStyleElement"));
set_prototype(&Bindings::cached_web_prototype(realm(), "HTMLStyleElement"));
}
HTMLStyleElement::~HTMLStyleElement() = default;

View file

@ -12,7 +12,7 @@ namespace Web::HTML {
HTMLTableCaptionElement::HTMLTableCaptionElement(DOM::Document& document, DOM::QualifiedName qualified_name)
: HTMLElement(document, move(qualified_name))
{
set_prototype(&window().cached_web_prototype("HTMLTableCaptionElement"));
set_prototype(&Bindings::cached_web_prototype(realm(), "HTMLTableCaptionElement"));
}
HTMLTableCaptionElement::~HTMLTableCaptionElement() = default;

View file

@ -14,7 +14,7 @@ namespace Web::HTML {
HTMLTableCellElement::HTMLTableCellElement(DOM::Document& document, DOM::QualifiedName qualified_name)
: HTMLElement(document, move(qualified_name))
{
set_prototype(&window().cached_web_prototype("HTMLTableCellElement"));
set_prototype(&Bindings::cached_web_prototype(realm(), "HTMLTableCellElement"));
}
HTMLTableCellElement::~HTMLTableCellElement() = default;

View file

@ -12,7 +12,7 @@ namespace Web::HTML {
HTMLTableColElement::HTMLTableColElement(DOM::Document& document, DOM::QualifiedName qualified_name)
: HTMLElement(document, move(qualified_name))
{
set_prototype(&window().cached_web_prototype("HTMLTableColElement"));
set_prototype(&Bindings::cached_web_prototype(realm(), "HTMLTableColElement"));
}
HTMLTableColElement::~HTMLTableColElement() = default;

View file

@ -20,7 +20,7 @@ namespace Web::HTML {
HTMLTableElement::HTMLTableElement(DOM::Document& document, DOM::QualifiedName qualified_name)
: HTMLElement(document, move(qualified_name))
{
set_prototype(&window().cached_web_prototype("HTMLTableElement"));
set_prototype(&Bindings::cached_web_prototype(realm(), "HTMLTableElement"));
}
HTMLTableElement::~HTMLTableElement() = default;
@ -103,7 +103,7 @@ WebIDL::ExceptionOr<void> HTMLTableElement::set_t_head(HTMLTableSectionElement*
VERIFY(thead);
if (thead->local_name() != TagNames::thead)
return WebIDL::HierarchyRequestError::create(global_object(), "Element is not thead");
return WebIDL::HierarchyRequestError::create(realm(), "Element is not thead");
// FIXME: The spec requires deleting the current thead if thead is null
// Currently the wrapper generator doesn't send us a nullable value
@ -190,7 +190,7 @@ WebIDL::ExceptionOr<void> HTMLTableElement::set_t_foot(HTMLTableSectionElement*
VERIFY(tfoot);
if (tfoot->local_name() != TagNames::tfoot)
return WebIDL::HierarchyRequestError::create(global_object(), "Element is not tfoot");
return WebIDL::HierarchyRequestError::create(realm(), "Element is not tfoot");
// FIXME: The spec requires deleting the current tfoot if tfoot is null
// Currently the wrapper generator doesn't send us a nullable value
@ -286,7 +286,7 @@ WebIDL::ExceptionOr<JS::NonnullGCPtr<HTMLTableRowElement>> HTMLTableElement::ins
auto rows_length = rows->length();
if (index < -1 || index > (long)rows_length) {
return WebIDL::IndexSizeError::create(global_object(), "Index is negative or greater than the number of rows");
return WebIDL::IndexSizeError::create(realm(), "Index is negative or greater than the number of rows");
}
auto& tr = static_cast<HTMLTableRowElement&>(*DOM::create_element(document(), TagNames::tr, Namespace::HTML));
if (rows_length == 0 && !has_child_of_type<HTMLTableRowElement>()) {
@ -313,7 +313,7 @@ WebIDL::ExceptionOr<void> HTMLTableElement::delete_row(long index)
// 1. If index is less than 1 or greater than or equal to the number of elements in the rows collection, then throw an "IndexSizeError" DOMException.
if (index < -1 || index >= (long)rows_length)
return WebIDL::IndexSizeError::create(global_object(), "Index is negative or greater than or equal to the number of rows");
return WebIDL::IndexSizeError::create(realm(), "Index is negative or greater than or equal to the number of rows");
// 2. If index is 1, then remove the last element in the rows collection from its parent, or do nothing if the rows collection is empty.
if (index == -1) {

View file

@ -16,7 +16,7 @@ namespace Web::HTML {
HTMLTableRowElement::HTMLTableRowElement(DOM::Document& document, DOM::QualifiedName qualified_name)
: HTMLElement(document, move(qualified_name))
{
set_prototype(&window().cached_web_prototype("HTMLTableRowElement"));
set_prototype(&Bindings::cached_web_prototype(realm(), "HTMLTableRowElement"));
}
HTMLTableRowElement::~HTMLTableRowElement() = default;

View file

@ -17,7 +17,7 @@ namespace Web::HTML {
HTMLTableSectionElement::HTMLTableSectionElement(DOM::Document& document, DOM::QualifiedName qualified_name)
: HTMLElement(document, move(qualified_name))
{
set_prototype(&window().cached_web_prototype("HTMLTableSectionElement"));
set_prototype(&Bindings::cached_web_prototype(realm(), "HTMLTableSectionElement"));
}
HTMLTableSectionElement::~HTMLTableSectionElement() = default;
@ -43,7 +43,7 @@ WebIDL::ExceptionOr<JS::NonnullGCPtr<HTMLTableRowElement>> HTMLTableSectionEleme
// 1. If index is less than 1 or greater than the number of elements in the rows collection, throw an "IndexSizeError" DOMException.
if (index < -1 || index > rows_collection_size)
return WebIDL::IndexSizeError::create(global_object(), "Index is negative or greater than the number of rows");
return WebIDL::IndexSizeError::create(realm(), "Index is negative or greater than the number of rows");
// 2. Let table row be the result of creating an element given this element's node document, tr, and the HTML namespace.
auto& table_row = static_cast<HTMLTableRowElement&>(*DOM::create_element(document(), TagNames::tr, Namespace::HTML));
@ -67,7 +67,7 @@ WebIDL::ExceptionOr<void> HTMLTableSectionElement::delete_row(long index)
// 1. If index is less than 1 or greater than or equal to the number of elements in the rows collection, then throw an "IndexSizeError" DOMException.
if (index < -1 || index >= rows_collection_size)
return WebIDL::IndexSizeError::create(global_object(), "Index is negative or greater than or equal to the number of rows");
return WebIDL::IndexSizeError::create(realm(), "Index is negative or greater than or equal to the number of rows");
// 2. If index is 1, then remove the last element in the rows collection from this element, or do nothing if the rows collection is empty.
if (index == -1) {

View file

@ -13,7 +13,7 @@ namespace Web::HTML {
HTMLTemplateElement::HTMLTemplateElement(DOM::Document& document, DOM::QualifiedName qualified_name)
: HTMLElement(document, move(qualified_name))
{
set_prototype(&window().cached_web_prototype("HTMLTemplateElement"));
set_prototype(&Bindings::cached_web_prototype(realm(), "HTMLTemplateElement"));
m_content = heap().allocate<DOM::DocumentFragment>(realm(), appropriate_template_contents_owner_document(document));
m_content->set_host(this);
@ -31,7 +31,7 @@ DOM::Document& HTMLTemplateElement::appropriate_template_contents_owner_document
{
if (!document.created_for_appropriate_template_contents()) {
if (!document.associated_inert_template_document()) {
auto new_document = DOM::Document::create(Bindings::main_thread_internal_window_object());
auto new_document = DOM::Document::create(realm());
new_document->set_created_for_appropriate_template_contents(true);
new_document->set_document_type(document.document_type());

View file

@ -12,7 +12,7 @@ namespace Web::HTML {
HTMLTextAreaElement::HTMLTextAreaElement(DOM::Document& document, DOM::QualifiedName qualified_name)
: HTMLElement(document, move(qualified_name))
{
set_prototype(&window().cached_web_prototype("HTMLTextAreaElement"));
set_prototype(&Bindings::cached_web_prototype(realm(), "HTMLTextAreaElement"));
}
HTMLTextAreaElement::~HTMLTextAreaElement() = default;

View file

@ -12,7 +12,7 @@ namespace Web::HTML {
HTMLTimeElement::HTMLTimeElement(DOM::Document& document, DOM::QualifiedName qualified_name)
: HTMLElement(document, move(qualified_name))
{
set_prototype(&window().cached_web_prototype("HTMLTimeElement"));
set_prototype(&Bindings::cached_web_prototype(realm(), "HTMLTimeElement"));
}
HTMLTimeElement::~HTMLTimeElement() = default;

View file

@ -13,7 +13,7 @@ namespace Web::HTML {
HTMLTitleElement::HTMLTitleElement(DOM::Document& document, DOM::QualifiedName qualified_name)
: HTMLElement(document, move(qualified_name))
{
set_prototype(&window().cached_web_prototype("HTMLTitleElement"));
set_prototype(&Bindings::cached_web_prototype(realm(), "HTMLTitleElement"));
}
HTMLTitleElement::~HTMLTitleElement() = default;

View file

@ -12,7 +12,7 @@ namespace Web::HTML {
HTMLTrackElement::HTMLTrackElement(DOM::Document& document, DOM::QualifiedName qualified_name)
: HTMLElement(document, move(qualified_name))
{
set_prototype(&window().cached_web_prototype("HTMLTrackElement"));
set_prototype(&Bindings::cached_web_prototype(realm(), "HTMLTrackElement"));
}
HTMLTrackElement::~HTMLTrackElement() = default;

View file

@ -12,7 +12,7 @@ namespace Web::HTML {
HTMLUListElement::HTMLUListElement(DOM::Document& document, DOM::QualifiedName qualified_name)
: HTMLElement(document, move(qualified_name))
{
set_prototype(&window().cached_web_prototype("HTMLUListElement"));
set_prototype(&Bindings::cached_web_prototype(realm(), "HTMLUListElement"));
}
HTMLUListElement::~HTMLUListElement() = default;

View file

@ -12,7 +12,7 @@ namespace Web::HTML {
HTMLUnknownElement::HTMLUnknownElement(DOM::Document& document, DOM::QualifiedName qualified_name)
: HTMLElement(document, move(qualified_name))
{
set_prototype(&window().cached_web_prototype("HTMLUnknownElement"));
set_prototype(&Bindings::cached_web_prototype(realm(), "HTMLUnknownElement"));
}
HTMLUnknownElement::~HTMLUnknownElement() = default;

View file

@ -12,7 +12,7 @@ namespace Web::HTML {
HTMLVideoElement::HTMLVideoElement(DOM::Document& document, DOM::QualifiedName qualified_name)
: HTMLMediaElement(document, move(qualified_name))
{
set_prototype(&window().cached_web_prototype("HTMLVideoElement"));
set_prototype(&Bindings::cached_web_prototype(realm(), "HTMLVideoElement"));
}
HTMLVideoElement::~HTMLVideoElement() = default;

View file

@ -4,21 +4,22 @@
* SPDX-License-Identifier: BSD-2-Clause
*/
#include <LibWeb/Bindings/Intrinsics.h>
#include <LibWeb/DOM/Document.h>
#include <LibWeb/HTML/History.h>
namespace Web::HTML {
JS::NonnullGCPtr<History> History::create(HTML::Window& window, DOM::Document& document)
JS::NonnullGCPtr<History> History::create(JS::Realm& realm, DOM::Document& document)
{
return *window.heap().allocate<History>(window.realm(), window, document);
return *realm.heap().allocate<History>(realm, realm, document);
}
History::History(HTML::Window& window, DOM::Document& document)
: PlatformObject(window.realm())
History::History(JS::Realm& realm, DOM::Document& document)
: PlatformObject(realm)
, m_associated_document(document)
{
set_prototype(&window.cached_web_prototype("History"));
set_prototype(&Bindings::cached_web_prototype(realm, "History"));
}
History::~History() = default;
@ -50,7 +51,7 @@ WebIDL::ExceptionOr<void> History::shared_history_push_replace_state(JS::Value,
// 2. If document is not fully active, then throw a "SecurityError" DOMException.
if (!m_associated_document->is_fully_active())
return WebIDL::SecurityError::create(global_object(), "Cannot perform pushState or replaceState on a document that isn't fully active.");
return WebIDL::SecurityError::create(realm(), "Cannot perform pushState or replaceState on a document that isn't fully active.");
// 3. Optionally, return. (For example, the user agent might disallow calls to these methods that are invoked on a timer,
// or from event listeners that are not triggered in response to a clear user action, or that are invoked in rapid succession.)

View file

@ -7,7 +7,6 @@
#pragma once
#include <LibJS/Heap/Handle.h>
#include <LibWeb/Bindings/PlatformObject.h>
#include <LibWeb/WebIDL/ExceptionOr.h>
@ -17,7 +16,7 @@ class History final : public Bindings::PlatformObject {
WEB_PLATFORM_OBJECT(History, Bindings::PlatformObject);
public:
static JS::NonnullGCPtr<History> create(HTML::Window&, DOM::Document&);
static JS::NonnullGCPtr<History> create(JS::Realm&, DOM::Document&);
virtual ~History() override;
@ -25,7 +24,7 @@ public:
WebIDL::ExceptionOr<void> replace_state(JS::Value data, String const& unused, String const& url);
private:
explicit History(HTML::Window&, DOM::Document&);
History(JS::Realm&, DOM::Document&);
virtual void visit_edges(Cell::Visitor&) override;

View file

@ -6,14 +6,13 @@
#include <LibGfx/Bitmap.h>
#include <LibJS/Runtime/TypedArray.h>
#include <LibWeb/Bindings/Intrinsics.h>
#include <LibWeb/HTML/ImageData.h>
#include <LibWeb/HTML/Window.h>
namespace Web::HTML {
JS::GCPtr<ImageData> ImageData::create_with_size(HTML::Window& window, int width, int height)
JS::GCPtr<ImageData> ImageData::create_with_size(JS::Realm& realm, int width, int height)
{
auto& realm = window.realm();
if (width <= 0 || height <= 0)
return nullptr;
@ -29,15 +28,15 @@ JS::GCPtr<ImageData> ImageData::create_with_size(HTML::Window& window, int width
auto bitmap_or_error = Gfx::Bitmap::try_create_wrapper(Gfx::BitmapFormat::RGBA8888, Gfx::IntSize(width, height), 1, width * sizeof(u32), data->data().data());
if (bitmap_or_error.is_error())
return nullptr;
return realm.heap().allocate<ImageData>(realm, window, bitmap_or_error.release_value(), move(data));
return realm.heap().allocate<ImageData>(realm, realm, bitmap_or_error.release_value(), move(data));
}
ImageData::ImageData(HTML::Window& window, NonnullRefPtr<Gfx::Bitmap> bitmap, JS::NonnullGCPtr<JS::Uint8ClampedArray> data)
: PlatformObject(window.realm())
ImageData::ImageData(JS::Realm& realm, NonnullRefPtr<Gfx::Bitmap> bitmap, JS::NonnullGCPtr<JS::Uint8ClampedArray> data)
: PlatformObject(realm)
, m_bitmap(move(bitmap))
, m_data(move(data))
{
set_prototype(&window.cached_web_prototype("ImageData"));
set_prototype(&Bindings::cached_web_prototype(realm, "ImageData"));
}
ImageData::~ImageData() = default;

View file

@ -15,7 +15,7 @@ class ImageData final : public Bindings::PlatformObject {
WEB_PLATFORM_OBJECT(ImageData, Bindings::PlatformObject);
public:
static JS::GCPtr<ImageData> create_with_size(HTML::Window&, int width, int height);
static JS::GCPtr<ImageData> create_with_size(JS::Realm&, int width, int height);
virtual ~ImageData() override;
@ -29,7 +29,7 @@ public:
const JS::Uint8ClampedArray* data() const;
private:
explicit ImageData(HTML::Window&, NonnullRefPtr<Gfx::Bitmap>, JS::NonnullGCPtr<JS::Uint8ClampedArray>);
ImageData(JS::Realm&, NonnullRefPtr<Gfx::Bitmap>, JS::NonnullGCPtr<JS::Uint8ClampedArray>);
virtual void visit_edges(Cell::Visitor&) override;

View file

@ -4,28 +4,28 @@
* SPDX-License-Identifier: BSD-2-Clause
*/
#include <LibWeb/Bindings/Intrinsics.h>
#include <LibWeb/DOM/Document.h>
#include <LibWeb/HTML/MessageChannel.h>
#include <LibWeb/HTML/MessagePort.h>
#include <LibWeb/HTML/Window.h>
namespace Web::HTML {
JS::NonnullGCPtr<MessageChannel> MessageChannel::create_with_global_object(HTML::Window& window)
JS::NonnullGCPtr<MessageChannel> MessageChannel::construct_impl(JS::Realm& realm)
{
return *window.heap().allocate<MessageChannel>(window.realm(), window);
return *realm.heap().allocate<MessageChannel>(realm, realm);
}
MessageChannel::MessageChannel(HTML::Window& window)
: PlatformObject(window.realm())
MessageChannel::MessageChannel(JS::Realm& realm)
: PlatformObject(realm)
{
set_prototype(&window.cached_web_prototype("MessageChannel"));
set_prototype(&Bindings::cached_web_prototype(realm, "MessageChannel"));
// 1. Set this's port 1 to a new MessagePort in this's relevant Realm.
m_port1 = MessagePort::create(window);
m_port1 = MessagePort::create(realm);
// 2. Set this's port 2 to a new MessagePort in this's relevant Realm.
m_port2 = MessagePort::create(window);
m_port2 = MessagePort::create(realm);
// 3. Entangle this's port 1 and this's port 2.
m_port1->entangle_with(*m_port2);

View file

@ -16,7 +16,7 @@ class MessageChannel final : public Bindings::PlatformObject {
WEB_PLATFORM_OBJECT(MessageChannel, Bindings::PlatformObject);
public:
static JS::NonnullGCPtr<MessageChannel> create_with_global_object(HTML::Window&);
static JS::NonnullGCPtr<MessageChannel> construct_impl(JS::Realm&);
virtual ~MessageChannel() override;
MessagePort* port1();
@ -26,7 +26,7 @@ public:
MessagePort const* port2() const;
private:
explicit MessageChannel(HTML::Window&);
explicit MessageChannel(JS::Realm&);
virtual void visit_edges(Cell::Visitor&) override;

View file

@ -4,28 +4,34 @@
* SPDX-License-Identifier: BSD-2-Clause
*/
#include <LibWeb/Bindings/Intrinsics.h>
#include <LibWeb/HTML/MessageEvent.h>
#include <LibWeb/HTML/Window.h>
namespace Web::HTML {
MessageEvent* MessageEvent::create(HTML::Window& window_object, FlyString const& event_name, MessageEventInit const& event_init)
MessageEvent* MessageEvent::create(JS::Realm& realm, FlyString const& event_name, MessageEventInit const& event_init)
{
return window_object.heap().allocate<MessageEvent>(window_object.realm(), window_object, event_name, event_init);
return realm.heap().allocate<MessageEvent>(realm, realm, event_name, event_init);
}
MessageEvent* MessageEvent::create_with_global_object(HTML::Window& window_object, FlyString const& event_name, MessageEventInit const& event_init)
MessageEvent* MessageEvent::create(HTML::Window& window, FlyString const& event_name, MessageEventInit const& event_init)
{
return create(window_object, event_name, event_init);
return create(window.realm(), event_name, event_init);
}
MessageEvent::MessageEvent(HTML::Window& window_object, FlyString const& event_name, MessageEventInit const& event_init)
: DOM::Event(window_object, event_name, event_init)
MessageEvent* MessageEvent::construct_impl(JS::Realm& realm, FlyString const& event_name, MessageEventInit const& event_init)
{
return create(realm, event_name, event_init);
}
MessageEvent::MessageEvent(JS::Realm& realm, FlyString const& event_name, MessageEventInit const& event_init)
: DOM::Event(realm, event_name, event_init)
, m_data(event_init.data)
, m_origin(event_init.origin)
, m_last_event_id(event_init.last_event_id)
{
set_prototype(&window_object.cached_web_prototype("MessageEvent"));
set_prototype(&Bindings::cached_web_prototype(realm, "MessageEvent"));
}
MessageEvent::~MessageEvent() = default;

View file

@ -21,10 +21,11 @@ class MessageEvent : public DOM::Event {
WEB_PLATFORM_OBJECT(MessageEvent, DOM::Event);
public:
static MessageEvent* create(JS::Realm&, FlyString const& event_name, MessageEventInit const& event_init = {});
static MessageEvent* create(HTML::Window&, FlyString const& event_name, MessageEventInit const& event_init = {});
static MessageEvent* create_with_global_object(HTML::Window&, FlyString const& event_name, MessageEventInit const& event_init);
static MessageEvent* construct_impl(JS::Realm&, FlyString const& event_name, MessageEventInit const& event_init);
MessageEvent(HTML::Window&, FlyString const& event_name, MessageEventInit const& event_init);
MessageEvent(JS::Realm&, FlyString const& event_name, MessageEventInit const& event_init);
virtual ~MessageEvent() override;
JS::Value data() const { return m_data; }

View file

@ -4,25 +4,25 @@
* SPDX-License-Identifier: BSD-2-Clause
*/
#include <LibWeb/Bindings/Intrinsics.h>
#include <LibWeb/DOM/EventDispatcher.h>
#include <LibWeb/HTML/EventHandler.h>
#include <LibWeb/HTML/EventLoop/EventLoop.h>
#include <LibWeb/HTML/EventNames.h>
#include <LibWeb/HTML/MessageEvent.h>
#include <LibWeb/HTML/MessagePort.h>
#include <LibWeb/HTML/Window.h>
namespace Web::HTML {
JS::NonnullGCPtr<MessagePort> MessagePort::create(HTML::Window& window)
JS::NonnullGCPtr<MessagePort> MessagePort::create(JS::Realm& realm)
{
return *window.heap().allocate<MessagePort>(window.realm(), window);
return *realm.heap().allocate<MessagePort>(realm, realm);
}
MessagePort::MessagePort(HTML::Window& window)
: DOM::EventTarget(window.realm())
MessagePort::MessagePort(JS::Realm& realm)
: DOM::EventTarget(realm)
{
set_prototype(&window.cached_web_prototype("MessagePort"));
set_prototype(&Bindings::cached_web_prototype(realm, "MessagePort"));
}
MessagePort::~MessagePort() = default;
@ -92,7 +92,7 @@ void MessagePort::post_message(JS::Value message)
MessageEventInit event_init {};
event_init.data = message;
event_init.origin = "<origin>";
target_port->dispatch_event(*MessageEvent::create(verify_cast<HTML::Window>(target_port->realm().global_object()), HTML::EventNames::message, event_init));
target_port->dispatch_event(*MessageEvent::create(target_port->realm(), HTML::EventNames::message, event_init));
}));
}

Some files were not shown because too many files have changed in this diff Show more