mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 05:17:34 +00:00
LibWeb: Remove unecessary dependence on Window from DOM and WebIDL
These classes only needed Window to get at its realm. Pass a realm directly to construct DOM and WebIDL classes. This change importantly removes the guarantee that a Document will always have a non-null Window object. Only Documents created by a BrowsingContext will have a non-null Window object. Documents created by for example, DocumentFragment, will not have a Window (soon). This incremental commit leaves some workarounds in place to keep other parts of the code building.
This commit is contained in:
parent
8407bf60c5
commit
8de7e49a56
56 changed files with 364 additions and 326 deletions
|
@ -4,9 +4,11 @@
|
|||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*/
|
||||
|
||||
#include <LibWeb/Bindings/Intrinsics.h>
|
||||
#include <LibWeb/DOM/Range.h>
|
||||
#include <LibWeb/DOM/Text.h>
|
||||
#include <LibWeb/HTML/HTMLInputElement.h>
|
||||
#include <LibWeb/HTML/Scripting/Environments.h>
|
||||
#include <LibWeb/HTML/Window.h>
|
||||
#include <LibWeb/Layout/TextNode.h>
|
||||
|
||||
|
@ -15,13 +17,13 @@ namespace Web::DOM {
|
|||
Text::Text(Document& document, String const& data)
|
||||
: CharacterData(document, NodeType::TEXT_NODE, data)
|
||||
{
|
||||
set_prototype(&window().cached_web_prototype("Text"));
|
||||
set_prototype(&Bindings::cached_web_prototype(realm(), "Text"));
|
||||
}
|
||||
|
||||
Text::Text(Document& document, NodeType type, String const& data)
|
||||
: CharacterData(document, type, data)
|
||||
{
|
||||
set_prototype(&window().cached_web_prototype("Text"));
|
||||
set_prototype(&Bindings::cached_web_prototype(realm(), "Text"));
|
||||
}
|
||||
|
||||
void Text::visit_edges(Cell::Visitor& visitor)
|
||||
|
@ -31,9 +33,11 @@ void Text::visit_edges(Cell::Visitor& visitor)
|
|||
}
|
||||
|
||||
// https://dom.spec.whatwg.org/#dom-text-text
|
||||
JS::NonnullGCPtr<Text> Text::create_with_global_object(HTML::Window& window, String const& data)
|
||||
JS::NonnullGCPtr<Text> Text::construct_impl(JS::Realm& realm, String const& data)
|
||||
{
|
||||
return *window.heap().allocate<Text>(window.realm(), window.associated_document(), data);
|
||||
// The new Text(data) constructor steps are to set this’s data to data and this’s node document to current global object’s associated Document.
|
||||
auto& window = verify_cast<HTML::Window>(HTML::current_global_object());
|
||||
return *realm.heap().allocate<Text>(realm, window.associated_document(), data);
|
||||
}
|
||||
|
||||
void Text::set_owner_input_element(Badge<HTML::HTMLInputElement>, HTML::HTMLInputElement& input_element)
|
||||
|
@ -50,7 +54,7 @@ WebIDL::ExceptionOr<JS::NonnullGCPtr<Text>> Text::split_text(size_t offset)
|
|||
|
||||
// 2. If offset is greater than length, then throw an "IndexSizeError" DOMException.
|
||||
if (offset > length)
|
||||
return WebIDL::IndexSizeError::create(global_object(), "Split offset is greater than length");
|
||||
return WebIDL::IndexSizeError::create(realm(), "Split offset is greater than length");
|
||||
|
||||
// 3. Let count be length minus offset.
|
||||
auto count = length - offset;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue