ladybird/Libraries/LibWeb/WebIDL/DOMException.cpp
Andreas Kling a6dfc74e93 LibWeb: Only set prototype once for object with IDL interface
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.
2025-04-20 18:43:11 +02:00

81 lines
2.3 KiB
C++
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

/*
* Copyright (c) 2022, Andreas Kling <andreas@ladybird.org>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#include <LibWeb/Bindings/DOMExceptionPrototype.h>
#include <LibWeb/Bindings/Intrinsics.h>
#include <LibWeb/HTML/StructuredSerialize.h>
#include <LibWeb/WebIDL/DOMException.h>
namespace Web::WebIDL {
GC_DEFINE_ALLOCATOR(DOMException);
GC::Ref<DOMException> DOMException::create(JS::Realm& realm, FlyString name, String message)
{
return realm.create<DOMException>(realm, move(name), move(message));
}
GC::Ref<DOMException> DOMException::create(JS::Realm& realm)
{
return realm.create<DOMException>(realm);
}
GC::Ref<DOMException> DOMException::construct_impl(JS::Realm& realm, String message, FlyString name)
{
return realm.create<DOMException>(realm, move(name), move(message));
}
DOMException::DOMException(JS::Realm& realm, FlyString name, String message)
: PlatformObject(realm)
, m_name(move(name))
, m_message(move(message))
{
}
DOMException::DOMException(JS::Realm& realm)
: PlatformObject(realm)
{
}
DOMException::~DOMException() = default;
void DOMException::initialize(JS::Realm& realm)
{
WEB_SET_PROTOTYPE_FOR_INTERFACE(DOMException);
Base::initialize(realm);
}
ExceptionOr<void> DOMException::serialization_steps(HTML::SerializationRecord& record, bool, HTML::SerializationMemory&)
{
auto& vm = this->vm();
// 1. Set serialized.[[Name]] to values name.
TRY(HTML::serialize_string(vm, record, m_name.to_string()));
// 2. Set serialized.[[Message]] to values message.
TRY(HTML::serialize_string(vm, record, m_message.to_string()));
// FIXME: 3. User agents should attach a serialized representation of any interesting accompanying data which are not yet specified, notably the stack property, to serialized.
return {};
}
ExceptionOr<void> DOMException::deserialization_steps(ReadonlySpan<u32> const& record, size_t& position, HTML::DeserializationMemory&)
{
auto& vm = this->vm();
// 1. Set values name to serialized.[[Name]].
m_name = TRY(HTML::deserialize_string(vm, record, position));
// 2. Set values message to serialized.[[Message]].
m_message = TRY(HTML::deserialize_string(vm, record, position));
// FIXME: 3. If any other data is attached to serialized, then deserialize and attach it to value.
return {};
}
}