Fix RegExp literal NullReferenceException in getters parsed via ParseExpression #2162
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.
Fixed a
NullReferenceException
that occurred when using RegExp literal notation in getters parsed viaParser().ParseExpression()
. The issue manifested inRegExpPrototype.RegExpBuiltinExec
when the regex object was null.Problem
When expressions containing regex literals are parsed individually (not as part of a full script preparation), the regex compilation step was skipped, leaving the
Regex
object uninitialized. This caused a null reference exception when the regex was later executed.Solution
Modified
JintLiteralExpression.ResolveValue()
to perform on-demand regex compilation whenregExpParseResult.Regex
is null. The fix uses the sameTokenizer.AdaptRegExp()
method that's used inRegExpConstructor
to ensure consistent behavior.The solution:
Testing
/pattern/flags
) and constructor notation (new RegExp()
) continue to workFixes #2161.
💬 Share your feedback on Copilot coding agent for the chance to win a $200 gift card! Click here to start the survey.