feat: add support for RegExp.leftContext RegExp.rightContext#923
feat: add support for RegExp.leftContext RegExp.rightContext#923ammarahm-ed wants to merge 4 commits intoquickjs-ng:masterfrom
Conversation
bnoordhuis
left a comment
There was a problem hiding this comment.
One problem I see with this approach is that regexp_last_match_str can stay around indefinitely (also applies to the substrings.)
Imagine you run a regex on a 100 MB string. That string can't be reclaimed until the next time a regexp runs - which may be never.
|
One thing we can do is probably calculate left & right contexts together and free the last matched string. Might help with reducing memory usage. |
|
That might ameliorate it but won't fix it structurally. I'm personally leaning towards not merging this for that reason (users shouldn't pay the cost for a feature they don't use) but a possible midway solution is adding a If you decide to go down that path, I'd also like to see that tested in run-test262.c (but only when a test specifies legacy-regexp) and maybe a qjs command line flag. |
This pull request to
quickjs.cintroduces several changes to enhance the handling of regular expression contexts within theJSContextstructure. The most important changes include adding new fields to store RegExp context information, initializing these fields in context creation, freeing them in context destruction, and implementing new functions to manage these contexts.Enhancements to RegExp context handling:
quickjs.c: Added new fieldsregexp_left_ctx,regexp_right_ctx,regexp_last_match_str,regexp_last_match_start, andregexp_last_match_endto theJSContextstructure to store RegExp context information.quickjs.c: Initialized the new RegExp context fields in theJS_NewContextRawfunction.quickjs.c: Freed the new RegExp context fields in theJS_FreeContextfunction to prevent memory leaks.quickjs.c: Implemented new functionsjs_regexp_get_leftContextandjs_regexp_get_rightContextto retrieve and manage the left and right context of the last RegExp match.quickjs.c: Updated thejs_regexp_execfunction to store the last match string and its start and end positions in the new context fields.Closes #921