2022-09-04 11:56:15 -03:00
/*
2024-10-04 08:19:50 -03:00
* Copyright ( c ) 2022 , Andreas Kling < andreas @ ladybird . org >
2022-09-04 11:56:15 -03:00
*
* SPDX - License - Identifier : BSD - 2 - Clause
*/
2026-04-18 05:54:06 -03:00
# include <LibWeb/Bindings/DOMException.h>
2022-09-25 19:15:49 -03:00
# include <LibWeb/Bindings/Intrinsics.h>
2024-11-22 08:17:18 -03:00
# include <LibWeb/HTML/StructuredSerialize.h>
2022-09-25 13:28:46 -03:00
# include <LibWeb/WebIDL/DOMException.h>
2022-09-04 11:56:15 -03:00
2022-09-25 13:28:46 -03:00
namespace Web : : WebIDL {
2022-09-04 11:56:15 -03:00
2024-11-14 12:01:23 -03:00
GC_DEFINE_ALLOCATOR ( DOMException ) ;
2023-11-19 15:47:52 -03:00
2025-08-07 20:31:52 -03:00
GC : : Ref < DOMException > DOMException : : create ( JS : : Realm & realm , FlyString name , Utf16String const & message )
2022-09-04 11:56:15 -03:00
{
2025-08-07 20:31:52 -03:00
return realm . create < DOMException > ( realm , move ( name ) , message ) ;
2022-09-04 11:56:15 -03:00
}
2024-11-22 08:17:18 -03:00
GC : : Ref < DOMException > DOMException : : create ( JS : : Realm & realm )
{
return realm . create < DOMException > ( realm ) ;
}
2025-08-07 20:31:52 -03:00
GC : : Ref < DOMException > DOMException : : construct_impl ( JS : : Realm & realm , Utf16String const & message , FlyString name )
2022-09-04 11:56:15 -03:00
{
2025-08-07 20:31:52 -03:00
return realm . create < DOMException > ( realm , move ( name ) , message ) ;
2022-09-04 11:56:15 -03:00
}
2025-08-07 20:31:52 -03:00
DOMException : : DOMException ( JS : : Realm & realm , FlyString name , Utf16String const & message )
2022-09-25 19:15:49 -03:00
: PlatformObject ( realm )
2026-04-04 10:39:01 -03:00
, ErrorData ( realm . vm ( ) )
2024-10-12 15:56:21 -03:00
, m_name ( move ( name ) )
2025-08-07 20:31:52 -03:00
, m_message ( message )
2022-09-04 11:56:15 -03:00
{
}
2024-11-22 08:17:18 -03:00
DOMException : : DOMException ( JS : : Realm & realm )
: PlatformObject ( realm )
2026-04-04 10:39:01 -03:00
, ErrorData ( realm . vm ( ) )
2024-11-22 08:17:18 -03:00
{
}
2022-09-04 11:56:15 -03:00
DOMException : : ~ DOMException ( ) = default ;
2023-08-07 03:41:28 -03:00
void DOMException : : initialize ( JS : : Realm & realm )
2023-01-10 08:28:20 -03:00
{
2024-03-16 09:13:08 -03:00
WEB_SET_PROTOTYPE_FOR_INTERFACE ( DOMException ) ;
2025-04-20 11:22:57 -03:00
Base : : initialize ( realm ) ;
2023-01-10 08:28:20 -03:00
}
2026-04-04 10:39:01 -03:00
void DOMException : : visit_edges ( Visitor & visitor )
{
Base : : visit_edges ( visitor ) ;
ErrorData : : visit_edges ( visitor ) ;
}
2025-07-17 10:51:04 -03:00
WebIDL : : ExceptionOr < void > DOMException : : serialization_steps ( HTML : : TransferDataEncoder & serialized , bool , HTML : : SerializationMemory & )
2024-11-22 08:17:18 -03:00
{
// 1. Set serialized.[[Name]] to value’ s name.
2025-07-17 10:51:04 -03:00
serialized . encode ( m_name . to_string ( ) ) ;
2024-11-22 08:17:18 -03:00
// 2. Set serialized.[[Message]] to value’ s message.
2025-08-07 20:31:52 -03:00
serialized . encode ( m_message . to_utf16_string ( ) ) ;
2024-11-22 08:17:18 -03: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 10:51:04 -03:00
WebIDL : : ExceptionOr < void > DOMException : : deserialization_steps ( HTML : : TransferDataDecoder & serialized , HTML : : DeserializationMemory & )
2024-11-22 08:17:18 -03:00
{
// 1. Set value’ s name to serialized.[[Name]].
2025-07-17 10:51:04 -03:00
m_name = serialized . decode < String > ( ) ;
2024-11-22 08:17:18 -03:00
// 2. Set value’ s message to serialized.[[Message]].
2025-08-07 20:31:52 -03:00
m_message = serialized . decode < Utf16String > ( ) ;
2024-11-22 08:17:18 -03:00
// FIXME: 3. If any other data is attached to serialized, then deserialize and attach it to value.
return { } ;
}
2022-09-04 11:56:15 -03:00
}