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:
parent
60c32f39a1
commit
07b332e17c
Notes:
sideshowbarker
2024-07-17 06:54:15 +09:00
Author: https://github.com/shannonbooth Commit: https://github.com/SerenityOS/serenity/commit/07b332e17c Pull-request: https://github.com/SerenityOS/serenity/pull/21197
9 changed files with 78 additions and 0 deletions
1
Tests/LibWeb/Text/expected/SVG/svg-script-element.txt
Normal file
1
Tests/LibWeb/Text/expected/SVG/svg-script-element.txt
Normal file
|
@ -0,0 +1 @@
|
|||
Name = SVGScriptElement
|
7
Tests/LibWeb/Text/input/SVG/svg-script-element.html
Normal file
7
Tests/LibWeb/Text/input/SVG/svg-script-element.html
Normal 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>
|
|
@ -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
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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; }
|
||||
|
||||
|
|
22
Userland/Libraries/LibWeb/SVG/SVGScriptElement.cpp
Normal file
22
Userland/Libraries/LibWeb/SVG/SVGScriptElement.cpp
Normal 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"));
|
||||
}
|
||||
|
||||
}
|
34
Userland/Libraries/LibWeb/SVG/SVGScriptElement.h
Normal file
34
Userland/Libraries/LibWeb/SVG/SVGScriptElement.h
Normal 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(); }
|
||||
|
||||
}
|
8
Userland/Libraries/LibWeb/SVG/SVGScriptElement.idl
Normal file
8
Userland/Libraries/LibWeb/SVG/SVGScriptElement.idl
Normal 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;
|
|
@ -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)
|
||||
|
|
Loading…
Add table
Reference in a new issue