mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 00:58:12 +00:00
LibWeb: Make DOMParser GC-allocated
This commit is contained in:
parent
8341f142ea
commit
d5e831988e
4 changed files with 18 additions and 20 deletions
|
@ -453,7 +453,6 @@ class CanvasGradientWrapper;
|
||||||
class CanvasRenderingContext2DWrapper;
|
class CanvasRenderingContext2DWrapper;
|
||||||
class CryptoWrapper;
|
class CryptoWrapper;
|
||||||
class DOMExceptionWrapper;
|
class DOMExceptionWrapper;
|
||||||
class DOMParserWrapper;
|
|
||||||
class DOMPointWrapper;
|
class DOMPointWrapper;
|
||||||
class DOMPointReadOnlyWrapper;
|
class DOMPointReadOnlyWrapper;
|
||||||
class DOMRectListWrapper;
|
class DOMRectListWrapper;
|
||||||
|
|
|
@ -8,13 +8,20 @@
|
||||||
#include <LibWeb/Bindings/MainThreadVM.h>
|
#include <LibWeb/Bindings/MainThreadVM.h>
|
||||||
#include <LibWeb/HTML/DOMParser.h>
|
#include <LibWeb/HTML/DOMParser.h>
|
||||||
#include <LibWeb/HTML/Parser/HTMLParser.h>
|
#include <LibWeb/HTML/Parser/HTMLParser.h>
|
||||||
|
#include <LibWeb/HTML/Scripting/Environments.h>
|
||||||
#include <LibWeb/XML/XMLDocumentBuilder.h>
|
#include <LibWeb/XML/XMLDocumentBuilder.h>
|
||||||
|
|
||||||
namespace Web::HTML {
|
namespace Web::HTML {
|
||||||
|
|
||||||
DOMParser::DOMParser(HTML::Window& window)
|
DOM::ExceptionOr<JS::NonnullGCPtr<DOMParser>> DOMParser::create_with_global_object(HTML::Window& window)
|
||||||
: m_window(JS::make_handle(window))
|
|
||||||
{
|
{
|
||||||
|
return JS::NonnullGCPtr(*window.heap().allocate<DOMParser>(window.realm(), window));
|
||||||
|
}
|
||||||
|
|
||||||
|
DOMParser::DOMParser(HTML::Window& window)
|
||||||
|
: PlatformObject(window.realm())
|
||||||
|
{
|
||||||
|
set_prototype(&window.ensure_web_prototype<Bindings::DOMParserPrototype>("DOMParser"));
|
||||||
}
|
}
|
||||||
|
|
||||||
DOMParser::~DOMParser() = default;
|
DOMParser::~DOMParser() = default;
|
||||||
|
@ -23,7 +30,7 @@ DOMParser::~DOMParser() = default;
|
||||||
JS::NonnullGCPtr<DOM::Document> DOMParser::parse_from_string(String const& string, Bindings::DOMParserSupportedType type)
|
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.
|
// 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(), m_window->associated_document().url());
|
auto document = DOM::Document::create(Bindings::main_thread_internal_window_object(), verify_cast<HTML::Window>(relevant_global_object(*this)).associated_document().url());
|
||||||
document->set_content_type(Bindings::idl_enum_to_string(type));
|
document->set_content_type(Bindings::idl_enum_to_string(type));
|
||||||
|
|
||||||
// 2. Switch on type:
|
// 2. Switch on type:
|
||||||
|
|
|
@ -6,9 +6,7 @@
|
||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <AK/RefCounted.h>
|
#include <LibWeb/Bindings/PlatformObject.h>
|
||||||
#include <AK/Weakable.h>
|
|
||||||
#include <LibWeb/Bindings/Wrappable.h>
|
|
||||||
#include <LibWeb/DOM/Document.h>
|
#include <LibWeb/DOM/Document.h>
|
||||||
#include <LibWeb/DOM/ExceptionOr.h>
|
#include <LibWeb/DOM/ExceptionOr.h>
|
||||||
#include <LibWeb/Forward.h>
|
#include <LibWeb/Forward.h>
|
||||||
|
@ -16,17 +14,11 @@
|
||||||
namespace Web::HTML {
|
namespace Web::HTML {
|
||||||
|
|
||||||
// https://html.spec.whatwg.org/multipage/dynamic-markup-insertion.html#domparser
|
// https://html.spec.whatwg.org/multipage/dynamic-markup-insertion.html#domparser
|
||||||
class DOMParser final
|
class DOMParser final : public Bindings::PlatformObject {
|
||||||
: public RefCounted<DOMParser>
|
WEB_PLATFORM_OBJECT(DOMParser, Bindings::PlatformObject);
|
||||||
, public Weakable<DOMParser>
|
|
||||||
, public Bindings::Wrappable {
|
|
||||||
public:
|
|
||||||
using WrapperType = Bindings::DOMParserWrapper;
|
|
||||||
|
|
||||||
static DOM::ExceptionOr<NonnullRefPtr<DOMParser>> create_with_global_object(HTML::Window& window)
|
public:
|
||||||
{
|
static DOM::ExceptionOr<JS::NonnullGCPtr<DOMParser>> create_with_global_object(HTML::Window&);
|
||||||
return adopt_ref(*new DOMParser(window));
|
|
||||||
}
|
|
||||||
|
|
||||||
virtual ~DOMParser() override;
|
virtual ~DOMParser() override;
|
||||||
|
|
||||||
|
@ -34,8 +26,8 @@ public:
|
||||||
|
|
||||||
private:
|
private:
|
||||||
explicit DOMParser(HTML::Window&);
|
explicit DOMParser(HTML::Window&);
|
||||||
|
|
||||||
JS::Handle<HTML::Window> m_window;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
WRAPPER_HACK(DOMParser, Web::HTML)
|
||||||
|
|
|
@ -64,7 +64,7 @@ libweb_js_wrapper(Geometry/DOMRectReadOnly)
|
||||||
libweb_js_wrapper(HTML/CanvasGradient)
|
libweb_js_wrapper(HTML/CanvasGradient)
|
||||||
libweb_js_wrapper(HTML/CanvasRenderingContext2D)
|
libweb_js_wrapper(HTML/CanvasRenderingContext2D)
|
||||||
libweb_js_wrapper(HTML/CloseEvent NO_INSTANCE)
|
libweb_js_wrapper(HTML/CloseEvent NO_INSTANCE)
|
||||||
libweb_js_wrapper(HTML/DOMParser)
|
libweb_js_wrapper(HTML/DOMParser NO_INSTANCE)
|
||||||
libweb_js_wrapper(HTML/DOMStringMap NO_INSTANCE)
|
libweb_js_wrapper(HTML/DOMStringMap NO_INSTANCE)
|
||||||
libweb_js_wrapper(HTML/ErrorEvent NO_INSTANCE)
|
libweb_js_wrapper(HTML/ErrorEvent NO_INSTANCE)
|
||||||
libweb_js_wrapper(HTML/History)
|
libweb_js_wrapper(HTML/History)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue