ladybird/Libraries/LibWeb/WebIDL/DOMException.cpp
Timothy Flynn 64abc6101d LibWeb+WebWorker: Use IPC mechanics for structured serialization
Our structured serialization implementation had its own bespoke encoder
and decoder to serialize JS values. It also used a u32 buffer under the
hood, which made using its structures a bit awkward. We had previously
worked around its data structures in transferable streams, which nested
transfers of MessagePort instances. We basically had to add hooks into
the MessagePort to route to the correct transfer receiving steps, and
we could not invoke the correct AOs directly as the spec dictates.

We now use IPC mechanics to encode and decode data. This works because,
although we are encoding JS values, we are only ultimately encoding
primitive and basic AK types. The resulting data structures actually
enforce that we implement transferable streams exactly as the spec is
worded (I had planned to do that in a separate commit, but the fallout
of this patch actually required that change).
2025-07-18 10:09:02 -04:00

77 lines
2.2 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);
}
WebIDL::ExceptionOr<void> DOMException::serialization_steps(HTML::TransferDataEncoder& serialized, bool, HTML::SerializationMemory&)
{
// 1. Set serialized.[[Name]] to values name.
serialized.encode(m_name.to_string());
// 2. Set serialized.[[Message]] to values message.
serialized.encode(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 {};
}
WebIDL::ExceptionOr<void> DOMException::deserialization_steps(HTML::TransferDataDecoder& serialized, HTML::DeserializationMemory&)
{
// 1. Set values name to serialized.[[Name]].
m_name = serialized.decode<String>();
// 2. Set values message to serialized.[[Message]].
m_message = serialized.decode<String>();
// FIXME: 3. If any other data is attached to serialized, then deserialize and attach it to value.
return {};
}
}