Luce packages
LuceLuce BaseLuciaOS

dymokomi/luce-browser-engine

Source of release 0.6.1

0.6.1 / src / web / web_idl / quota_exceeded_error.lucb

#==============================================================================================
#
#   quota_exceeded_error - WebIDL::QuotaExceededError: the DOMException with quota and requested
#
#   DESCRIPTION:
#       Port of Libraries/LibWeb/WebIDL/QuotaExceededError.cpp (lines 1-109) and
#       QuotaExceededError.h (lines 1-53). Structured serialization is phase 3 and later.
#
#       Copyright (c) 2025, Shannon Booth <shannon@serenityos.org>
#       SPDX-License-Identifier: BSD-2-Clause
#
#==============================================================================================

## Ported from Libraries/LibWeb/WebIDL/QuotaExceededError.cpp:16 Web::WebIDL::QuotaExceededError::QuotaExceededError.
pub func idl_quota_exceeded_error_construct(this: IdlQuotaExceededError*, realm: Realm*):
    idl_dom_exception_construct(this.idl_dom_exception(), realm)
    this.dom_exception.serializable.vtable = &idl_quota_exceeded_error_serializable_vtable

## Ported from Libraries/LibWeb/WebIDL/QuotaExceededError.cpp:21 Web::WebIDL::QuotaExceededError::QuotaExceededError.
pub func idl_quota_exceeded_error_construct_utf16_string(this: IdlQuotaExceededError*, realm: Realm*, message: ak.Utf16String):
    idl_dom_exception_construct_fly_string(this.idl_dom_exception(), realm, ak.fly_string_from_str("QuotaExceededError"), message)
    this.dom_exception.serializable.vtable = &idl_quota_exceeded_error_serializable_vtable

## Ported from Libraries/LibWeb/WebIDL/QuotaExceededError.cpp:26 Web::WebIDL::QuotaExceededError::initialize (override).
pub func idl_quota_exceeded_error_initialize_impl(base: JsCell*, realm: Realm*):
    web_set_prototype_for_interface(base, realm, BindInterfaceName.quota_exceeded_error)
    idl_dom_exception_initialize_impl(base, realm)

## Ported from Libraries/LibWeb/WebIDL/QuotaExceededError.cpp:32 Web::WebIDL::QuotaExceededError::create.
pub func idl_quota_exceeded_error_create(realm: Realm*) -> IdlQuotaExceededError*:
    return realm_create_idl_quota_exceeded_error(realm, realm)

## Ported from Libraries/LibWeb/WebIDL/QuotaExceededError.cpp:37 Web::WebIDL::QuotaExceededError::create.
pub func idl_quota_exceeded_error_create_utf16_string(realm: Realm*, message: ak.Utf16String) -> IdlQuotaExceededError*:
    return realm_create_idl_quota_exceeded_error_utf16_string(realm, realm, message)

## Ported from Libraries/LibWeb/WebIDL/QuotaExceededError.cpp:43 Web::WebIDL::QuotaExceededError::construct_impl.
## https://webidl.spec.whatwg.org/#dom-quotaexceedederror-quotaexceedederror
pub func idl_quota_exceeded_error_construct_impl(realm: Realm*, message: ak.Utf16String, options: IdlQuotaExceededErrorOptions) -> IdlQuotaExceededError*!:
    let vm = realm_vm(realm)

    # 1. Set this’s name to "QuotaExceededError".
    # 2. Set this’s message to message.
    # NB: Done in constructor.
    let error_ = realm_create_idl_quota_exceeded_error_utf16_string(realm, realm, message)

    # 3. If options["quota"] is present:
    if let quota = options.quota:
        # 1. If options["quota"] is less than 0, then throw a RangeError.
        if quota < 0.0:
            return try vm_throw_completion(vm, IdlSimpleExceptionType.range_error, .string_view(ak.sv("Quota cannot be less than 0")))

        # 2. Set this’s quota to options["quota"].
        error_.m_quota = options.quota

    # 4. If options["requested"] is present:
    if let requested = options.requested:
        # 1. If options["requested"] is less than 0, then throw a RangeError.
        if requested < 0.0:
            return try vm_throw_completion(vm, IdlSimpleExceptionType.range_error, .string_view(ak.sv("Requested cannot be less than 0")))

        # 2. Set this’s requested to options["requested"].
        error_.m_requested = options.requested

    # 5. If this’s quota is not null, this’s requested is not null, and this’s requested is less than this’s quota, then throw a RangeError.
    if let quota = error_.m_quota:
        if let requested = error_.m_requested:
            if requested < quota:
                return try vm_throw_completion(vm, IdlSimpleExceptionType.range_error, .string_view(ak.sv("Requested cannot be less than quota")))

    return error_

