3030#include "internal_helpers.h"
3131#include "php_dom_arginfo.h"
3232#include "dom_properties.h"
33+ #include "token_list.h"
3334#include "zend_interfaces.h"
3435#include "lexbor/lexbor/core/types.h"
3536#include "lexbor/lexbor/core/lexbor.h"
@@ -81,6 +82,7 @@ PHP_DOM_EXPORT zend_class_entry *dom_modern_entityreference_class_entry;
8182PHP_DOM_EXPORT zend_class_entry * dom_processinginstruction_class_entry ;
8283PHP_DOM_EXPORT zend_class_entry * dom_modern_processinginstruction_class_entry ;
8384PHP_DOM_EXPORT zend_class_entry * dom_abstract_base_document_class_entry ;
85+ PHP_DOM_EXPORT zend_class_entry * dom_token_list_class_entry ;
8486#ifdef LIBXML_XPATH_ENABLED
8587PHP_DOM_EXPORT zend_class_entry * dom_xpath_class_entry ;
8688PHP_DOM_EXPORT zend_class_entry * dom_modern_xpath_class_entry ;
@@ -97,6 +99,7 @@ static zend_object_handlers dom_modern_nodelist_object_handlers;
9799static zend_object_handlers dom_html_collection_object_handlers ;
98100static zend_object_handlers dom_object_namespace_node_handlers ;
99101static zend_object_handlers dom_modern_domimplementation_object_handlers ;
102+ static zend_object_handlers dom_token_list_object_handlers ;
100103#ifdef LIBXML_XPATH_ENABLED
101104zend_object_handlers dom_xpath_object_handlers ;
102105#endif
@@ -132,6 +135,7 @@ static HashTable dom_modern_entity_prop_handlers;
132135static HashTable dom_processinginstruction_prop_handlers ;
133136static HashTable dom_modern_processinginstruction_prop_handlers ;
134137static HashTable dom_namespace_node_prop_handlers ;
138+ static HashTable dom_token_list_prop_handlers ;
135139#ifdef LIBXML_XPATH_ENABLED
136140static HashTable dom_xpath_prop_handlers ;
137141#endif
@@ -633,6 +637,18 @@ static zend_object *dom_object_namespace_node_clone_obj(zend_object *zobject)
633637 return clone ;
634638}
635639
640+ static zend_object * dom_token_list_new (zend_class_entry * class_type )
641+ {
642+ dom_token_list_object * intern = zend_object_alloc (sizeof (* intern ), class_type );
643+
644+ intern -> dom .prop_handler = & dom_token_list_prop_handlers ;
645+
646+ zend_object_std_init (& intern -> dom .std , class_type );
647+ object_properties_init (& intern -> dom .std , class_type );
648+
649+ return & intern -> dom .std ;
650+ }
651+
636652static const zend_module_dep dom_deps [] = {
637653 ZEND_MOD_REQUIRED ("libxml" )
638654 ZEND_MOD_CONFLICTS ("domxml" )
@@ -658,7 +674,6 @@ zend_module_entry dom_module_entry = { /* {{{ */
658674ZEND_GET_MODULE (dom )
659675#endif
660676
661- void dom_objects_free_storage (zend_object * object );
662677void dom_nnodemap_objects_free_storage (zend_object * object );
663678static zval * dom_nodelist_read_dimension (zend_object * object , zval * offset , int type , zval * rv );
664679static int dom_nodelist_has_dimension (zend_object * object , zval * member , int check_empty );
@@ -732,6 +747,16 @@ PHP_MINIT_FUNCTION(dom)
732747 dom_object_namespace_node_handlers .free_obj = dom_object_namespace_node_free_storage ;
733748 dom_object_namespace_node_handlers .clone_obj = dom_object_namespace_node_clone_obj ;
734749
750+ memcpy (& dom_token_list_object_handlers , & dom_object_handlers , sizeof (zend_object_handlers ));
751+ dom_token_list_object_handlers .offset = XtOffsetOf (dom_token_list_object , dom .std );
752+ dom_token_list_object_handlers .free_obj = dom_token_list_free_obj ;
753+ /* The Web IDL (Web Interface Description Language - https://webidl.spec.whatwg.org) has the [SameObject] constraint
754+ * for this object, which is incompatible with cloning because it imposes that there is only one instance
755+ * per parent object. */
756+ dom_token_list_object_handlers .clone_obj = NULL ;
757+ dom_token_list_object_handlers .read_dimension = dom_token_list_read_dimension ;
758+ dom_token_list_object_handlers .has_dimension = dom_token_list_has_dimension ;
759+
735760 zend_hash_init (& classes , 0 , NULL , NULL , true);
736761
737762 dom_adjacent_position_class_entry = register_class_Dom_AdjacentPosition ();
@@ -1033,6 +1058,7 @@ PHP_MINIT_FUNCTION(dom)
10331058 DOM_REGISTER_PROP_HANDLER (& dom_modern_element_prop_handlers , "tagName" , dom_element_tag_name_read , NULL );
10341059 DOM_REGISTER_PROP_HANDLER (& dom_modern_element_prop_handlers , "id" , dom_element_id_read , dom_element_id_write );
10351060 DOM_REGISTER_PROP_HANDLER (& dom_modern_element_prop_handlers , "className" , dom_element_class_name_read , dom_element_class_name_write );
1061+ DOM_REGISTER_PROP_HANDLER (& dom_modern_element_prop_handlers , "classList" , dom_element_class_list_read , NULL );
10361062 DOM_REGISTER_PROP_HANDLER (& dom_modern_element_prop_handlers , "attributes" , dom_node_attributes_read , NULL );
10371063 DOM_REGISTER_PROP_HANDLER (& dom_modern_element_prop_handlers , "firstElementChild" , dom_parent_node_first_element_child_read , NULL );
10381064 DOM_REGISTER_PROP_HANDLER (& dom_modern_element_prop_handlers , "lastElementChild" , dom_parent_node_last_element_child_read , NULL );
@@ -1227,6 +1253,16 @@ PHP_MINIT_FUNCTION(dom)
12271253 zend_hash_add_new_ptr (& classes , dom_modern_xpath_class_entry -> name , & dom_xpath_prop_handlers );
12281254#endif
12291255
1256+ dom_token_list_class_entry = register_class_Dom_TokenList (zend_ce_aggregate , zend_ce_countable );
1257+ dom_token_list_class_entry -> create_object = dom_token_list_new ;
1258+ dom_token_list_class_entry -> default_object_handlers = & dom_token_list_object_handlers ;
1259+ dom_token_list_class_entry -> get_iterator = dom_token_list_get_iterator ;
1260+
1261+ zend_hash_init (& dom_token_list_prop_handlers , 0 , NULL , NULL , true);
1262+ DOM_REGISTER_PROP_HANDLER (& dom_token_list_prop_handlers , "length" , dom_token_list_length_read , NULL );
1263+ DOM_REGISTER_PROP_HANDLER (& dom_token_list_prop_handlers , "value" , dom_token_list_value_read , dom_token_list_value_write );
1264+ zend_hash_add_new_ptr (& classes , dom_token_list_class_entry -> name , & dom_token_list_prop_handlers );
1265+
12301266 register_php_dom_symbols (module_number );
12311267
12321268 php_libxml_register_export (dom_node_class_entry , php_dom_export_node );
@@ -1292,6 +1328,7 @@ PHP_MSHUTDOWN_FUNCTION(dom) /* {{{ */
12921328 zend_hash_destroy (& dom_modern_entity_prop_handlers );
12931329 zend_hash_destroy (& dom_processinginstruction_prop_handlers );
12941330 zend_hash_destroy (& dom_modern_processinginstruction_prop_handlers );
1331+ zend_hash_destroy (& dom_token_list_prop_handlers );
12951332#ifdef LIBXML_XPATH_ENABLED
12961333 zend_hash_destroy (& dom_xpath_prop_handlers );
12971334#endif
0 commit comments