
    \jC                        S SK Jr  S SKJr  S SKJr  S SKJr  S SKJr  S SKJ	r	  S SKJ
r
  S SKJr  S S	KJr  S S
KJr  S SKJr  S SKJr  S\S\4S jrS\S\S\SS4S jrS\S\S\SS4S jrS\S\S\SS4S jrS\S\S\SS4S jrS\S\S\SS4S jrS\S\S\SS4S jrS\S\S\S\SS4
S jrS\S\S\S\SS4
S jrS\S\S\S\SS4
S jrS\S\S\S\SS4
S jrS\S\S\S\S\SS4S jr g)     )TextIO)%write_operation_parameter_conversions)GenerationContext)"fully_qualified_name_for_interfaceidl_identifier_cpp_name)idl_implementation_cpp_name)#implementation_header_for_interface)wrap_with_ce_reactions)GeneratedIncludes)to_javascript_value)	Interface)SpecialOperation	interfacereturnc                 J    U R                   S L=(       a    SU R                  ;   $ )NGlobal)named_property_getterextended_attributes)r   s    j/mnt/mint/home/seanl/public/Repos/ladybird/Meta/Generators/libweb_bindings/named_and_indexed_properties.py#interface_supports_named_propertiesr      s#    **$6d8yGdGd;dd    outincludesNc                 T   UR                  S5        UR                  S5        UR                  S5        UR                  S5        UR                  S5        U R                  SUR                   SUR                   SUR                   S	UR                   S
UR                   S35        g )NzAK/Optional.hzLibGC/Ptr.hzLibJS/Runtime/Object.h"LibJS/Runtime/PropertyDescriptor.hLibJS/Runtime/PropertyKey.hzclass z/Properties : public JS::Object {
    JS_OBJECT(z2Properties, JS::Object);
    GC_DECLARE_ALLOCATOR(z#Properties);

public:
    explicit zWProperties(JS::Realm&);
    virtual void initialize(JS::Realm&) override;
    virtual ~ar  Properties() override;

    JS::Realm& realm() const { return m_realm; }

private:
    virtual JS::ThrowCompletionOr<Optional<JS::PropertyDescriptor>> internal_get_own_property(JS::PropertyKey const&) const override;
    virtual JS::ThrowCompletionOr<bool> internal_define_own_property(JS::PropertyKey const&, JS::PropertyDescriptor&, Optional<JS::PropertyDescriptor>* precomputed_get_own_property = nullptr) override;
    virtual JS::ThrowCompletionOr<bool> internal_delete(JS::PropertyKey const&) override;
    virtual JS::ThrowCompletionOr<bool> internal_set_prototype_of(JS::Object* prototype) override;
    virtual JS::ThrowCompletionOr<bool> internal_prevent_extensions() override;

    virtual bool eligible_for_own_property_enumeration_fast_path() const override final { return false; }

    virtual void visit_edges(Visitor&) override;

    GC::Ref<JS::Realm> m_realm;
};

)addwritename)r   r   r   s      r   )write_named_properties_object_declarationr!      s    LL!LLLL)*LL56LL./II9>>" #~~ #..) * nn nn 	r   c                    [        U5      (       d  g UR                  S5        UR                  S5        UR                  S5        UR                  S5        UR                  S5        UR                  S5        UR                  [        U5      5        SnUR                  (       a  SUR                   S	UR                   S
3nU R	                  SR                  / SPUR                   PSPUR                   PSPUR                   PSPUR                   PSPUR                   PSPUR                   PSPUR                   PSPU PSPUR                   PSP[        U5       PSPSUR                  ;   a  SOS PSPUR                   PSPUR                   PSPUR                   PSPUR                   PSPUR                   PSP5      5        g ) NzAK/TypeCasts.hzAK/Utf16FlyString.hzLibJS/Runtime/PrimitiveString.hr   r   zLibWeb/Bindings/Intrinsics.hz%realm.intrinsics().object_prototype()z&ensure_web_prototype<zPrototype>(realm, "z"_fly_string) zGC_DEFINE_ALLOCATOR(zProperties);

zProperties::zProperties(JS::Realm& realm)
    : JS::Object(realm, nullptr, MayInterfereWithIndexedPropertyAccess::Yes)
    , m_realm(realm)
{
}

zProperties::~zProperties()
{
}

