mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-06-13 13:51:51 +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.
68 lines
2.3 KiB
C++
68 lines
2.3 KiB
C++
/*
|
|
* Copyright (c) 2021, Idan Horowitz <idan.horowitz@serenityos.org>
|
|
*
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
|
*/
|
|
|
|
#include <LibJS/Runtime/Array.h>
|
|
#include <LibJS/Runtime/Iterator.h>
|
|
#include <LibWeb/Bindings/Intrinsics.h>
|
|
#include <LibWeb/Bindings/URLSearchParamsIteratorPrototype.h>
|
|
#include <LibWeb/DOMURL/URLSearchParamsIterator.h>
|
|
|
|
namespace Web::Bindings {
|
|
|
|
template<>
|
|
void Intrinsics::create_web_prototype_and_constructor<URLSearchParamsIteratorPrototype>(JS::Realm& realm)
|
|
{
|
|
auto prototype = realm.create<URLSearchParamsIteratorPrototype>(realm);
|
|
m_prototypes.set("URLSearchParamsIterator"_fly_string, prototype);
|
|
}
|
|
|
|
}
|
|
|
|
namespace Web::DOMURL {
|
|
|
|
GC_DEFINE_ALLOCATOR(URLSearchParamsIterator);
|
|
|
|
WebIDL::ExceptionOr<GC::Ref<URLSearchParamsIterator>> URLSearchParamsIterator::create(URLSearchParams const& url_search_params, JS::Object::PropertyKind iteration_kind)
|
|
{
|
|
return url_search_params.realm().create<URLSearchParamsIterator>(url_search_params, iteration_kind);
|
|
}
|
|
|
|
URLSearchParamsIterator::URLSearchParamsIterator(URLSearchParams const& url_search_params, JS::Object::PropertyKind iteration_kind)
|
|
: PlatformObject(url_search_params.realm())
|
|
, m_url_search_params(url_search_params)
|
|
, m_iteration_kind(iteration_kind)
|
|
{
|
|
}
|
|
|
|
URLSearchParamsIterator::~URLSearchParamsIterator() = default;
|
|
|
|
void URLSearchParamsIterator::initialize(JS::Realm& realm)
|
|
{
|
|
WEB_SET_PROTOTYPE_FOR_INTERFACE(URLSearchParamsIterator);
|
|
Base::initialize(realm);
|
|
}
|
|
|
|
void URLSearchParamsIterator::visit_edges(JS::Cell::Visitor& visitor)
|
|
{
|
|
Base::visit_edges(visitor);
|
|
visitor.visit(m_url_search_params);
|
|
}
|
|
|
|
JS::Object* URLSearchParamsIterator::next()
|
|
{
|
|
if (m_index >= m_url_search_params->m_list.size())
|
|
return create_iterator_result_object(vm(), JS::js_undefined(), true);
|
|
|
|
auto& entry = m_url_search_params->m_list[m_index++];
|
|
if (m_iteration_kind == JS::Object::PropertyKind::Key)
|
|
return create_iterator_result_object(vm(), JS::PrimitiveString::create(vm(), entry.name), false);
|
|
else if (m_iteration_kind == JS::Object::PropertyKind::Value)
|
|
return create_iterator_result_object(vm(), JS::PrimitiveString::create(vm(), entry.value), false);
|
|
|
|
return create_iterator_result_object(vm(), JS::Array::create_from(realm(), { JS::PrimitiveString::create(vm(), entry.name), JS::PrimitiveString::create(vm(), entry.value) }), false);
|
|
}
|
|
|
|
}
|