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.
Built from https://develop.svn.wordpress.org/trunk@56558


git-svn-id: http://core.svn.wordpress.org/trunk@56070 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
Bernhard Reiter 2023-09-12 15:12:17 +00:00
parent b847b9c484
commit 251a9c7653
3 changed files with 24 additions and 22 deletions

View File

@ -85,6 +85,15 @@ class WP_HTML_Processor_State {
*/ */
public $active_formatting_elements = null; public $active_formatting_elements = null;
/**
* Refers to the currently-matched tag, if any.
*
* @since 6.4.0
*
* @var WP_HTML_Token|null
*/
public $current_token = null;
/** /**
* Tree construction insertion mode. * Tree construction insertion mode.
* *

View File

@ -164,15 +164,6 @@ class WP_HTML_Processor extends WP_HTML_Tag_Processor {
*/ */
private $bookmark_counter = 0; private $bookmark_counter = 0;
/**
* Refers to the currently-matched tag, if any.
*
* @since 6.4.0
*
* @var WP_HTML_Token|null
*/
private $current_token = null;
/** /**
* Stores an explanation for why something failed, if it did. * Stores an explanation for why something failed, if it did.
* *
@ -451,7 +442,7 @@ class WP_HTML_Processor extends WP_HTML_Tag_Processor {
return false; return false;
} }
$this->current_token = new WP_HTML_Token( $this->state->current_token = new WP_HTML_Token(
$this->bookmark_tag(), $this->bookmark_tag(),
$this->get_tag(), $this->get_tag(),
$this->is_tag_closer(), $this->is_tag_closer(),
@ -538,7 +529,7 @@ class WP_HTML_Processor extends WP_HTML_Tag_Processor {
} }
$this->reconstruct_active_formatting_elements(); $this->reconstruct_active_formatting_elements();
$this->insert_html_element( $this->current_token ); $this->insert_html_element( $this->state->current_token );
$this->state->frameset_ok = false; $this->state->frameset_ok = false;
return true; return true;
@ -558,7 +549,7 @@ class WP_HTML_Processor extends WP_HTML_Tag_Processor {
$this->close_a_p_element(); $this->close_a_p_element();
} }
$this->insert_html_element( $this->current_token ); $this->insert_html_element( $this->state->current_token );
return true; return true;
/* /*
@ -590,7 +581,7 @@ class WP_HTML_Processor extends WP_HTML_Tag_Processor {
*/ */
case '-P': case '-P':
if ( ! $this->state->stack_of_open_elements->has_p_in_button_scope() ) { if ( ! $this->state->stack_of_open_elements->has_p_in_button_scope() ) {
$this->insert_html_element( $this->current_token ); $this->insert_html_element( $this->state->current_token );
} }
$this->close_a_p_element(); $this->close_a_p_element();
@ -612,8 +603,8 @@ class WP_HTML_Processor extends WP_HTML_Tag_Processor {
} }
$this->reconstruct_active_formatting_elements(); $this->reconstruct_active_formatting_elements();
$this->insert_html_element( $this->current_token ); $this->insert_html_element( $this->state->current_token );
$this->state->active_formatting_elements->push( $this->current_token ); $this->state->active_formatting_elements->push( $this->state->current_token );
return true; return true;
/* /*
@ -633,8 +624,8 @@ class WP_HTML_Processor extends WP_HTML_Tag_Processor {
case '+TT': case '+TT':
case '+U': case '+U':
$this->reconstruct_active_formatting_elements(); $this->reconstruct_active_formatting_elements();
$this->insert_html_element( $this->current_token ); $this->insert_html_element( $this->state->current_token );
$this->state->active_formatting_elements->push( $this->current_token ); $this->state->active_formatting_elements->push( $this->state->current_token );
return true; return true;
/* /*
@ -662,7 +653,7 @@ class WP_HTML_Processor extends WP_HTML_Tag_Processor {
*/ */
case '+IMG': case '+IMG':
$this->reconstruct_active_formatting_elements(); $this->reconstruct_active_formatting_elements();
$this->insert_html_element( $this->current_token ); $this->insert_html_element( $this->state->current_token );
return true; return true;
/* /*
@ -670,7 +661,7 @@ class WP_HTML_Processor extends WP_HTML_Tag_Processor {
*/ */
case '+SPAN': case '+SPAN':
$this->reconstruct_active_formatting_elements(); $this->reconstruct_active_formatting_elements();
$this->insert_html_element( $this->current_token ); $this->insert_html_element( $this->state->current_token );
return true; return true;
/* /*
@ -796,7 +787,9 @@ class WP_HTML_Processor extends WP_HTML_Tag_Processor {
*/ */
public function seek( $bookmark_name ) { public function seek( $bookmark_name ) {
$actual_bookmark_name = "_{$bookmark_name}"; $actual_bookmark_name = "_{$bookmark_name}";
$processor_started_at = $this->current_token ? $this->bookmarks[ $this->current_token->bookmark_name ]->start : 0; $processor_started_at = $this->state->current_token
? $this->bookmarks[ $this->state->current_token->bookmark_name ]->start
: 0;
$bookmark_starts_at = $this->bookmarks[ $actual_bookmark_name ]->start; $bookmark_starts_at = $this->bookmarks[ $actual_bookmark_name ]->start;
$direction = $bookmark_starts_at > $processor_started_at ? 'forward' : 'backward'; $direction = $bookmark_starts_at > $processor_started_at ? 'forward' : 'backward';
@ -804,7 +797,7 @@ class WP_HTML_Processor extends WP_HTML_Tag_Processor {
case 'forward': case 'forward':
// When moving forwards, re-parse the document until reaching the same location as the original bookmark. // When moving forwards, re-parse the document until reaching the same location as the original bookmark.
while ( $this->step() ) { while ( $this->step() ) {
if ( $bookmark_starts_at === $this->bookmarks[ $this->current_token->bookmark_name ]->start ) { if ( $bookmark_starts_at === $this->bookmarks[ $this->state->current_token->bookmark_name ]->start ) {
return true; return true;
} }
} }

View File

@ -16,7 +16,7 @@
* *
* @global string $wp_version * @global string $wp_version
*/ */
$wp_version = '6.4-alpha-56557'; $wp_version = '6.4-alpha-56558';
/** /**
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema. * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.