void aK  Properties::initialize(JS::Realm& realm)
{
    Base::initialize(realm);
    auto& vm = realm.vm();

    // The class string of a named properties object is the concatenation of the interface's identifier and the string "Properties".
    define_direct_property(vm.well_known_symbol_to_string_tag(), JS::PrimitiveString::create(vm, "ay  Properties"_utf16), JS::Attribute::Configurable);

    // 1. Let proto be null.
    // 2. If interface is declared to inherit from another interface, then set proto to the interface prototype object in realm for the inherited interface.
    // 3. Otherwise, set proto to realm.[[Intrinsics]].[[%Object.prototype%]].
    // 10. Set obj.[[Prototype]] to proto.
    set_prototype(z);
}

// https://webidl.spec.whatwg.org/#named-properties-object-getownproperty
JS::ThrowCompletionOr<Optional<JS::PropertyDescriptor>> zProperties::internal_get_own_property(JS::PropertyKey const& property_name) const
{
    auto& realm = this->realm();

    // 1. Let A be the interface for the named properties object O.
    using A = u  ;

    // 2. Let object be O.[[Realm]]'s global object.
    // 3. Assert: object implements A.
    auto& object = as<A>(realm.global_object());

    // 4. If the result of running the named property visibility algorithm with property name P and object object is true, then:
    if (TRY(object.is_named_property_exposed_on_object(property_name))) {
        auto property_name_utf16 = Utf16FlyString { property_name.to_utf16_string() };

        // 1. Let operation be the operation used to declare the named property getter.
        // 2. Let value be an uninitialized variable.
        // 3. If operation was defined without an identifier, then set value to the result of performing the steps listed in the interface description to determine the value of a named property with P as the name.
        // 4. Otherwise, operation was defined with an identifier. Set value to the result of performing the method steps of operation with « P » as the only argument value.
        auto value = object.named_item_value(property_name_utf16);

        // 5. Let desc be a newly created Property Descriptor with no fields.
        JS::PropertyDescriptor descriptor;

        // 6. Set desc.[[Value]] to the result of converting value to an ECMAScript value.
        descriptor.value = value;

        // 7. If A implements an interface with the [LegacyUnenumerableNamedProperties] extended attribute, then set desc.[[Enumerable]] to false, otherwise set it to true.
        descriptor.enumerable = !LegacyUnenumerableNamedPropertiesfalsetruea  ;

        // 8. Set desc.[[Writable]] to true and desc.[[Configurable]] to true.
        descriptor.writable = true;
        descriptor.configurable = true;

        // 9. Return desc.
        return descriptor;
    }

    // 5. Return OrdinaryGetOwnProperty(O, P).
    return JS::Object::internal_get_own_property(property_name);
}

// https://webidl.spec.whatwg.org/#named-properties-object-defineownproperty
JS::ThrowCompletionOr<bool> a
  Properties::internal_define_own_property(JS::PropertyKey const&, JS::PropertyDescriptor&, Optional<JS::PropertyDescriptor>*)
{
    // 1. Return false.
    return false;
}

// https://webidl.spec.whatwg.org/#named-properties-object-delete
JS::ThrowCompletionOr<bool> zProperties::internal_delete(JS::PropertyKey const&)
{
    // 1. Return false.
    return false;
}

// https://webidl.spec.whatwg.org/#named-properties-object-setprototypeof
JS::ThrowCompletionOr<bool> u  Properties::internal_set_prototype_of(JS::Object* prototype)
{
    // 1. If O’s associated realm’s is global prototype chain mutable is true, return ? OrdinarySetPrototypeOf(O, V).
    // NB: This is only ever true for ShadowRealms.

    // 2. Return ? SetImmutablePrototype(O, V).
    return set_immutable_prototype(prototype);
}

// https://webidl.spec.whatwg.org/#named-properties-object-preventextensions
JS::ThrowCompletionOr<bool> zProperties::internal_prevent_extensions()
{
    // 1. Return false.
    // Note: this keeps named properties object extensible by making [[PreventExtensions]] fail.
    return false;
}

void zkProperties::visit_edges(Visitor& visitor)
{
    Base::visit_edges(visitor);
    visitor.visit(m_realm);
}

)	r   r   r
   parent_namer   joinr    r   r   )r   r   r   parent_prototypes       r   ,write_named_properties_object_implementationr*   =   s   
 /y99LL!"LL&'LL23LL56LL./LL/0LL4Y?@>$Y%:%:$;;NyOdOdNeers 	 IIl	 l	  l	 0 l	 1 l	
 l	l	&^^,l	-l	  l	 l	 (nn-l	.l	 nnl	cl	$ dmcqcqbr%l	$s%l	0 $$1l	0%91l	8 :C8H9l	8I9l	B 2)<=Cl	B>!Cl	p -PS\SpSp,pv| }ql	p~ql	N '^^,Ol	N-Ol	\ '^^,]l	\-]l	j '^^,kl	j
