jscript: Treat only ASCII digits as digits.

Signed-off-by: Jacek Caban <jacek@codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard@winehq.org>
This commit is contained in:
Jacek Caban 2019-11-08 21:26:08 +01:00 committed by Alexandre Julliard
parent 8b7e38c542
commit f34cecbae2
9 changed files with 40 additions and 32 deletions

View file

@ -1191,10 +1191,10 @@ static void Array_on_put(jsdisp_t *dispex, const WCHAR *name)
const WCHAR *ptr = name;
DWORD id = 0;
if(!iswdigit(*ptr))
if(!is_digit(*ptr))
return;
while(*ptr && iswdigit(*ptr)) {
while(*ptr && is_digit(*ptr)) {
id = id*10 + (*ptr-'0');
ptr++;
}

View file

@ -239,7 +239,7 @@ static HRESULT find_prop_name(jsdisp_t *This, unsigned hash, const WCHAR *name,
const WCHAR *ptr;
unsigned idx = 0;
for(ptr = name; iswdigit(*ptr) && idx < 0x10000; ptr++)
for(ptr = name; is_digit(*ptr) && idx < 0x10000; ptr++)
idx = idx*10 + (*ptr-'0');
if(!*ptr && idx < This->builtin_info->idx_length(This)) {
prop = alloc_prop(This, name, PROP_IDX, This->builtin_info->idx_put ? PROPF_WRITABLE : 0);

View file

@ -376,6 +376,8 @@ static HRESULT JSGlobal_parseFloat(script_ctx_t *ctx, vdisp_t *jsthis, WORD flag
return S_OK;
}
TRACE("%s\n", debugstr_jsval(argv[0]));
hres = to_flat_string(ctx, argv[0], &val_str, &str);
if(FAILED(hres))
return hres;
@ -389,10 +391,10 @@ static HRESULT JSGlobal_parseFloat(script_ctx_t *ctx, vdisp_t *jsthis, WORD flag
str++;
}
if(iswdigit(*str))
if(is_digit(*str))
ret_nan = FALSE;
while(iswdigit(*str)) {
while(is_digit(*str)) {
hlp = d*10 + *(str++) - '0';
if(d>MAXLONGLONG/10 || hlp<0) {
exp++;
@ -401,17 +403,17 @@ static HRESULT JSGlobal_parseFloat(script_ctx_t *ctx, vdisp_t *jsthis, WORD flag
else
d = hlp;
}
while(iswdigit(*str)) {
while(is_digit(*str)) {
exp++;
str++;
}
if(*str == '.') str++;
if(iswdigit(*str))
if(is_digit(*str))
ret_nan = FALSE;
while(iswdigit(*str)) {
while(is_digit(*str)) {
hlp = d*10 + *(str++) - '0';
if(d>MAXLONGLONG/10 || hlp<0)
break;
@ -419,7 +421,7 @@ static HRESULT JSGlobal_parseFloat(script_ctx_t *ctx, vdisp_t *jsthis, WORD flag
d = hlp;
exp--;
}
while(iswdigit(*str))
while(is_digit(*str))
str++;
if(*str && !ret_nan && (*str=='e' || *str=='E')) {
@ -433,7 +435,7 @@ static HRESULT JSGlobal_parseFloat(script_ctx_t *ctx, vdisp_t *jsthis, WORD flag
str++;
}
while(iswdigit(*str)) {
while(is_digit(*str)) {
if(e>INT_MAX/10 || (e = e*10 + *str++ - '0')<0)
e = INT_MAX;
}
@ -461,7 +463,7 @@ static HRESULT JSGlobal_parseFloat(script_ctx_t *ctx, vdisp_t *jsthis, WORD flag
static inline int hex_to_int(const WCHAR wch) {
if(towupper(wch)>='A' && towupper(wch)<='F') return towupper(wch)-'A'+10;
if(iswdigit(wch)) return wch-'0';
if(is_digit(wch)) return wch-'0';
return -1;
}

View file

@ -354,6 +354,11 @@ HRESULT decode_source(WCHAR*) DECLSPEC_HIDDEN;
HRESULT double_to_string(double,jsstr_t**) DECLSPEC_HIDDEN;
BOOL is_finite(double) DECLSPEC_HIDDEN;
static inline BOOL is_digit(WCHAR c)
{
return '0' <= c && c <= '9';
}
typedef struct named_item_t {
IDispatch *disp;
DWORD flags;

View file

@ -260,7 +260,7 @@ static HRESULT parse_json_value(json_parse_ctx_t *ctx, jsval_t *r)
skip_spaces(ctx);
}
if(*ctx->ptr == '0' && ctx->ptr + 1 < ctx->end && iswdigit(ctx->ptr[1]))
if(*ctx->ptr == '0' && ctx->ptr + 1 < ctx->end && is_digit(ctx->ptr[1]))
break;
hres = parse_decimal(&ctx->ptr, ctx->end, &n);

View file

@ -555,7 +555,7 @@ static HRESULT str_to_number(jsstr_t *str, double *ret)
return S_OK;
}
while(iswdigit(*ptr))
while(is_digit(*ptr))
d = d*10 + (*ptr++ - '0');
if(*ptr == 'e' || *ptr == 'E') {
@ -570,7 +570,7 @@ static HRESULT str_to_number(jsstr_t *str, double *ret)
ptr++;
}
while(iswdigit(*ptr))
while(is_digit(*ptr))
l = l*10 + (*ptr++ - '0');
if(eneg)
l = -l;
@ -580,7 +580,7 @@ static HRESULT str_to_number(jsstr_t *str, double *ret)
DOUBLE dec = 0.1;
ptr++;
while(iswdigit(*ptr)) {
while(is_digit(*ptr)) {
d += dec * (*ptr++ - '0');
dec *= 0.1;
}

View file

@ -297,11 +297,11 @@ BOOL unescape(WCHAR *str, size_t *len)
c += i;
break;
default:
if(iswdigit(*p)) {
if(is_digit(*p)) {
c = *p++ - '0';
if(p < end && iswdigit(*p)) {
if(p < end && is_digit(*p)) {
c = c*8 + (*p++ - '0');
if(p < end && iswdigit(*p))
if(p < end && is_digit(*p))
c = c*8 + (*p++ - '0');
}
p--;
@ -400,7 +400,7 @@ HRESULT parse_decimal(const WCHAR **iter, const WCHAR *end, double *ret)
LONGLONG d = 0, hlp;
int exp = 0;
while(ptr < end && iswdigit(*ptr)) {
while(ptr < end && is_digit(*ptr)) {
hlp = d*10 + *(ptr++) - '0';
if(d>MAXLONGLONG/10 || hlp<0) {
exp++;
@ -409,7 +409,7 @@ HRESULT parse_decimal(const WCHAR **iter, const WCHAR *end, double *ret)
else
d = hlp;
}
while(ptr < end && iswdigit(*ptr)) {
while(ptr < end && is_digit(*ptr)) {
exp++;
ptr++;
}
@ -417,7 +417,7 @@ HRESULT parse_decimal(const WCHAR **iter, const WCHAR *end, double *ret)
if(*ptr == '.') {
ptr++;
while(ptr < end && iswdigit(*ptr)) {
while(ptr < end && is_digit(*ptr)) {
hlp = d*10 + *(ptr++) - '0';
if(d>MAXLONGLONG/10 || hlp<0)
break;
@ -425,7 +425,7 @@ HRESULT parse_decimal(const WCHAR **iter, const WCHAR *end, double *ret)
d = hlp;
exp--;
}
while(ptr < end && iswdigit(*ptr))
while(ptr < end && is_digit(*ptr))
ptr++;
}
@ -438,7 +438,7 @@ HRESULT parse_decimal(const WCHAR **iter, const WCHAR *end, double *ret)
}else if(*ptr == '-') {
sign = -1;
ptr++;
}else if(!iswdigit(*ptr)) {
}else if(!is_digit(*ptr)) {
WARN("Expected exponent part\n");
return E_FAIL;
}
@ -449,7 +449,7 @@ HRESULT parse_decimal(const WCHAR **iter, const WCHAR *end, double *ret)
return E_FAIL;
}
while(ptr < end && iswdigit(*ptr)) {
while(ptr < end && is_digit(*ptr)) {
if(e > INT_MAX/10 || (e = e*10 + *ptr++ - '0')<0)
e = INT_MAX;
}
@ -500,12 +500,12 @@ static BOOL parse_numeric_literal(parser_ctx_t *ctx, double *ret)
return TRUE;
}
if(iswdigit(*ctx->ptr)) {
if(is_digit(*ctx->ptr)) {
unsigned base = 8;
const WCHAR *ptr;
double val = 0;
for(ptr = ctx->ptr; ptr < ctx->end && iswdigit(*ptr); ptr++) {
for(ptr = ctx->ptr; ptr < ctx->end && is_digit(*ptr); ptr++) {
if(*ptr > '7') {
base = 10;
break;
@ -514,7 +514,7 @@ static BOOL parse_numeric_literal(parser_ctx_t *ctx, double *ret)
do {
val = val*base + *ctx->ptr-'0';
}while(++ctx->ptr < ctx->end && iswdigit(*ctx->ptr));
}while(++ctx->ptr < ctx->end && is_digit(*ctx->ptr));
/* FIXME: Do we need it here? */
if(ctx->ptr < ctx->end && (is_identifier_char(*ctx->ptr) || *ctx->ptr == '.')) {
@ -564,7 +564,7 @@ static int next_token(parser_ctx_t *ctx, void *lval)
return parse_identifier(ctx, lval);
}
if(iswdigit(*ctx->ptr)) {
if(is_digit(*ctx->ptr)) {
double n;
if(!parse_numeric_literal(ctx, &n))
@ -591,7 +591,7 @@ static int next_token(parser_ctx_t *ctx, void *lval)
return '}';
case '.':
if(ctx->ptr+1 < ctx->end && iswdigit(ctx->ptr[1])) {
if(ctx->ptr+1 < ctx->end && is_digit(ctx->ptr[1])) {
double n;
HRESULT hres;
hres = parse_decimal(&ctx->ptr, ctx->end, &n);
@ -909,7 +909,7 @@ int try_parse_ccval(parser_ctx_t *ctx, ccval_t *r)
if(!skip_spaces(ctx))
return -1;
if(iswdigit(*ctx->ptr)) {
if(is_digit(*ctx->ptr)) {
double n;
if(!parse_numeric_literal(ctx, &n))

View file

@ -904,14 +904,14 @@ static HRESULT String_replace(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, un
default: {
DWORD idx;
if(!iswdigit(ptr2[1])) {
if(!is_digit(ptr2[1])) {
hres = strbuf_append(&ret, ptr2, 1);
ptr = ptr2+1;
break;
}
idx = ptr2[1] - '0';
if(iswdigit(ptr2[2]) && idx*10 + (ptr2[2]-'0') <= match->paren_count) {
if(is_digit(ptr2[2]) && idx*10 + (ptr2[2]-'0') <= match->paren_count) {
idx = idx*10 + (ptr[2]-'0');
ptr = ptr2+3;
}else if(idx && idx <= match->paren_count) {

View file

@ -1442,6 +1442,7 @@ ok(isNaN(parseFloat('not a number')), "parseFloat('not a number') is not NaN");
ok(parseFloat('+13.2e-3') === 13.2e-3, "parseFloat('+13.2e-3') = " + parseFloat('+13.2e-3'));
ok(parseFloat('.12') === 0.12, "parseFloat('.12') = " + parseFloat('.12'));
ok(parseFloat('1e') === 1, "parseFloat('1e') = " + parseFloat('1e'));
ok(isNaN(parseFloat('\uff16')), "parseFloat('\\uD835') is not NaN");
tmp = Math.min(1);
ok(tmp === 1, "Math.min(1) = " + tmp);