## Ported from Libraries/LibWeb/WebIDL/QuotaExceededError.cpp:80 Web::WebIDL::QuotaExceededError::serialization_steps (override).
## https://webidl.spec.whatwg.org/#ref-for-quotaexceedederror⑦
pub func idl_quota_exceeded_error_serialization_steps_impl(base: BindSerializable*, serialized: HtmlTransferDataEncoder*, for_storage: bool, memory_: ak.HashMap[JsValue*?, u32, ak.PtrTraits[JsValue]]*) -> !:
    # 1. Run the DOMException serialization steps given value and serialized.
    # 2. Set serialized.[[Quota]] to value’s quota.
    # 3. Set serialized.[[Requested]] to value’s requested.
    trap("unported (P3): Web::WebIDL::QuotaExceededError::serialization_steps (HTML::TransferDataEncoder)")

## Ported from Libraries/LibWeb/WebIDL/QuotaExceededError.cpp:95 Web::WebIDL::QuotaExceededError::deserialization_steps (override).
## https://webidl.spec.whatwg.org/#ref-for-quotaexceedederror⑦
pub func idl_quota_exceeded_error_deserialization_steps_impl(base: BindSerializable*, serialized: HtmlTransferDataDecoder*, memory_: ak.Vector[JsValue]*) -> !:
    # 1. Run the DOMException deserialization steps given serialized and value.
    # 2. Set value’s quota to serialized.[[Quota]].
    # 3. Set value’s requested to serialized.[[Requested]].
    trap("unported (P3): Web::WebIDL::QuotaExceededError::deserialization_steps (HTML::TransferDataDecoder)")

## Ported from Libraries/LibWeb/WebIDL/QuotaExceededError.h:34 Web::WebIDL::QuotaExceededError::quota.
## https://webidl.spec.whatwg.org/#dom-quotaexceedederror-quota
pub func idl_quota_exceeded_error_quota(this: IdlQuotaExceededError*) -> f64?:
    return this.m_quota

## Ported from Libraries/LibWeb/WebIDL/QuotaExceededError.h:37 Web::WebIDL::QuotaExceededError::requested.
## https://webidl.spec.whatwg.org/#dom-quotaexceedederror-quota
pub func idl_quota_exceeded_error_requested(this: IdlQuotaExceededError*) -> f64?:
    return this.m_requested

## WEB_PLATFORM_OBJECT(QuotaExceededError, DOMException)'s interface_name (override).
pub func idl_quota_exceeded_error_interface_name_impl(this: BindPlatformObject*) -> BindInterfaceName:
    return BindInterfaceName.quota_exceeded_error

## WEB_PLATFORM_OBJECT(QuotaExceededError, DOMException)'s implements_interface (override).
pub func idl_quota_exceeded_error_implements_interface_impl(this: BindPlatformObject*, interface_: ak.String) -> bool:
    if ak.string_eq_string_view(&interface_, ak.sv("QuotaExceededError")):
        return true
    return idl_dom_exception_implements_interface_impl(this, interface_)