htsparse: convert the JS-detection automaton macros to static functions - #468
Merged
Conversation
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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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 twostatichelpers driven through a smallscript_automatestruct of pointers built once, and moves theINSCRIPTenum to file scope so the helpers can name it. The opaquenew_state_pos*sizeof(row) < sizeof(table)assert becomes the equivalentnext < 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).