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
2025-08-07 19:31:52 -04:00
GC : : Ref < DOMException > DOMException : : create ( JS : : Realm & realm , FlyString name , Utf16String const & message )
2022-09-04 16:56:15 +02:00
{
2025-08-07 19:31:52 -04:00
return realm . create < DOMException > ( realm , move ( name ) , 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 ) ;
}
2025-08-07 19:31:52 -04:00
GC : : Ref < DOMException > DOMException : : construct_impl ( JS : : Realm & realm , Utf16String const & message , FlyString name )
2022-09-04 16:56:15 +02:00
{
2025-08-07 19:31:52 -04:00
return realm . create < DOMException > ( realm , move ( name ) , message ) ;
2022-09-04 16:56:15 +02:00
}
2025-08-07 19:31:52 -04:00
DOMException : : DOMException ( JS : : Realm & realm , FlyString name , Utf16String const & message )
2022-09-25 16:15:49 -06:00
: PlatformObject ( realm )
2024-10-12 20:56:21 +02:00
, m_name ( move ( name ) )
2025-08-07 19:31:52 -04:00
, m_message ( 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
}
2025-07-17 09:51:04 -04:00
WebIDL : : ExceptionOr < void > DOMException : : serialization_steps ( HTML : : TransferDataEncoder & serialized , bool , HTML : : SerializationMemory & )
2024-11-22 12:17:18 +01:00
{
// 1. Set serialized.[[Name]] to value’ s name.
2025-07-17 09:51:04 -04:00
serialized . encode ( m_name . to_string ( ) ) ;
2024-11-22 12:17:18 +01:00
// 2. Set serialized.[[Message]] to value’ s message.
2025-08-07 19:31:52 -04:00
serialized . encode ( m_message . to_utf16_string ( ) ) ;
2024-11-22 12:17:18 +01:00
// 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 { } ;
}
2025-07-17 09:51:04 -04:00
WebIDL : : ExceptionOr < void > DOMException : : deserialization_steps ( HTML : : TransferDataDecoder & serialized , HTML : : DeserializationMemory & )
2024-11-22 12:17:18 +01:00
{
// 1. Set value’ s name to serialized.[[Name]].
2025-07-17 09:51:04 -04:00
m_name = serialized . decode < String > ( ) ;
2024-11-22 12:17:18 +01:00
// 2. Set value’ s message to serialized.[[Message]].
2025-08-07 19:31:52 -04:00
m_message = serialized . decode < Utf16String > ( ) ;
2024-11-22 12:17:18 +01:00
// 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
}