Skip to content

htsparse: convert the JS-detection automaton macros to static functions - #468

Merged
xroche merged 1 commit into
masterfrom
htsparse-t2-automaton
Jul 1, 2026
Merged

htsparse: convert the JS-detection automaton macros to static functions#468
xroche merged 1 commit into
masterfrom
htsparse-t2-automaton

Conversation

@xroche

@xroche xroche commented Jul 1, 2026

Copy link
Copy Markdown
Owner

The two macros driving the <script>-body JS-detection automaton (AUTOMATE_LOOKUP_CURRENT_ADR, INCREMENT_CURRENT_ADR) captured four parser locals by lexical scope, so they only worked where they happened to be expanded. This lifts them to two static helpers driven through a small script_automate struct of pointers built once, and moves the INSCRIPT enum to file scope so the helpers can name it. The opaque new_state_pos*sizeof(row) < sizeof(table) assert becomes the equivalent next < INSCRIPT_NSTATES.

Pure refactor. Proven behavior-preserving: a JS-heavy fixture (document.write, quoted/escaped strings, // and /* */ comments, an onclick handler) crawled under both the master and patched binaries mirrors byte-identically. Continues the htsparse macro cleanup (#463/#464/#467).

AUTOMATE_LOOKUP_CURRENT_ADR and INCREMENT_CURRENT_ADR captured four parser
locals (inscript, inscript_state, inscript_state_pos, html) by lexical scope.
Replace them with two static helpers driven through a small script_automate
struct of pointers set up once, and lift the INSCRIPT enum to file scope so the
helpers can name it. The obscure `new_state_pos*sizeof(row) < sizeof(table)`
bound becomes the equivalent `next < INSCRIPT_NSTATES`.

Behavior-preserving: a JS-heavy crawl (document.write, quoted/escaped strings,
// and /* */ comments, onclick handlers) mirrors byte-identically against
master.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Signed-off-by: Xavier Roche <roche@httrack.com>
@xroche
xroche merged commit d97a7bd into master Jul 1, 2026
15 checks passed
@xroche
xroche deleted the htsparse-t2-automaton branch July 27, 2026 18:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant