Make WordPress Core


Ignore:
Timestamp:
09/12/2023 03:10:19 PM (3 years ago)
Author:
Bernhard Reiter
Message:

HTML API: Store current token reference in HTML Processor state.

The $current_token reference has been stored in the HTML Processor itself, but I suggested to move it into the externalized state so that it can be stored and replaced.

In this patch the reference is moved to that state variable and it should become more possible to save and load state, to resume execution after pausing.

Props dmsnell.
Fixes #59268.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/html-api/class-wp-html-processor.php

    r56493 r56558  
    164164         */
    165165        private $bookmark_counter = 0;
    166 
    167         /**
    168          * Refers to the currently-matched tag, if any.
    169          *
    170          * @since 6.4.0
    171          *
    172          * @var WP_HTML_Token|null
    173          */
    174         private $current_token = null;
    175166
    176167        /**
    … …  
    452443                }
    453444
    454                 $this->current_token = new WP_HTML_Token(
     445                $this->state->current_token = new WP_HTML_Token(
    455446                        $this->bookmark_tag(),
    456447                        $this->get_tag(),
    … …  
    539530
    540531                                $this->reconstruct_active_formatting_elements();
    541                                 $this->insert_html_element( $this->current_token );
     532                                $this->insert_html_element( $this->state->current_token );
    542533                                $this->state->frameset_ok = false;
    543534
    … …  
    559550                                }
    560551
    561                                 $this->insert_html_element( $this->current_token );
     552                                $this->insert_html_element( $this->state->current_token );
    562553                                return true;
    563554
    … …  
    591582                        case '-P':
    592583                                if ( ! $this->state->stack_of_open_elements->has_p_in_button_scope() ) {
    593                                         $this->insert_html_element( $this->current_token );
     584                                        $this->insert_html_element( $this->state->current_token );
    594585                                }
    595586
    … …  
    613604
    614605                                $this->reconstruct_active_formatting_elements();
    615                                 $this->insert_html_element( $this->current_token );
    616                                 $this->state->active_formatting_elements->push( $this->current_token );
     606                                $this->insert_html_element( $this->state->current_token );
     607                                $this->state->active_formatting_elements->push( $this->state->current_token );
    617608                                return true;
    618609
    … …  
    634625                        case '+U':
    635626                                $this->reconstruct_active_formatting_elements();
    636                                 $this->insert_html_element( $this->current_token );
    637                                 $this->state->active_formatting_elements->push( $this->current_token );
     627                                $this->insert_html_element( $this->state->current_token );
     628                                $this->state->active_formatting_elements->push( $this->state->current_token );
    638629                                return true;
    639630
    … …  
    663654                        case '+IMG':
    664655                                $this->reconstruct_active_formatting_elements();
    665                                 $this->insert_html_element( $this->current_token );
     656                                $this->insert_html_element( $this->state->current_token );
    666657                                return true;
    667658
    … …  
    671662                        case '+SPAN':
    672663                                $this->reconstruct_active_formatting_elements();
    673                                 $this->insert_html_element( $this->current_token );
     664                                $this->insert_html_element( $this->state->current_token );
    674665                                return true;
    675666
    … …  
    797788        public function seek( $bookmark_name ) {
    798789                $actual_bookmark_name = "_{$bookmark_name}";
    799                 $processor_started_at = $this->current_token ? $this->bookmarks[ $this->current_token->bookmark_name ]->start : 0;
     790                $processor_started_at = $this->state->current_token
     791                        ? $this->bookmarks[ $this->state->current_token->bookmark_name ]->start
     792                        : 0;
    800793                $bookmark_starts_at   = $this->bookmarks[ $actual_bookmark_name ]->start;
    801794                $direction            = $bookmark_starts_at > $processor_started_at ? 'forward' : 'backward';
    … …  
    805798                                // When moving forwards, re-parse the document until reaching the same location as the original bookmark.
    806799                                while ( $this->step() ) {
    807                                         if ( $bookmark_starts_at === $this->bookmarks[ $this->current_token->bookmark_name ]->start ) {
     800                                        if ( $bookmark_starts_at === $this->bookmarks[ $this->state->current_token->bookmark_name ]->start ) {
    808801                                                return true;
    809802                                        }
Note: See TracChangeset for help on using the changeset viewer.