mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-06-06 10:22:57 +00:00
Before this change, we were going through the chain of base classes for each IDL interface object and having them set the prototype to their prototype. Instead of doing that, reorder things so that we set the right prototype immediately in Foo::initialize(), and then don't bother in all the base class overrides. This knocks off a ~1% profile item on Speedometer 3.
73 lines
2.3 KiB
C++
73 lines
2.3 KiB
C++
/*
|
|
* Copyright (c) 2024, MacDue <macdue@dueutil.tech>
|
|
*
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
|
*/
|
|
|
|
#include <LibWeb/Bindings/Intrinsics.h>
|
|
#include <LibWeb/Bindings/SVGTransformListPrototype.h>
|
|
#include <LibWeb/SVG/SVGTransformList.h>
|
|
#include <LibWeb/WebIDL/ExceptionOr.h>
|
|
|
|
namespace Web::SVG {
|
|
|
|
GC_DEFINE_ALLOCATOR(SVGTransformList);
|
|
|
|
GC::Ref<SVGTransformList> SVGTransformList::create(JS::Realm& realm)
|
|
{
|
|
return realm.create<SVGTransformList>(realm);
|
|
}
|
|
|
|
SVGTransformList::~SVGTransformList() = default;
|
|
|
|
SVGTransformList::SVGTransformList(JS::Realm& realm)
|
|
: PlatformObject(realm)
|
|
{
|
|
}
|
|
|
|
// https://svgwg.org/svg2-draft/single-page.html#types-__svg__SVGNameList__length
|
|
WebIDL::UnsignedLong SVGTransformList::length()
|
|
{
|
|
// The length and numberOfItems IDL attributes represents the length of the list, and on getting simply return the length of the list.
|
|
return m_transforms.size();
|
|
}
|
|
|
|
// https://svgwg.org/svg2-draft/single-page.html#types-__svg__SVGNameList__numberOfItems
|
|
WebIDL::UnsignedLong SVGTransformList::number_of_items()
|
|
{
|
|
// The length and numberOfItems IDL attributes represents the length of the list, and on getting simply return the length of the list.
|
|
return m_transforms.size();
|
|
}
|
|
|
|
// https://svgwg.org/svg2-draft/single-page.html#types-__svg__SVGNameList__getItem
|
|
WebIDL::ExceptionOr<GC::Ref<SVGTransform>> SVGTransformList::get_item(WebIDL::UnsignedLong index)
|
|
{
|
|
// 1. If index is greater than or equal to the length of the list, then throw an IndexSizeError.
|
|
if (index >= m_transforms.size())
|
|
return WebIDL::IndexSizeError::create(realm(), "SVGTransformList index out of bounds"_string);
|
|
// 2. Return the element in the list at position index.
|
|
return m_transforms.at(index);
|
|
}
|
|
|
|
// https://svgwg.org/svg2-draft/single-page.html#types-__svg__SVGNameList__appendItem
|
|
GC::Ref<SVGTransform> SVGTransformList::append_item(GC::Ref<SVGTransform> new_item)
|
|
{
|
|
// FIXME: This does not implement the steps from the specification.
|
|
m_transforms.append(new_item);
|
|
return new_item;
|
|
}
|
|
|
|
void SVGTransformList::initialize(JS::Realm& realm)
|
|
{
|
|
WEB_SET_PROTOTYPE_FOR_INTERFACE(SVGTransformList);
|
|
Base::initialize(realm);
|
|
}
|
|
|
|
void SVGTransformList::visit_edges(Cell::Visitor& visitor)
|
|
{
|
|
Base::visit_edges(visitor);
|
|
for (auto transform : m_transforms)
|
|
transform->visit_edges(visitor);
|
|
}
|
|
|
|
}
|