Skip to content

Commit 7ecf79c

Browse files
committed
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: https://core.svn.wordpress.org/trunk@56070 1a063a9b-81f0-0310-95a4-ce76da25c4cd
1 parent a96340c commit 7ecf79c

File tree

3 files changed

+24
-22
lines changed

3 files changed

+24
-22
lines changed

wp-includes/html-api/class-wp-html-processor-state.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,15 @@ class WP_HTML_Processor_State {
8585
*/
8686
public $active_formatting_elements = null;
8787

88+
/**
89+
* Refers to the currently-matched tag, if any.
90+
*
91+
* @since 6.4.0
92+
*
93+
* @var WP_HTML_Token|null
94+
*/
95+
public $current_token = null;
96+
8897
/**
8998
* Tree construction insertion mode.
9099
*

wp-includes/html-api/class-wp-html-processor.php

Lines changed: 14 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -164,15 +164,6 @@ class WP_HTML_Processor extends WP_HTML_Tag_Processor {
164164
*/
165165
private $bookmark_counter = 0;
166166

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;
175-
176167
/**
177168
* Stores an explanation for why something failed, if it did.
178169
*
@@ -451,7 +442,7 @@ public function step( $node_to_process = self::PROCESS_NEXT_NODE ) {
451442
return false;
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(),
457448
$this->is_tag_closer(),
@@ -538,7 +529,7 @@ private function step_in_body() {
538529
}
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

544535
return true;
@@ -558,7 +549,7 @@ private function step_in_body() {
558549
$this->close_a_p_element();
559550
}
560551

561-
$this->insert_html_element( $this->current_token );
552+
$this->insert_html_element( $this->state->current_token );
562553
return true;
563554

564555
/*
@@ -590,7 +581,7 @@ private function step_in_body() {
590581
*/
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

596587
$this->close_a_p_element();
@@ -612,8 +603,8 @@ private function step_in_body() {
612603
}
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

619610
/*
@@ -633,8 +624,8 @@ private function step_in_body() {
633624
case '+TT':
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

640631
/*
@@ -662,15 +653,15 @@ private function step_in_body() {
662653
*/
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

668659
/*
669660
* > Any other start tag
670661
*/
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

676667
/*
@@ -796,15 +787,17 @@ public function release_bookmark( $bookmark_name ) {
796787
*/
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';
802795

803796
switch ( $direction ) {
804797
case 'forward':
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
}
810803
}

wp-includes/version.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
*
1717
* @global string $wp_version
1818
*/
19-
$wp_version = '6.4-alpha-56557';
19+
$wp_version = '6.4-alpha-56558';
2020

2121
/**
2222
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.

0 commit comments

Comments
 (0)