2022-09-04 16:56:15 +02:00
/*
2024-10-04 13:19:50 +02:00
* Copyright ( c ) 2022 , Andreas Kling < andreas @ ladybird . org >
2022-09-04 16:56:15 +02:00
*
* SPDX - License - Identifier : BSD - 2 - Clause
*/
2024-04-27 12:09:58 +12:00
# include <LibWeb/Bindings/DOMExceptionPrototype.h>
2022-09-25 16:15:49 -06:00
# include <LibWeb/Bindings/Intrinsics.h>
2024-11-22 12:17:18 +01:00
# include <LibWeb/HTML/StructuredSerialize.h>
2022-09-25 17:28:46 +01:00
# include <LibWeb/WebIDL/DOMException.h>
2022-09-04 16:56:15 +02:00
2022-09-25 17:28:46 +01:00
namespace Web : : WebIDL {
2022-09-04 16:56:15 +02:00
2024-11-15 04:01:23 +13:00
GC_DEFINE_ALLOCATOR ( DOMException ) ;
2023-11-19 19:47:52 +01:00
2024-11-15 04:01:23 +13:00
GC : : Ref < DOMException > DOMException : : create ( JS : : Realm & realm , FlyString name , String message )
2022-09-04 16:56:15 +02:00
{
2024-11-14 05:50:17 +13:00
return realm . create < DOMException > ( realm , move ( name ) , move ( message ) ) ;
2022-09-04 16:56:15 +02:00
}
2024-11-22 12:17:18 +01:00
GC : : Ref < DOMException > DOMException : : create ( JS : : Realm & realm )
{
return realm . create < DOMException > ( realm ) ;
}
2024-11-15 04:01:23 +13:00
GC : : Ref < DOMException > DOMException : : construct_impl ( JS : : Realm & realm , String message , FlyString name )
2022-09-04 16:56:15 +02:00
{
2024-11-14 05:50:17 +13:00
return realm . create < DOMException > ( realm , move ( name ) , move ( message ) ) ;
2022-09-04 16:56:15 +02:00
}
2024-10-12 20:56:21 +02:00
DOMException : : DOMException ( JS : : Realm & realm , FlyString name , String message )
2022-09-25 16:15:49 -06:00
: PlatformObject ( realm )
2024-10-12 20:56:21 +02:00
, m_name ( move ( name ) )
, m_message ( move ( message ) )
2022-09-04 16:56:15 +02:00
{
}
2024-11-22 12:17:18 +01:00
DOMException : : DOMException ( JS : : Realm & realm )
: PlatformObject ( realm )
{
}
2022-09-04 16:56:15 +02:00
DOMException : : ~ DOMException ( ) = default ;
2023-08-07 08:41:28 +02:00
void DOMException : : initialize ( JS : : Realm & realm )
2023-01-10 06:28:20 -05:00
{
2024-03-16 13:13:08 +01:00
WEB_SET_PROTOTYPE_FOR_INTERFACE ( DOMException ) ;
2025-04-20 16:22:57 +02:00
Base : : initialize ( realm ) ;
2023-01-10 06:28:20 -05:00
}
2024-11-22 12:17:18 +01:00
ExceptionOr < void > DOMException : : serialization_steps ( HTML : : SerializationRecord & record , bool , HTML : : SerializationMemory & )
{
auto & vm = this - > vm ( ) ;
// 1. Set serialized.[[Name]] to value’ s name.
TRY ( HTML : : serialize_string ( vm , record , m_name . to_string ( ) ) ) ;
// 2. Set serialized.[[Message]] to value’ s 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 value’ s name to serialized.[[Name]].
m_name = TRY ( HTML : : deserialize_string ( vm , record , position ) ) ;
// 2. Set value’ s 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 { } ;
}
2022-09-04 16:56:15 +02:00
}