quickjs-ng / quickjs

QuickJS, the Next Generation: a mighty JavaScript engine
https://quickjs-ng.github.io/quickjs/
MIT License
972 stars 79 forks source link

Fix member accesses for non-decimal numeric literals #377

Closed bptato closed 5 months ago

bptato commented 5 months ago
$ 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 commented 5 months ago

(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.

chqrlie commented 5 months ago

Thank you for your contribution