Skip to content
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

Allow "constructor" and other object properties as grammar literals #521

Merged
merged 4 commits into from
Jun 19, 2024

Conversation

hildjj
Copy link
Contributor

@hildjj hildjj commented Jun 19, 2024

Fixes #520.

The Intern class uses an internal object to track whether a particular string has been seen before. It checks this with let num = this.offsets[s];. If one of the 8 base properties of Object is used as the literal name, num gets a non-numeric result.

The quick fix is to initialize offsets with an object that has no prototype instead of {}.

Comment on lines 35 to 42
"d = '__proto__'",
"e = 'constructor'",
"f = 'hasOwnProperty'",
"g = 'isPrototypeOf'",
"h = 'propertyIsEnumerable'",
"i = 'toLocaleString'",
"j = 'toString'",
"k = 'valueOf'",
Copy link
Member

Choose a reason for hiding this comment

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

Probably it is better to create a dedicated test with explicit intention to check that special properties are allowed.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'll squash the two last commits if this change works for you @Mingun

@hildjj
Copy link
Contributor Author

hildjj commented Jun 19, 2024

Puppeteer tests are broken again. I'm going to take a few minutes to switch to playwright, and get the web tests running headless, cross-browser, and in CI.

@Mingun
Copy link
Member

Mingun commented Jun 19, 2024

I did not test changes by myself, but they seems correct, so rely on CI.

@hildjj hildjj merged commit c433373 into peggyjs:main Jun 19, 2024
9 checks passed
@hildjj hildjj deleted the constructor branch June 19, 2024 16:23
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.

Grammar with token "constructor" fails to generate
2 participants