Skip to content

editorial: Get/Set 'lastIndex' on RegExp object cannot trigger user-code #3636

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

aapoalas
Copy link

@aapoalas aapoalas commented Jul 4, 2025

Purely an editorial change, this implies no change in the implementation: The Get and Set calls on "lastIndex" property of a builtin RegExp object cannot trigger user-code, as the property is installed as an unconfigurable own data property of the object with a set value: the property cannot be turned into an accessor property, and the value cannot be unset to make the Get/Set operations enter the prototype chain.

The Get call on "lastIndex" is thus fully infallible: it will always find a valid property value and can never throw any errors.
The Set call on "lastIndex" can still throw errors, as the property can be made unwritable in which case trying to change its value will throw an error.

This appears most importantly in the RegExpBuiltinExec function but also in RegExpInitialize.

Copy link
Member

@michaelficarra michaelficarra left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Your reasoning seems correct to me.

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.

3 participants