Fix member accesses for non-decimal numeric literals (#377)
* Fix member accesses for non-decimal numeric literals e.g. 0x0.a should return undefined, not SyntaxError. * Remove ineffective non-decimal float parsing code and redundant checks on `is_float && radix != 10` (The code already wasn't doing anything because of the `is_float` check.)
This commit is contained in:
parent
5797f2a716
commit
29b45337f0
2 changed files with 13 additions and 8 deletions
10
quickjs.c
10
quickjs.c
|
@ -10264,7 +10264,7 @@ static JSValue js_atof2(JSContext *ctx, const char *str, const char **pp,
|
||||||
to_digit((uint8_t)p[1]) < radix)) {
|
to_digit((uint8_t)p[1]) < radix)) {
|
||||||
p++;
|
p++;
|
||||||
}
|
}
|
||||||
if (!(flags & ATOD_INT_ONLY)) {
|
if (!(flags & ATOD_INT_ONLY) && radix == 10) {
|
||||||
if (*p == '.' && (p > p_start || to_digit((uint8_t)p[1]) < radix)) {
|
if (*p == '.' && (p > p_start || to_digit((uint8_t)p[1]) < radix)) {
|
||||||
is_float = TRUE;
|
is_float = TRUE;
|
||||||
p++;
|
p++;
|
||||||
|
@ -10274,9 +10274,7 @@ static JSValue js_atof2(JSContext *ctx, const char *str, const char **pp,
|
||||||
(*p == sep && to_digit((uint8_t)p[1]) < radix))
|
(*p == sep && to_digit((uint8_t)p[1]) < radix))
|
||||||
p++;
|
p++;
|
||||||
}
|
}
|
||||||
if (p > p_start &&
|
if (p > p_start && (*p == 'e' || *p == 'E')) {
|
||||||
(((*p == 'e' || *p == 'E') && radix == 10) ||
|
|
||||||
((*p == 'p' || *p == 'P') && (radix == 2 || radix == 8 || radix == 16)))) {
|
|
||||||
const char *p1 = p + 1;
|
const char *p1 = p + 1;
|
||||||
is_float = TRUE;
|
is_float = TRUE;
|
||||||
if (*p1 == '+') {
|
if (*p1 == '+') {
|
||||||
|
@ -10317,11 +10315,7 @@ static JSValue js_atof2(JSContext *ctx, const char *str, const char **pp,
|
||||||
if (*p == 'n') {
|
if (*p == 'n') {
|
||||||
p++;
|
p++;
|
||||||
atod_type = ATOD_TYPE_BIG_INT;
|
atod_type = ATOD_TYPE_BIG_INT;
|
||||||
} else if (is_float && radix != 10) {
|
|
||||||
goto fail;
|
|
||||||
}
|
}
|
||||||
} else if ((atod_type == ATOD_TYPE_FLOAT64) && is_float && radix != 10) {
|
|
||||||
goto fail;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
switch(atod_type) {
|
switch(atod_type) {
|
||||||
|
|
|
@ -593,6 +593,16 @@ function test_reserved_names()
|
||||||
test_name('static', SyntaxError);
|
test_name('static', SyntaxError);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function test_number_literals()
|
||||||
|
{
|
||||||
|
assert(0.1.a, undefined);
|
||||||
|
assert(0x1.a, undefined);
|
||||||
|
assert(0b1.a, undefined);
|
||||||
|
assert(01.a, undefined);
|
||||||
|
assert(0o1.a, undefined);
|
||||||
|
test_expr('0.a', SyntaxError);
|
||||||
|
}
|
||||||
|
|
||||||
test_op1();
|
test_op1();
|
||||||
test_cvt();
|
test_cvt();
|
||||||
test_eq();
|
test_eq();
|
||||||
|
@ -613,3 +623,4 @@ test_function_length();
|
||||||
test_argument_scope();
|
test_argument_scope();
|
||||||
test_function_expr_name();
|
test_function_expr_name();
|
||||||
test_reserved_names();
|
test_reserved_names();
|
||||||
|
test_number_literals();
|
||||||
|
|
Loading…
Reference in a new issue