dymokomi/luce-browser-engine
Source of release 0.6.1
0.6.1 / src / web / web_idl / dom_exception.lucb
#==============================================================================================
#
# dom_exception - WebIDL::DOMException and the named DOMException factories
#
# DESCRIPTION:
# Port of Libraries/LibWeb/WebIDL/DOMException.cpp (lines 1-85) and DOMException.h
# (lines 1-167): the platform object every WebIDL operation throws, its legacy codes, the
# 31 ErrorName::create factories (`WebIDL::HierarchyRequestError::create(realm, message)`),
# the conversion to a JS throw completion and the AK formatter. The JS::ErrorData base (the
# captured JS stack) and structured serialization are phase 3 and later.
#
# Copyright (c) 2022, Andreas Kling <andreas@ladybird.org>
# SPDX-License-Identifier: BSD-2-Clause
#
#==============================================================================================
# mark: Legacy codes ============================================================================
## Ported from Libraries/LibWeb/WebIDL/DOMException.h:85 Web::WebIDL::get_legacy_code_for_name
## (ENUMERATE_DOM_EXCEPTION_LEGACY_CODES). The following have a legacy code value but *don't*
## produce it as DOMException.code value when used as name (and are therefore omitted here):
## DOMStringSizeError (DOMSTRING_SIZE_ERR = 2), NoDataAllowedError (NO_DATA_ALLOWED_ERR = 6),
## ValidationError (VALIDATION_ERR = 16).
func idl_get_legacy_code_for_name(name: ak.FlyString) -> u16:
if ak.fly_string_eq_string_view(&name, ak.sv("IndexSizeError")):
return 1
if ak.fly_string_eq_string_view(&name, ak.sv("HierarchyRequestError")):
return 3
if ak.fly_string_eq_string_view(&name, ak.sv("WrongDocumentError")):
return 4
if ak.fly_string_eq_string_view(&name, ak.sv("InvalidCharacterError")):
return 5
if ak.fly_string_eq_string_view(&name, ak.sv("NoModificationAllowedError")):
return 7
if ak.fly_string_eq_string_view(&name, ak.sv("NotFoundError")):
return 8
if ak.fly_string_eq_string_view(&name, ak.sv("NotSupportedError")):
return 9
if ak.fly_string_eq_string_view(&name, ak.sv("InUseAttributeError")):
return 10
if ak.fly_string_eq_string_view(&name, ak.sv("InvalidStateError")):
return 11
if ak.fly_string_eq_string_view(&name, ak.sv("SyntaxError")):
return 12
if ak.fly_string_eq_string_view(&name, ak.sv("InvalidModificationError")):
return 13
if ak.fly_string_eq_string_view(&name, ak.sv("NamespaceError")):
return 14
if ak.fly_string_eq_string_view(&name, ak.sv("InvalidAccessError")):
return 15
if ak.fly_string_eq_string_view(&name, ak.sv("TypeMismatchError")):
return 17
if ak.fly_string_eq_string_view(&name, ak.sv("SecurityError")):
return 18
if ak.fly_string_eq_string_view(&name, ak.sv("NetworkError")):
return 19
if ak.fly_string_eq_string_view(&name, ak.sv("AbortError")):
return 20
if ak.fly_string_eq_string_view(&name, ak.sv("URLMismatchError")):
return 21
if ak.fly_string_eq_string_view(&name, ak.sv("QuotaExceededError")):
return 22
if ak.fly_string_eq_string_view(&name, ak.sv("TimeoutError")):
return 23
if ak.fly_string_eq_string_view(&name, ak.sv("InvalidNodeTypeError")):
return 24
if ak.fly_string_eq_string_view(&name, ak.sv("DataCloneError")):
return 25
return 0
# mark: DOMException ============================================================================
## Ported from Libraries/LibWeb/WebIDL/DOMException.cpp:16 Web::WebIDL::DOMException::create.
pub func idl_dom_exception_create_fly_string(realm: Realm*, name: ak.FlyString, message: ak.Utf16String) -> IdlDomException*:
return realm_create_idl_dom_exception_fly_string(realm, realm, name, message)
## Ported from Libraries/LibWeb/WebIDL/DOMException.cpp:21 Web::WebIDL::DOMException::create.
pub func idl_dom_exception_create(realm: Realm*) -> IdlDomException*:
return realm_create_idl_dom_exception(realm, realm)
## Ported from Libraries/LibWeb/WebIDL/DOMException.cpp:26 Web::WebIDL::DOMException::construct_impl.
## JS constructor has message first, name second.
## FIXME: This is a completely pointless footgun, let's use the same order for both factories.
pub func idl_dom_exception_construct_impl(realm: Realm*, message: ak.Utf16String, name: ak.FlyString) -> IdlDomException*:
return realm_create_idl_dom_exception_fly_string(realm, realm, name, message)
## Ported from Libraries/LibWeb/WebIDL/DOMException.cpp:31 Web::WebIDL::DOMException::DOMException.
pub func idl_dom_exception_construct_fly_string(this: IdlDomException*, realm: Realm*, name: ak.FlyString, message: ak.Utf16String):
idl_dom_exception_construct(this, realm)
this.m_name = name
this.m_message = ak.utf16_fly_string_from_utf16_string(message)
## Ported from Libraries/LibWeb/WebIDL/DOMException.cpp:39 Web::WebIDL::DOMException::DOMException.
## The JS::ErrorData base, constructed from realm.vm(), captures the JS stack (phase 3).
pub func idl_dom_exception_construct(this: IdlDomException*, realm: Realm*):
bind_platform_object_construct_realm(this.bind_platform_object(), realm)
# The vptr of the Bindings::Serializable base.
this.serializable.vtable = &idl_dom_exception_serializable_vtable
## Ported from Libraries/LibWeb/WebIDL/DOMException.cpp:47 Web::WebIDL::DOMException::initialize (override).
pub func idl_dom_exception_initialize_impl(base: JsCell*, realm: Realm*):
web_set_prototype_for_interface(base, realm, BindInterfaceName.dom_exception)
# Base::initialize(realm): PlatformObject inherits JS::Object's.
js_cell_initialize_impl(base, realm)
## Ported from Libraries/LibWeb/WebIDL/DOMException.cpp:53 Web::WebIDL::DOMException::visit_edges (override).
pub func idl_dom_exception_visit_edges_impl(base: gc.Cell*, visitor: gc.CellVisitor*):
bind_platform_object_visit_edges_impl(base, visitor)
# ErrorData::visit_edges(visitor): the captured stack's cells (phase 3).
## Ported from Libraries/LibWeb/WebIDL/DOMException.cpp:59 Web::WebIDL::DOMException::serialization_steps (override).
pub func idl_dom_exception_serialization_steps_impl(base: BindSerializable*, serialized: HtmlTransferDataEncoder*, for_storage: bool, arg2: ak.HashMap[JsValue*?, u32, ak.PtrTraits[JsValue]]*) -> !:
# 1. Set serialized.[[Name]] to value’s name.
# 2. Set serialized.[[Message]] to value’s message.
# 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.
trap("unported (P3): Web::WebIDL::DOMException::serialization_steps (HTML::TransferDataEncoder)")
## Ported from Libraries/LibWeb/WebIDL/DOMException.cpp:72 Web::WebIDL::DOMException::deserialization_steps (override).
pub func idl_dom_exception_deserialization_steps_impl(base: BindSerializable*, serialized: HtmlTransferDataDecoder*, arg1: ak.Vector[JsValue]*) -> !:
# 1. Set value’s name to serialized.[[Name]].
# 2. Set value’s message to serialized.[[Message]].
# FIXME: 3. If any other data is attached to serialized, then deserialize and attach it to value.
trap("unported (P3): Web::WebIDL::DOMException::deserialization_steps (HTML::TransferDataDecoder)")
## Ported from Libraries/LibWeb/WebIDL/DOMException.h:113 Web::WebIDL::DOMException::name.
pub func idl_dom_exception_name(this: IdlDomException*) -> ak.FlyString:
return this.m_name
## Ported from Libraries/LibWeb/WebIDL/DOMException.h:114 Web::WebIDL::DOMException::message.
pub func idl_dom_exception_message(this: IdlDomException*) -> ak.Utf16FlyString:
return this.m_message
## Ported from Libraries/LibWeb/WebIDL/DOMException.h:115 Web::WebIDL::DOMException::code.
pub func idl_dom_exception_code(this: IdlDomException*) -> u16:
return idl_get_legacy_code_for_name(this.m_name)
## Ported from Libraries/LibWeb/WebIDL/DOMException.h:128 Web::WebIDL::DOMException::error_data (virtual).
pub func idl_dom_exception_error_data_impl(this: IdlDomException*) -> JsErrorData*?:
trap("unported (P3): Web::WebIDL::DOMException::error_data (the JS::ErrorData base)")
## Ported from Libraries/LibWeb/WebIDL/DOMException.h:129 Web::WebIDL::DOMException::error_data (virtual).
pub func idl_dom_exception_error_data_const_impl(this: IdlDomException*) -> const JsErrorData*?:
trap("unported (P3): Web::WebIDL::DOMException::error_data (the JS::ErrorData base)")
## WEB_PLATFORM_OBJECT(DOMException, Bindings::PlatformObject)'s interface_name (override).
pub func idl_dom_exception_interface_name_impl(this: BindPlatformObject*) -> BindInterfaceName:
return BindInterfaceName.dom_exception
## WEB_PLATFORM_OBJECT(DOMException, Bindings::PlatformObject)'s implements_interface (override).
pub func idl_dom_exception_implements_interface_impl(this: BindPlatformObject*, interface_: ak.String) -> bool:
if ak.string_eq_string_view(&interface_, ak.sv("DOMException")):
return true
return bind_platform_object_implements_interface_impl(this, interface_)
# mark: The named DOMExceptions =================================================================
## Ported from Libraries/LibWeb/WebIDL/DOMException.h:143 Web::WebIDL::IndexSizeError::create
## (ENUMERATE_DOM_EXCEPTION_ERROR_NAMES: `DOMException::create(realm, #ErrorName##_fly_string,
## message)` for each name, in the spec's order). Deprecated.
pub func idl_index_size_error_create(realm: Realm*, message: ak.Utf16String) -> IdlDomException*:
return idl_dom_exception_create_fly_string(realm, ak.fly_string_from_str("IndexSizeError"), message)
## Ported from Libraries/LibWeb/WebIDL/DOMException.h:143 Web::WebIDL::HierarchyRequestError::create.
pub func idl_hierarchy_request_error_create(realm: Realm*, message: ak.Utf16String) -> IdlDomException*:
return idl_dom_exception_create_fly_string(realm, ak.fly_string_from_str("HierarchyRequestError"), message)
## Ported from Libraries/LibWeb/WebIDL/DOMException.h:143 Web::WebIDL::WrongDocumentError::create.
pub func idl_wrong_document_error_create(realm: Realm*, message: ak.Utf16String) -> IdlDomException*:
return idl_dom_exception_create_fly_string(realm, ak.fly_string_from_str("WrongDocumentError"), message)
## Ported from Libraries/LibWeb/WebIDL/DOMException.h:143 Web::WebIDL::InvalidCharacterError::create.
pub func idl_invalid_character_error_create(realm: Realm*, message: ak.Utf16String) -> IdlDomException*:
return idl_dom_exception_create_fly_string(realm, ak.fly_string_from_str("InvalidCharacterError"), message)
## Ported from Libraries/LibWeb/WebIDL/DOMException.h:143 Web::WebIDL::NoModificationAllowedError::create.
pub func idl_no_modification_allowed_error_create(realm: Realm*, message: ak.Utf16String) -> IdlDomException*:
return idl_dom_exception_create_fly_string(realm, ak.fly_string_from_str("NoModificationAllowedError"), message)
## Ported from Libraries/LibWeb/WebIDL/DOMException.h:143 Web::WebIDL::NotFoundError::create.
pub func idl_not_found_error_create(realm: Realm*, message: ak.Utf16String) -> IdlDomException*:
return idl_dom_exception_create_fly_string(realm, ak.fly_string_from_str("NotFoundError"), message)
## Ported from Libraries/LibWeb/WebIDL/DOMException.h:143 Web::WebIDL::NotSupportedError::create.
pub func idl_not_supported_error_create(realm: Realm*, message: ak.Utf16String) -> IdlDomException*:
return idl_dom_exception_create_fly_string(realm, ak.fly_string_from_str("NotSupportedError"), message)
## Ported from Libraries/LibWeb/WebIDL/DOMException.h:143 Web::WebIDL::InUseAttributeError::create.
pub func idl_in_use_attribute_error_create(realm: Realm*, message: ak.Utf16String) -> IdlDomException*:
return idl_dom_exception_create_fly_string(realm, ak.fly_string_from_str("InUseAttributeError"), message)
## Ported from Libraries/LibWeb/WebIDL/DOMException.h:143 Web::WebIDL::InvalidStateError::create.
pub func idl_invalid_state_error_create(realm: Realm*, message: ak.Utf16String) -> IdlDomException*:
return idl_dom_exception_create_fly_string(realm, ak.fly_string_from_str("InvalidStateError"), message)
## Ported from Libraries/LibWeb/WebIDL/DOMException.h:143 Web::WebIDL::SyntaxError::create.
pub func idl_syntax_error_create(realm: Realm*, message: ak.Utf16String) -> IdlDomException*:
return idl_dom_exception_create_fly_string(realm, ak.fly_string_from_str("SyntaxError"), message)
## Ported from Libraries/LibWeb/WebIDL/DOMException.h:143 Web::WebIDL::InvalidModificationError::create.
pub func idl_invalid_modification_error_create(realm: Realm*, message: ak.Utf16String) -> IdlDomException*:
return idl_dom_exception_create_fly_string(realm, ak.fly_string_from_str("InvalidModificationError"), message)
## Ported from Libraries/LibWeb/WebIDL/DOMException.h:143 Web::WebIDL::NamespaceError::create.
pub func idl_namespace_error_create(realm: Realm*, message: ak.Utf16String) -> IdlDomException*:
return idl_dom_exception_create_fly_string(realm, ak.fly_string_from_str("NamespaceError"), message)
## Ported from Libraries/LibWeb/WebIDL/DOMException.h:143 Web::WebIDL::InvalidAccessError::create. Deprecated.
pub func idl_invalid_access_error_create(realm: Realm*, message: ak.Utf16String) -> IdlDomException*:
return idl_dom_exception_create_fly_string(realm, ak.fly_string_from_str("InvalidAccessError"), message)
## Ported from Libraries/LibWeb/WebIDL/DOMException.h:143 Web::WebIDL::TypeMismatchError::create. Deprecated.
pub func idl_type_mismatch_error_create(realm: Realm*, message: ak.Utf16String) -> IdlDomException*:
return idl_dom_exception_create_fly_string(realm, ak.fly_string_from_str("TypeMismatchError"), message)
## Ported from Libraries/LibWeb/WebIDL/DOMException.h:143 Web::WebIDL::SecurityError::create.
pub func idl_security_error_create(realm: Realm*, message: ak.Utf16String) -> IdlDomException*:
return idl_dom_exception_create_fly_string(realm, ak.fly_string_from_str("SecurityError"), message)
## Ported from Libraries/LibWeb/WebIDL/DOMException.h:143 Web::WebIDL::NetworkError::create.
pub func idl_network_error_create(realm: Realm*, message: ak.Utf16String) -> IdlDomException*:
return idl_dom_exception_create_fly_string(realm, ak.fly_string_from_str("NetworkError"), message)
## Ported from Libraries/LibWeb/WebIDL/DOMException.h:143 Web::WebIDL::AbortError::create.
pub func idl_abort_error_create(realm: Realm*, message: ak.Utf16String) -> IdlDomException*:
return idl_dom_exception_create_fly_string(realm, ak.fly_string_from_str("AbortError"), message)
## Ported from Libraries/LibWeb/WebIDL/DOMException.h:143 Web::WebIDL::URLMismatchError::create.
pub func idl_url_mismatch_error_create(realm: Realm*, message: ak.Utf16String) -> IdlDomException*:
return idl_dom_exception_create_fly_string(realm, ak.fly_string_from_str("URLMismatchError"), message)
## Ported from Libraries/LibWeb/WebIDL/DOMException.h:143 Web::WebIDL::TimeoutError::create.
pub func idl_timeout_error_create(realm: Realm*, message: ak.Utf16String) -> IdlDomException*:
return idl_dom_exception_create_fly_string(realm, ak.fly_string_from_str("TimeoutError"), message)
## Ported from Libraries/LibWeb/WebIDL/DOMException.h:143 Web::WebIDL::InvalidNodeTypeError::create.
pub func idl_invalid_node_type_error_create(realm: Realm*, message: ak.Utf16String) -> IdlDomException*:
return idl_dom_exception_create_fly_string(realm, ak.fly_string_from_str("InvalidNodeTypeError"), message)
## Ported from Libraries/LibWeb/WebIDL/DOMException.h:143 Web::WebIDL::DataCloneError::create.
pub func idl_data_clone_error_create(realm: Realm*, message: ak.Utf16String) -> IdlDomException*:
return idl_dom_exception_create_fly_string(realm, ak.fly_string_from_str("DataCloneError"), message)
## Ported from Libraries/LibWeb/WebIDL/DOMException.h:143 Web::WebIDL::EncodingError::create.
pub func idl_encoding_error_create(realm: Realm*, message: ak.Utf16String) -> IdlDomException*:
return idl_dom_exception_create_fly_string(realm, ak.fly_string_from_str("EncodingError"), message)
## Ported from Libraries/LibWeb/WebIDL/DOMException.h:143 Web::WebIDL::NotReadableError::create.
pub func idl_not_readable_error_create(realm: Realm*, message: ak.Utf16String) -> IdlDomException*:
return idl_dom_exception_create_fly_string(realm, ak.fly_string_from_str("NotReadableError"), message)
## Ported from Libraries/LibWeb/WebIDL/DOMException.h:143 Web::WebIDL::UnknownError::create.
pub func idl_unknown_error_create(realm: Realm*, message: ak.Utf16String) -> IdlDomException*:
return idl_dom_exception_create_fly_string(realm, ak.fly_string_from_str("UnknownError"), message)
## Ported from Libraries/LibWeb/WebIDL/DOMException.h:143 Web::WebIDL::ConstraintError::create.
pub func idl_constraint_error_create(realm: Realm*, message: ak.Utf16String) -> IdlDomException*:
return idl_dom_exception_create_fly_string(realm, ak.fly_string_from_str("ConstraintError"), message)
## Ported from Libraries/LibWeb/WebIDL/DOMException.h:143 Web::WebIDL::DataError::create.
pub func idl_data_error_create(realm: Realm*, message: ak.Utf16String) -> IdlDomException*:
return idl_dom_exception_create_fly_string(realm, ak.fly_string_from_str("DataError"), message)
## Ported from Libraries/LibWeb/WebIDL/DOMException.h:143 Web::WebIDL::TransactionInactiveError::create.
pub func idl_transaction_inactive_error_create(realm: Realm*, message: ak.Utf16String) -> IdlDomException*:
return idl_dom_exception_create_fly_string(realm, ak.fly_string_from_str("TransactionInactiveError"), message)
## Ported from Libraries/LibWeb/WebIDL/DOMException.h:143 Web::WebIDL::ReadOnlyError::create.
pub func idl_read_only_error_create(realm: Realm*, message: ak.Utf16String) -> IdlDomException*:
return idl_dom_exception_create_fly_string(realm, ak.fly_string_from_str("ReadOnlyError"), message)
## Ported from Libraries/LibWeb/WebIDL/DOMException.h:143 Web::WebIDL::VersionError::create.
pub func idl_version_error_create(realm: Realm*, message: ak.Utf16String) -> IdlDomException*:
return idl_dom_exception_create_fly_string(realm, ak.fly_string_from_str("VersionError"), message)
## Ported from Libraries/LibWeb/WebIDL/DOMException.h:143 Web::WebIDL::OperationError::create.
pub func idl_operation_error_create(realm: Realm*, message: ak.Utf16String) -> IdlDomException*:
return idl_dom_exception_create_fly_string(realm, ak.fly_string_from_str("OperationError"), message)
## Ported from Libraries/LibWeb/WebIDL/DOMException.h:143 Web::WebIDL::NotAllowedError::create.
pub func idl_not_allowed_error_create(realm: Realm*, message: ak.Utf16String) -> IdlDomException*:
return idl_dom_exception_create_fly_string(realm, ak.fly_string_from_str("NotAllowedError"), message)
# mark: Throw completion and formatter ==========================================================
## Ported from Libraries/LibWeb/WebIDL/DOMException.h:150 Web::throw_completion:
## `JS::throw_completion(JS::Value(exception))` (region r19 gave JS::Completion and the object
## values their phase-1 form).
pub func throw_completion(exception: IdlDomException*) -> JsCompletion:
return js_throw_completion(js_value_from_object((JsObject*)exception))
## Ported from Libraries/LibWeb/WebIDL/DOMException.h:161 AK::Formatter<WebIDL::DOMException>::format:
## "[{name}]: {message}".
pub func idl_dom_exception_to_string(exception: IdlDomException*) -> ak.String:
var builder = ak.string_builder_new()
ak.string_builder_append(&builder, "[")
ak.string_builder_append_string_view(&builder, ak.fly_string_bytes_as_string_view(&exception.m_name))
ak.string_builder_append(&builder, "]: ")
ak.string_builder_append_utf16_view(&builder, ak.utf16_fly_string_view(&exception.m_message))
return ak.string_builder_to_string(&builder) else trap("MUST: StringBuilder::to_string")