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

Fix member accesses for non-decimal numeric literals #377

Merged
merged 2 commits into from
Apr 16, 2024

Conversation

bptato
Copy link
Contributor

@bptato bptato commented Apr 14, 2024

$ node -e 'console.log(0x0.a)'
undefined
$ qjs -e 'console.log(0x0.a)'
SyntaxError: invalid number literal
    at <cmdline>:1:1

(I have run into a polyfill that depends on this.)

To fix it I just added a base-10 check to the part of js_atof2 which
consumes the fraction part.

(I think there is no place where parsing non-decimal floats makes
sense; it could be useful for error messages if it really were an error,
but it isn't one.)

I've also added some tests to illustrate what should work.

@chqrlie
Copy link
Collaborator

chqrlie commented Apr 14, 2024

(I think there is no place where parsing non-decimal floats makes sense; it could be useful for error messages if it really were an error, but it isn't one.)

Hello @bptato,
It would make sense for Javascript to accept hexadecimal floats such as 0x0.8 (one half) or 0x1p-1 (same).
Yet ECMA does not support this syntax and quickjs-ng aims for strictly standard Javascript, so your patch does fix a bug.

quickjs.c Outdated Show resolved Hide resolved
e.g. 0x0.a should return undefined, not SyntaxError.
(The code already wasn't doing anything because of the is_float check.)
@chqrlie chqrlie merged commit 29b4533 into quickjs-ng:master Apr 16, 2024
47 checks passed
@chqrlie
Copy link
Collaborator

chqrlie commented Apr 16, 2024

Thank you for your contribution

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.

2 participants