-kl	~ '^^,l	~-l	L nnMl	LMl	nr   c           
      x   UR                   c  g UR                   nUR                  S5        UR                  (       aA  U R                  SUR                   S[	        U5       S[        UR                  5       S35        UR                  bh  UR                  R                  (       aM  UR                  nU R                  SUR                   S[	        U5       S[        UR                  5       S35        U R                  S5        UR                  b*  UR                  R                  c  U R                  S5        g g g )NzLibJS/Runtime/ArrayPrototype.h*    object.define_native_function(realm, ""_utf16_fly_string, , z, default_attributes);
z    object.define_direct_property(vm.well_known_symbol_iterator(), realm.intrinsics().array_prototype()->get_without_side_effects(vm.names.values), JS::Attribute::Configurable | JS::Attribute::Writable);

ae      object.define_direct_property(vm.names.entries, realm.intrinsics().array_prototype()->get_without_side_effects(vm.names.entries), default_attributes);
    object.define_direct_property(vm.names.keys, realm.intrinsics().array_prototype()->get_without_side_effects(vm.names.keys), default_attributes);
    object.define_direct_property(vm.names.values, realm.intrinsics().array_prototype()->get_without_side_effects(vm.names.values), default_attributes);
    object.define_direct_property(vm.names.forEach, realm.intrinsics().array_prototype()->get_without_side_effects(vm.names.forEach), default_attributes);

)
indexed_property_getterr   r    r   r   len
parametersr   iterablekey_type)r   r   r   	operations       r   "define_the_indexed_property_getterr5      s   
 ((011ILL12~~		:9>>:JJ^_v  xA  `B  _C  CE  FI  JS  J^  J^  F_  E` ` 	

 &&2y7V7V7[7[33			:9>>:JJ^_v  xA  `B  _C  CE  FI  JS  J^  J^  F_  E` ` 	

 II	 %)*<*<*E*E*M			
 +N%r   contextc           
          UR                   c  g UR                  b  g UR                   nUR                  (       d  g U R                  SUR                   S[	        U5       S[        UR                  5       S35        g Nr,   r-   r.   z, default_attributes);

)r   r/   r    r   r   r0   r1   r   r6   r   r4   s       r    define_the_named_property_getterr:      s    &&.((4//I>>II6y~~6FFZ[rs|[}Z~  A  BE  FO  FZ  FZ  B[  A\ \ 	r   c           
          UR                   c  g UR                   nUR                  (       d  g U R                  SUR                   S[        U5       S[	        UR
                  5       S35        g r8   )named_property_setterr    r   r   r0   r1   r9   s       r    define_the_named_property_setterr=      s    &&.//I>>II6y~~6FFZ[rs|[}Z~  A  BE  FO  FZ  FZ  B[  A\ \ 	r   c           
          UR                   c  g UR                   nUR                  (       d  g U R                  SUR                   S[        U5       S[	        UR
                  5       S35        g r8   )named_property_deleterr    r   r   r0   r1   r9   s       r   !define_the_named_property_deleterr@     s    ''/00I>>II6y~~6FFZ[rs|[}Z~  A  BE  FO  FZ  FZ  B[  A\ \ 	r   c                 4   UR                   c  g UR                   nUR                  (       d  g [        UR                  5      S:w  a  [	        SUR                   S35      eUR                  S   n[        U5      nU R                  SUR                   S[        U5       SUR                   S[        U5       SUR                   S	35        [        XR                  X!5        U R                  S
[        U5       SU S[        UR                  SX!5       S35        g )N   z.Unsupported indexed property getter arity on ''r   JS_DEFINE_NATIVE_FUNCTION(::)
{
    WebIDL::log_trace(vm, "");
    [[maybe_unused]] auto* idl_object = TRY(impl_from(vm));

    if (vm.argument_count() < 1)
        return vm.throw_completion<JS::TypeError>(JS::ErrorType::BadArgCountOne, "");

N

    auto R = TRY(throw_dom_exception_if_needed(vm, [&] { return idl_object->(); }));
    return R;
}

)r/   r    r0   r1   RuntimeErrorr   r   prototype_classr   r	   r   return_typer   r6   r   r   r4   	parameterparameter_names          r   write_indexed_property_getterrT     sA    ((011I>>
9 A%KINNK[[\]^^$$Q'I,Y7NII&y'@'@&AD[\eDfCg h%556b9PQZ9[8\ ]S T]SaSaRb c	
 *#/C/CXWIINNijsNtMuuv  xF  wG G	 5 5sHNO P	r   c                 4   UR                   c  g UR                   nUR                  (       d  g [        UR                  5      S:w  a  [	        SUR                   S35      eUR                  S   n[        U5      nU R                  SUR                   S[        U5       SUR                   S[        U5       SUR                   S	35        [        XR                  X!5        U R                  S
[        U5       SU S[        UR                  SX!5       S35        g )NrB   z,Unsupported named property getter arity on 'rC   r   rD   rE   rF   rG   rH   rI   rJ   rK   rL   rM   )r   r    r0   r1   rN   r   r   rO   r   r	   r   rP   rQ   s          r   write_named_property_getterrV   D  sA    &&.//I>>
9 A%I)..IYYZ[\\$$Q'I,Y7NII&y'@'@&AD[\eDfCg h%556b9PQZ9[8\ ]S T]SaSaRb c	
 *#/C/CXWIINNijsNtMuuv  xF  wG G	 5 5sHNO P	r   c                 v    UR                   c  g UR                   nUR                  (       d  g [        XX#U5        g N)r<   r    write_named_property_operationr   r6   r   r   r4   s        r   write_named_property_setterr[   n  s4     &&.//I>>"3iPr   c                 v    UR                   c  g UR                   nUR                  (       d  g [        XX#U5        g rX   )r?   r    rY   rZ   s        r   write_named_property_deleterr]   ~  s4     ''/00I>>"3iPr   r4   c                    UR                   (       d  [        SUR                   S35      e[        UR                  SX!5      nSR                  S UR                    5       5      nU R                  SUR                   S[        U5       SUR                   S[        U5       S	3	5        [        UR                   5      S
:X  a   U R                  SUR                   S35        OKU R                  S[        UR                   5       SUR                   S[        UR                   5       S35        [        XR                   X!5        UR                  R                  S:H  nSUR                  ;   a4  [        US5      nU R                  S[        U5       SU SU SU S3	5        g Sn	U(       d  SU S3n	U R                  S[        U5       SU SU	 S35        g )Nz/Unsupported named property operation arity on 'rC   rL   r.   c              3   8   #    U  H  n[        U5      v   M     g 7frX   r   ).0rR   s     r   	<genexpr>1write_named_property_operation.<locals>.<genexpr>  s     cNb1)<<Nbs   rD   rE   rF   z@");
    [[maybe_unused]] auto* idl_object = TRY(impl_from(vm));
rB   zs    if (vm.argument_count() < 1)
        return vm.throw_completion<JS::TypeError>(JS::ErrorType::BadArgCountOne, "rH   z    if (vm.argument_count() < zU)
        return vm.throw_completion<JS::TypeError>(JS::ErrorType::BadArgCountMany, "z", "	undefinedCEReactionszoriginal_steps()zj    auto original_steps = [&] {
        return throw_dom_exception_if_needed(vm, [&] { return idl_object->rJ   z1); });
    };

    [[maybe_unused]] auto R = TRY(z);
    return rM   zreturn JS::js_undefined();zreturn ;z]    [[maybe_unused]] auto R = TRY(throw_dom_exception_if_needed(vm, [&] { return idl_object->z); }));
    z
}

)r1   rN   r    r   rP   r(   r   rO   r   r0   r   r   r   r	   )
r   r6   r   r   r4   return_value	argumentsoperation_returns_undefinedce_reactions_stepsreturn_statements
             r   rY   rY     sL    LY^^L\\]^__&y'<'<c8UL		ciNbNbccIII&y'@'@&AD[\eDfCg h%556b9PQZ9[8\ ]	 9 A%		SS\SaSaRb c	
 			.s93G3G/H.I JTT]TbTbSccghklu  mA  mA  iB  hC C	
 *#/C/CXW"+"7"7"<"<"K	5553H>PQ		LLghqLrKsstu~t @# $6"6 7> 
	
 	3&$\N!4IIj  lG  HQ  lR  kS  ST  U^  T_ _ 	r   )!typingr   $Generators.libweb_bindings.argumentsr   "Generators.libweb_bindings.contextr   $Generators.libweb_bindings.cpp_typesr   r   r	   r
   .Generators.libweb_bindings.extended_attributesr   #Generators.libweb_bindings.includesr   &Generators.libweb_bindings.to_js_valuer   Utils.webidl_parserr   r   boolr   r!   r*   r5   r:   r=   r@   rT   rV   r[   r]   rY    r   r   <module>ru      sB    V @ S H L T Q A F ) 0e9 e e!6 !EV !cl !qu !HB	BB B 
	BJ&
	&
&
 &
 
	&
R& ;L Yb gk "& ;L Yb gk 6 <M Zc hl '	''  ' 	'
 
'T'	''  ' 	'
 
'TQ	QQ  Q 	Q
 
Q Q	QQ  Q 	Q
 
Q >	>>  > 	>
  > 
>r   