Commit f34cecba authored by Jacek Caban's avatar Jacek Caban Committed by Alexandre Julliard

jscript: Treat only ASCII digits as digits.

parent 8b7e38c5
...@@ -1191,10 +1191,10 @@ static void Array_on_put(jsdisp_t *dispex, const WCHAR *name) ...@@ -1191,10 +1191,10 @@ static void Array_on_put(jsdisp_t *dispex, const WCHAR *name)
const WCHAR *ptr = name; const WCHAR *ptr = name;
DWORD id = 0; DWORD id = 0;
if(!iswdigit(*ptr)) if(!is_digit(*ptr))
return; return;
while(*ptr && iswdigit(*ptr)) { while(*ptr && is_digit(*ptr)) {
id = id*10 + (*ptr-'0'); id = id*10 + (*ptr-'0');
ptr++; ptr++;
} }
......
...@@ -239,7 +239,7 @@ static HRESULT find_prop_name(jsdisp_t *This, unsigned hash, const WCHAR *name, ...@@ -239,7 +239,7 @@ static HRESULT find_prop_name(jsdisp_t *This, unsigned hash, const WCHAR *name,
const WCHAR *ptr; const WCHAR *ptr;
unsigned idx = 0; 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'); idx = idx*10 + (*ptr-'0');
if(!*ptr && idx < This->builtin_info->idx_length(This)) { if(!*ptr && idx < This->builtin_info->idx_length(This)) {
prop = alloc_prop(This, name, PROP_IDX, This->builtin_info->idx_put ? PROPF_WRITABLE : 0); prop = alloc_prop(This, name, PROP_IDX, This->builtin_info->idx_put ? PROPF_WRITABLE : 0);
......
...@@ -376,6 +376,8 @@ static HRESULT JSGlobal_parseFloat(script_ctx_t *ctx, vdisp_t *jsthis, WORD flag ...@@ -376,6 +376,8 @@ static HRESULT JSGlobal_parseFloat(script_ctx_t *ctx, vdisp_t *jsthis, WORD flag
return S_OK; return S_OK;
} }
TRACE("%s\n", debugstr_jsval(argv[0]));
hres = to_flat_string(ctx, argv[0], &val_str, &str); hres = to_flat_string(ctx, argv[0], &val_str, &str);
if(FAILED(hres)) if(FAILED(hres))
return hres; return hres;
...@@ -389,10 +391,10 @@ static HRESULT JSGlobal_parseFloat(script_ctx_t *ctx, vdisp_t *jsthis, WORD flag ...@@ -389,10 +391,10 @@ static HRESULT JSGlobal_parseFloat(script_ctx_t *ctx, vdisp_t *jsthis, WORD flag
str++; str++;
} }
if(iswdigit(*str)) if(is_digit(*str))
ret_nan = FALSE; ret_nan = FALSE;
while(iswdigit(*str)) { while(is_digit(*str)) {
hlp = d*10 + *(str++) - '0'; hlp = d*10 + *(str++) - '0';
if(d>MAXLONGLONG/10 || hlp<0) { if(d>MAXLONGLONG/10 || hlp<0) {
exp++; exp++;
...@@ -401,17 +403,17 @@ static HRESULT JSGlobal_parseFloat(script_ctx_t *ctx, vdisp_t *jsthis, WORD flag ...@@ -401,17 +403,17 @@ static HRESULT JSGlobal_parseFloat(script_ctx_t *ctx, vdisp_t *jsthis, WORD flag
else else
d = hlp; d = hlp;
} }
while(iswdigit(*str)) { while(is_digit(*str)) {
exp++; exp++;
str++; str++;
} }
if(*str == '.') str++; if(*str == '.') str++;
if(iswdigit(*str)) if(is_digit(*str))
ret_nan = FALSE; ret_nan = FALSE;
while(iswdigit(*str)) { while(is_digit(*str)) {
hlp = d*10 + *(str++) - '0'; hlp = d*10 + *(str++) - '0';
if(d>MAXLONGLONG/10 || hlp<0) if(d>MAXLONGLONG/10 || hlp<0)
break; break;
...@@ -419,7 +421,7 @@ static HRESULT JSGlobal_parseFloat(script_ctx_t *ctx, vdisp_t *jsthis, WORD flag ...@@ -419,7 +421,7 @@ static HRESULT JSGlobal_parseFloat(script_ctx_t *ctx, vdisp_t *jsthis, WORD flag
d = hlp; d = hlp;
exp--; exp--;
} }
while(iswdigit(*str)) while(is_digit(*str))
str++; str++;
if(*str && !ret_nan && (*str=='e' || *str=='E')) { 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 ...@@ -433,7 +435,7 @@ static HRESULT JSGlobal_parseFloat(script_ctx_t *ctx, vdisp_t *jsthis, WORD flag
str++; str++;
} }
while(iswdigit(*str)) { while(is_digit(*str)) {
if(e>INT_MAX/10 || (e = e*10 + *str++ - '0')<0) if(e>INT_MAX/10 || (e = e*10 + *str++ - '0')<0)
e = INT_MAX; e = INT_MAX;
} }
...@@ -461,7 +463,7 @@ static HRESULT JSGlobal_parseFloat(script_ctx_t *ctx, vdisp_t *jsthis, WORD flag ...@@ -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) { static inline int hex_to_int(const WCHAR wch) {
if(towupper(wch)>='A' && towupper(wch)<='F') return towupper(wch)-'A'+10; 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; return -1;
} }
......
...@@ -354,6 +354,11 @@ HRESULT decode_source(WCHAR*) DECLSPEC_HIDDEN; ...@@ -354,6 +354,11 @@ HRESULT decode_source(WCHAR*) DECLSPEC_HIDDEN;
HRESULT double_to_string(double,jsstr_t**) DECLSPEC_HIDDEN; HRESULT double_to_string(double,jsstr_t**) DECLSPEC_HIDDEN;
BOOL is_finite(double) 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 { typedef struct named_item_t {
IDispatch *disp; IDispatch *disp;
DWORD flags; DWORD flags;
......
...@@ -260,7 +260,7 @@ static HRESULT parse_json_value(json_parse_ctx_t *ctx, jsval_t *r) ...@@ -260,7 +260,7 @@ static HRESULT parse_json_value(json_parse_ctx_t *ctx, jsval_t *r)
skip_spaces(ctx); 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; break;
hres = parse_decimal(&ctx->ptr, ctx->end, &n); hres = parse_decimal(&ctx->ptr, ctx->end, &n);
......
...@@ -555,7 +555,7 @@ static HRESULT str_to_number(jsstr_t *str, double *ret) ...@@ -555,7 +555,7 @@ static HRESULT str_to_number(jsstr_t *str, double *ret)
return S_OK; return S_OK;
} }
while(iswdigit(*ptr)) while(is_digit(*ptr))
d = d*10 + (*ptr++ - '0'); d = d*10 + (*ptr++ - '0');
if(*ptr == 'e' || *ptr == 'E') { if(*ptr == 'e' || *ptr == 'E') {
...@@ -570,7 +570,7 @@ static HRESULT str_to_number(jsstr_t *str, double *ret) ...@@ -570,7 +570,7 @@ static HRESULT str_to_number(jsstr_t *str, double *ret)
ptr++; ptr++;
} }
while(iswdigit(*ptr)) while(is_digit(*ptr))
l = l*10 + (*ptr++ - '0'); l = l*10 + (*ptr++ - '0');
if(eneg) if(eneg)
l = -l; l = -l;
...@@ -580,7 +580,7 @@ static HRESULT str_to_number(jsstr_t *str, double *ret) ...@@ -580,7 +580,7 @@ static HRESULT str_to_number(jsstr_t *str, double *ret)
DOUBLE dec = 0.1; DOUBLE dec = 0.1;
ptr++; ptr++;
while(iswdigit(*ptr)) { while(is_digit(*ptr)) {
d += dec * (*ptr++ - '0'); d += dec * (*ptr++ - '0');
dec *= 0.1; dec *= 0.1;
} }
......
...@@ -297,11 +297,11 @@ BOOL unescape(WCHAR *str, size_t *len) ...@@ -297,11 +297,11 @@ BOOL unescape(WCHAR *str, size_t *len)
c += i; c += i;
break; break;
default: default:
if(iswdigit(*p)) { if(is_digit(*p)) {
c = *p++ - '0'; c = *p++ - '0';
if(p < end && iswdigit(*p)) { if(p < end && is_digit(*p)) {
c = c*8 + (*p++ - '0'); c = c*8 + (*p++ - '0');
if(p < end && iswdigit(*p)) if(p < end && is_digit(*p))
c = c*8 + (*p++ - '0'); c = c*8 + (*p++ - '0');
} }
p--; p--;
...@@ -400,7 +400,7 @@ HRESULT parse_decimal(const WCHAR **iter, const WCHAR *end, double *ret) ...@@ -400,7 +400,7 @@ HRESULT parse_decimal(const WCHAR **iter, const WCHAR *end, double *ret)
LONGLONG d = 0, hlp; LONGLONG d = 0, hlp;
int exp = 0; int exp = 0;
while(ptr < end && iswdigit(*ptr)) { while(ptr < end && is_digit(*ptr)) {
hlp = d*10 + *(ptr++) - '0'; hlp = d*10 + *(ptr++) - '0';
if(d>MAXLONGLONG/10 || hlp<0) { if(d>MAXLONGLONG/10 || hlp<0) {
exp++; exp++;
...@@ -409,7 +409,7 @@ HRESULT parse_decimal(const WCHAR **iter, const WCHAR *end, double *ret) ...@@ -409,7 +409,7 @@ HRESULT parse_decimal(const WCHAR **iter, const WCHAR *end, double *ret)
else else
d = hlp; d = hlp;
} }
while(ptr < end && iswdigit(*ptr)) { while(ptr < end && is_digit(*ptr)) {
exp++; exp++;
ptr++; ptr++;
} }
...@@ -417,7 +417,7 @@ HRESULT parse_decimal(const WCHAR **iter, const WCHAR *end, double *ret) ...@@ -417,7 +417,7 @@ HRESULT parse_decimal(const WCHAR **iter, const WCHAR *end, double *ret)
if(*ptr == '.') { if(*ptr == '.') {
ptr++; ptr++;
while(ptr < end && iswdigit(*ptr)) { while(ptr < end && is_digit(*ptr)) {
hlp = d*10 + *(ptr++) - '0'; hlp = d*10 + *(ptr++) - '0';
if(d>MAXLONGLONG/10 || hlp<0) if(d>MAXLONGLONG/10 || hlp<0)
break; break;
...@@ -425,7 +425,7 @@ HRESULT parse_decimal(const WCHAR **iter, const WCHAR *end, double *ret) ...@@ -425,7 +425,7 @@ HRESULT parse_decimal(const WCHAR **iter, const WCHAR *end, double *ret)
d = hlp; d = hlp;
exp--; exp--;
} }
while(ptr < end && iswdigit(*ptr)) while(ptr < end && is_digit(*ptr))
ptr++; ptr++;
} }
...@@ -438,7 +438,7 @@ HRESULT parse_decimal(const WCHAR **iter, const WCHAR *end, double *ret) ...@@ -438,7 +438,7 @@ HRESULT parse_decimal(const WCHAR **iter, const WCHAR *end, double *ret)
}else if(*ptr == '-') { }else if(*ptr == '-') {
sign = -1; sign = -1;
ptr++; ptr++;
}else if(!iswdigit(*ptr)) { }else if(!is_digit(*ptr)) {
WARN("Expected exponent part\n"); WARN("Expected exponent part\n");
return E_FAIL; return E_FAIL;
} }
...@@ -449,7 +449,7 @@ HRESULT parse_decimal(const WCHAR **iter, const WCHAR *end, double *ret) ...@@ -449,7 +449,7 @@ HRESULT parse_decimal(const WCHAR **iter, const WCHAR *end, double *ret)
return E_FAIL; 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) if(e > INT_MAX/10 || (e = e*10 + *ptr++ - '0')<0)
e = INT_MAX; e = INT_MAX;
} }
...@@ -500,12 +500,12 @@ static BOOL parse_numeric_literal(parser_ctx_t *ctx, double *ret) ...@@ -500,12 +500,12 @@ static BOOL parse_numeric_literal(parser_ctx_t *ctx, double *ret)
return TRUE; return TRUE;
} }
if(iswdigit(*ctx->ptr)) { if(is_digit(*ctx->ptr)) {
unsigned base = 8; unsigned base = 8;
const WCHAR *ptr; const WCHAR *ptr;
double val = 0; 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') { if(*ptr > '7') {
base = 10; base = 10;
break; break;
...@@ -514,7 +514,7 @@ static BOOL parse_numeric_literal(parser_ctx_t *ctx, double *ret) ...@@ -514,7 +514,7 @@ static BOOL parse_numeric_literal(parser_ctx_t *ctx, double *ret)
do { do {
val = val*base + *ctx->ptr-'0'; 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? */ /* FIXME: Do we need it here? */
if(ctx->ptr < ctx->end && (is_identifier_char(*ctx->ptr) || *ctx->ptr == '.')) { 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) ...@@ -564,7 +564,7 @@ static int next_token(parser_ctx_t *ctx, void *lval)
return parse_identifier(ctx, lval); return parse_identifier(ctx, lval);
} }
if(iswdigit(*ctx->ptr)) { if(is_digit(*ctx->ptr)) {
double n; double n;
if(!parse_numeric_literal(ctx, &n)) if(!parse_numeric_literal(ctx, &n))
...@@ -591,7 +591,7 @@ static int next_token(parser_ctx_t *ctx, void *lval) ...@@ -591,7 +591,7 @@ static int next_token(parser_ctx_t *ctx, void *lval)
return '}'; return '}';
case '.': case '.':
if(ctx->ptr+1 < ctx->end && iswdigit(ctx->ptr[1])) { if(ctx->ptr+1 < ctx->end && is_digit(ctx->ptr[1])) {
double n; double n;
HRESULT hres; HRESULT hres;
hres = parse_decimal(&ctx->ptr, ctx->end, &n); hres = parse_decimal(&ctx->ptr, ctx->end, &n);
...@@ -909,7 +909,7 @@ int try_parse_ccval(parser_ctx_t *ctx, ccval_t *r) ...@@ -909,7 +909,7 @@ int try_parse_ccval(parser_ctx_t *ctx, ccval_t *r)
if(!skip_spaces(ctx)) if(!skip_spaces(ctx))
return -1; return -1;
if(iswdigit(*ctx->ptr)) { if(is_digit(*ctx->ptr)) {
double n; double n;
if(!parse_numeric_literal(ctx, &n)) if(!parse_numeric_literal(ctx, &n))
......
...@@ -904,14 +904,14 @@ static HRESULT String_replace(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, un ...@@ -904,14 +904,14 @@ static HRESULT String_replace(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, un
default: { default: {
DWORD idx; DWORD idx;
if(!iswdigit(ptr2[1])) { if(!is_digit(ptr2[1])) {
hres = strbuf_append(&ret, ptr2, 1); hres = strbuf_append(&ret, ptr2, 1);
ptr = ptr2+1; ptr = ptr2+1;
break; break;
} }
idx = ptr2[1] - '0'; 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'); idx = idx*10 + (ptr[2]-'0');
ptr = ptr2+3; ptr = ptr2+3;
}else if(idx && idx <= match->paren_count) { }else if(idx && idx <= match->paren_count) {
......
...@@ -1442,6 +1442,7 @@ ok(isNaN(parseFloat('not a number')), "parseFloat('not a number') is not NaN"); ...@@ -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('+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('.12') === 0.12, "parseFloat('.12') = " + parseFloat('.12'));
ok(parseFloat('1e') === 1, "parseFloat('1e') = " + parseFloat('1e')); ok(parseFloat('1e') === 1, "parseFloat('1e') = " + parseFloat('1e'));
ok(isNaN(parseFloat('\uff16')), "parseFloat('\\uD835') is not NaN");
tmp = Math.min(1); tmp = Math.min(1);
ok(tmp === 1, "Math.min(1) = " + tmp); ok(tmp === 1, "Math.min(1) = " + tmp);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment