1
0
mirror of https://github.com/SerenityOS/serenity synced 2024-07-09 05:20:45 +00:00

LibWeb: Add IDL definition for SVGScriptElement

It does not currently handle any of the actual scripting, but this
should at least allow us to create an instance of the element.

The test being added here isn't actually testing much, but before the
previous commit we used to crash parsing the page due to a TODO().
This commit is contained in:
Shannon Booth 2023-09-23 08:56:49 +12:00 committed by Andreas Kling
parent 60c32f39a1
commit 07b332e17c
9 changed files with 78 additions and 0 deletions

View File

@ -0,0 +1 @@
Name = SVGScriptElement

View File

@ -0,0 +1,7 @@
<script src="../include.js"></script>
<svg xmlns="http://www.w3.org/2000/svg"><script id="svg-script-element"></script></svg>
<script>
test(() => {
println(`Name = ${document.getElementById('svg-script-element').constructor.name}`);
});
</script>

View File

@ -569,6 +569,7 @@ set(SOURCES
SVG/SVGPolylineElement.cpp
SVG/SVGRectElement.cpp
SVG/SVGRadialGradientElement.cpp
SVG/SVGScriptElement.cpp
SVG/SVGSVGElement.cpp
SVG/SVGStopElement.cpp
SVG/SVGStyleElement.cpp

View File

@ -98,6 +98,7 @@
#include <LibWeb/SVG/SVGRadialGradientElement.h>
#include <LibWeb/SVG/SVGRectElement.h>
#include <LibWeb/SVG/SVGSVGElement.h>
#include <LibWeb/SVG/SVGScriptElement.h>
#include <LibWeb/SVG/SVGStopElement.h>
#include <LibWeb/SVG/SVGStyleElement.h>
#include <LibWeb/SVG/SVGSymbolElement.h>
@ -472,6 +473,8 @@ static JS::GCPtr<SVG::SVGElement> create_svg_element(JS::Realm& realm, Document&
return realm.heap().allocate<SVG::SVGTSpanElement>(realm, document, move(qualified_name));
if (local_name == SVG::TagNames::use)
return realm.heap().allocate<SVG::SVGUseElement>(realm, document, move(qualified_name));
if (local_name == SVG::TagNames::script)
return realm.heap().allocate<SVG::SVGScriptElement>(realm, document, move(qualified_name));
return nullptr;
}

View File

@ -76,6 +76,7 @@ public:
virtual bool is_svg_container() const { return false; }
virtual bool is_svg_element() const { return false; }
virtual bool is_svg_graphics_element() const { return false; }
virtual bool is_svg_script_element() const { return false; }
virtual bool is_svg_svg_element() const { return false; }
virtual bool is_svg_use_element() const { return false; }

View File

@ -0,0 +1,22 @@
/*
* Copyright (c) 2023, Shannon Booth <shannon@serenityos.org>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#include <LibWeb/SVG/SVGScriptElement.h>
namespace Web::SVG {
SVGScriptElement::SVGScriptElement(DOM::Document& document, DOM::QualifiedName qualified_name)
: SVGElement(document, move(qualified_name))
{
}
void SVGScriptElement::initialize(JS::Realm& realm)
{
Base::initialize(realm);
set_prototype(&Bindings::ensure_web_prototype<Bindings::SVGScriptElementPrototype>(realm, "SVGScriptElement"));
}
}

View File

@ -0,0 +1,34 @@
/*
* Copyright (c) 2023, Shannon Booth <shannon@serenityos.org>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#pragma once
#include <LibWeb/SVG/SVGElement.h>
namespace Web::SVG {
// https://www.w3.org/TR/SVG/interact.html#InterfaceSVGScriptElement
class SVGScriptElement : public SVGElement {
WEB_PLATFORM_OBJECT(SVGScriptElement, SVGElement);
public:
protected:
SVGScriptElement(DOM::Document&, DOM::QualifiedName);
virtual void initialize(JS::Realm&) override;
private:
virtual bool is_svg_script_element() const final { return true; }
};
}
namespace Web::DOM {
template<>
inline bool Node::fast_is<SVG::SVGScriptElement>() const { return is_svg_script_element(); }
}

View File

@ -0,0 +1,8 @@
// https://www.w3.org/TR/SVG/interact.html#InterfaceSVGScriptElement
[Exposed=Window]
interface SVGScriptElement : SVGElement {
[Reflect] attribute DOMString type;
[Reflect=crossorigin] attribute DOMString? crossOrigin;
};
// FIXME: SVGScriptElement includes SVGURIReference;

View File

@ -238,6 +238,7 @@ libweb_js_bindings(SVG/SVGPolygonElement)
libweb_js_bindings(SVG/SVGPolylineElement)
libweb_js_bindings(SVG/SVGRadialGradientElement)
libweb_js_bindings(SVG/SVGRectElement)
libweb_js_bindings(SVG/SVGScriptElement)
libweb_js_bindings(SVG/SVGSVGElement)
libweb_js_bindings(SVG/SVGStopElement)
libweb_js_bindings(SVG/SVGStyleElement)