Signed-off-by: Jeff Smith whydoubt@gmail.com --- dlls/jscript/decode.c | 11 ++++------- dlls/jscript/function.c | 34 +++++++++++++++------------------- dlls/jscript/jsutils.c | 6 ++---- dlls/jscript/parser.y | 4 +--- dlls/jscript/string.c | 4 +--- 5 files changed, 23 insertions(+), 36 deletions(-)
diff --git a/dlls/jscript/decode.c b/dlls/jscript/decode.c index 283aa2ed947..b121c34b70e 100644 --- a/dlls/jscript/decode.c +++ b/dlls/jscript/decode.c @@ -113,14 +113,11 @@ HRESULT decode_source(WCHAR *code) const WCHAR *src = code; WCHAR *dst = code;
- static const WCHAR decode_beginW[] = {'#','@','~','^'}; - static const WCHAR decode_endW[] = {'^','#','~','@'}; - while(*src) { - if(!wcsncmp(src, decode_beginW, ARRAY_SIZE(decode_beginW))) { + if(!wcscmp(src, L"#@~^")) { DWORD len, i, j=0, csum, s=0;
- src += ARRAY_SIZE(decode_beginW); + src += lstrlenW(L"#@~^");
if(!decode_dword(src, &len)) return JS_E_INVALID_CHAR; @@ -165,9 +162,9 @@ HRESULT decode_source(WCHAR *code) return JS_E_INVALID_CHAR; src += 8;
- if(wcsncmp(src, decode_endW, ARRAY_SIZE(decode_endW))) + if(wcscmp(src, L"^#~@")) return JS_E_INVALID_CHAR; - src += ARRAY_SIZE(decode_endW); + src += lstrlenW(L"^#~@"); }else { *dst++ = *src++; } diff --git a/dlls/jscript/function.c b/dlls/jscript/function.c index 9f6aa4b4ec6..f3b40d22865 100644 --- a/dlls/jscript/function.c +++ b/dlls/jscript/function.c @@ -616,24 +616,20 @@ static HRESULT NativeFunction_call(script_ctx_t *ctx, FunctionInstance *func, ID static HRESULT NativeFunction_toString(FunctionInstance *func, jsstr_t **ret) { NativeFunction *function = (NativeFunction*)func; - DWORD name_len; + DWORD str_len; jsstr_t *str; WCHAR *ptr;
- static const WCHAR native_prefixW[] = {'\n','f','u','n','c','t','i','o','n',' '}; - static const WCHAR native_suffixW[] = - {'(',')',' ','{','\n',' ',' ',' ',' ','[','n','a','t','i','v','e',' ','c','o','d','e',']','\n','}','\n'}; + static const WCHAR native_formatW[] = L"\nfunction %s() {\n [native code]\n}\n";
- name_len = function->name ? lstrlenW(function->name) : 0; - str = jsstr_alloc_buf(ARRAY_SIZE(native_prefixW) + ARRAY_SIZE(native_suffixW) + name_len, &ptr); + str_len = lstrlenW(native_formatW) - 2; + if(function->name) + str_len += lstrlenW(function->name); + str = jsstr_alloc_buf(str_len, &ptr); if(!str) return E_OUTOFMEMORY;
- memcpy(ptr, native_prefixW, sizeof(native_prefixW)); - ptr += ARRAY_SIZE(native_prefixW); - memcpy(ptr, function->name, name_len*sizeof(WCHAR)); - ptr += name_len; - memcpy(ptr, native_suffixW, sizeof(native_suffixW)); + swprintf(ptr, str_len+1, native_formatW, function->name ? function->name : L"");
*ret = str; return S_OK; @@ -912,8 +908,8 @@ static HRESULT construct_function(script_ctx_t *ctx, unsigned argc, jsval_t *arg int j = 0; HRESULT hres = S_OK;
- static const WCHAR function_anonymousW[] = {'f','u','n','c','t','i','o','n',' ','a','n','o','n','y','m','o','u','s','('}; - static const WCHAR function_beginW[] = {')',' ','{','\n'}; + static const WCHAR function_anonymousW[] = L"function anonymous("; + static const WCHAR function_beginW[] = L") {\n"; static const WCHAR function_endW[] = L"\n}";
if(argc) { @@ -932,11 +928,11 @@ static HRESULT construct_function(script_ctx_t *ctx, unsigned argc, jsval_t *arg }
if(SUCCEEDED(hres)) { - len += ARRAY_SIZE(function_anonymousW) + ARRAY_SIZE(function_beginW) + ARRAY_SIZE(function_endW); + len += lstrlenW(function_anonymousW) + lstrlenW(function_beginW) + lstrlenW(function_endW) + 1; str = heap_alloc(len*sizeof(WCHAR)); if(str) { - memcpy(str, function_anonymousW, sizeof(function_anonymousW)); - ptr = str + ARRAY_SIZE(function_anonymousW); + memcpy(str, function_anonymousW, lstrlenW(function_anonymousW)*sizeof(WCHAR)); + ptr = str + lstrlenW(function_anonymousW); if(argc > 1) { while(1) { ptr += jsstr_flush(params[j], ptr); @@ -946,11 +942,11 @@ static HRESULT construct_function(script_ctx_t *ctx, unsigned argc, jsval_t *arg *ptr++ = ' '; } } - memcpy(ptr, function_beginW, sizeof(function_beginW)); - ptr += ARRAY_SIZE(function_beginW); + memcpy(ptr, function_beginW, lstrlenW(function_beginW)*sizeof(WCHAR)); + ptr += lstrlenW(function_beginW); if(argc) ptr += jsstr_flush(params[argc-1], ptr); - memcpy(ptr, function_endW, sizeof(function_endW)); + memcpy(ptr, function_endW, (lstrlenW(function_endW)+1)*sizeof(WCHAR));
TRACE("%s\n", debugstr_w(str)); }else { diff --git a/dlls/jscript/jsutils.c b/dlls/jscript/jsutils.c index 56e8306ba21..29075282e0b 100644 --- a/dlls/jscript/jsutils.c +++ b/dlls/jscript/jsutils.c @@ -494,8 +494,6 @@ static HRESULT str_to_number(jsstr_t *str, double *ret) BOOL neg = FALSE; DOUBLE d = 0.0;
- static const WCHAR infinityW[] = {'I','n','f','i','n','i','t','y'}; - ptr = jsstr_flatten(str); if(!ptr) return E_OUTOFMEMORY; @@ -510,8 +508,8 @@ static HRESULT str_to_number(jsstr_t *str, double *ret) ptr++; }
- if(!wcsncmp(ptr, infinityW, ARRAY_SIZE(infinityW))) { - ptr += ARRAY_SIZE(infinityW); + if(!wcscmp(ptr, L"Infinity")) { + ptr += lstrlenW(L"Infinity"); while(*ptr && iswspace(*ptr)) ptr++;
diff --git a/dlls/jscript/parser.y b/dlls/jscript/parser.y index 6016be6cfd8..ba81668dbb3 100644 --- a/dlls/jscript/parser.y +++ b/dlls/jscript/parser.y @@ -1573,14 +1573,12 @@ HRESULT script_parse(script_ctx_t *ctx, struct _compiler_ctx_t *compiler, byteco heap_pool_t *mark; HRESULT hres;
- const WCHAR html_tagW[] = {'<','/','s','c','r','i','p','t','>',0}; - parser_ctx = heap_alloc_zero(sizeof(parser_ctx_t)); if(!parser_ctx) return E_OUTOFMEMORY;
parser_ctx->error_loc = -1; - parser_ctx->is_html = delimiter && !wcsicmp(delimiter, html_tagW); + parser_ctx->is_html = delimiter && !wcsicmp(delimiter, L"</script>");
parser_ctx->begin = parser_ctx->ptr = code->source; parser_ctx->end = parser_ctx->begin + lstrlenW(parser_ctx->begin); diff --git a/dlls/jscript/string.c b/dlls/jscript/string.c index 3dd40e6744f..694cca2b9bb 100644 --- a/dlls/jscript/string.c +++ b/dlls/jscript/string.c @@ -888,9 +888,7 @@ static HRESULT String_replace(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, un if(FAILED(hres)) break; }else { - static const WCHAR undefinedW[] = {'u','n','d','e','f','i','n','e','d'}; - - hres = strbuf_append(&ret, undefinedW, ARRAY_SIZE(undefinedW)); + hres = strbuf_append(&ret, L"undefined", lstrlenW(L"undefined")); if(FAILED(hres)) break; }
Signed-off-by: Jeff Smith whydoubt@gmail.com --- dlls/jscript/date.c | 25 ++++++++++++------------- 1 file changed, 12 insertions(+), 13 deletions(-)
diff --git a/dlls/jscript/date.c b/dlls/jscript/date.c index 5ca23f199f3..efb97aa632e 100644 --- a/dlls/jscript/date.c +++ b/dlls/jscript/date.c @@ -441,7 +441,7 @@ static inline HRESULT date_to_string(DOUBLE time, BOOL show_offset, int offset, LOCALE_SABBREVMONTHNAME9, LOCALE_SABBREVMONTHNAME10, LOCALE_SABBREVMONTHNAME11, LOCALE_SABBREVMONTHNAME12 };
- BOOL formatAD = TRUE; + const WCHAR *formatEra = L""; WCHAR week[64], month[64]; WCHAR buf[192]; jsstr_t *date_jsstr; @@ -466,7 +466,7 @@ static inline HRESULT date_to_string(DOUBLE time, BOOL show_offset, int offset,
year = year_from_time(time); if(year<0) { - formatAD = FALSE; + formatEra = L" B.C."; year = -year+1; }
@@ -480,16 +480,16 @@ static inline HRESULT date_to_string(DOUBLE time, BOOL show_offset, int offset, if(!show_offset) swprintf(buf, ARRAY_SIZE(buf), L"%s %s %d %02d:%02d:%02d %d%s", week, month, day, (int)hour_from_time(time), (int)min_from_time(time), - (int)sec_from_time(time), year, formatAD?L"":L" B.C."); + (int)sec_from_time(time), year, formatEra); else if(offset) swprintf(buf, ARRAY_SIZE(buf), L"%s %s %d %02d:%02d:%02d UTC%c%02d%02d %d%s", week, month, day, (int)hour_from_time(time), (int)min_from_time(time), (int)sec_from_time(time), sign, offset/60, offset%60, - year, formatAD?L"":L" B.C."); + year, formatEra); else swprintf(buf, ARRAY_SIZE(buf), L"%s %s %d %02d:%02d:%02d UTC %d%s", week, month, day, (int)hour_from_time(time), (int)min_from_time(time), - (int)sec_from_time(time), year, formatAD?L"":L" B.C."); + (int)sec_from_time(time), year, formatEra);
date_jsstr = jsstr_alloc(buf); if(!date_jsstr) @@ -638,7 +638,7 @@ static inline HRESULT create_utc_string(script_ctx_t *ctx, vdisp_t *jsthis, jsva LOCALE_SABBREVMONTHNAME9, LOCALE_SABBREVMONTHNAME10, LOCALE_SABBREVMONTHNAME11, LOCALE_SABBREVMONTHNAME12 };
- BOOL formatAD = TRUE; + const WCHAR *formatEra = L""; WCHAR week[64], month[64]; WCHAR buf[192]; DateInstance *date; @@ -666,15 +666,15 @@ static inline HRESULT create_utc_string(script_ctx_t *ctx, vdisp_t *jsthis, jsva
year = year_from_time(date->time); if(year<0) { - formatAD = FALSE; + formatEra = L" B.C."; year = -year+1; }
day = date_from_time(date->time);
swprintf(buf, ARRAY_SIZE(buf), - formatAD ? L"%s, %d %s %d %02d:%02d:%02d UTC" : L"%s, %d %s %d B.C. %02d:%02d:%02d UTC", - week, day, month, year, (int)hour_from_time(date->time), (int)min_from_time(date->time), + L"%s, %d %s %d%s %02d:%02d:%02d UTC", week, day, month, year, formatEra, + (int)hour_from_time(date->time), (int)min_from_time(date->time), (int)sec_from_time(date->time));
date_str = jsstr_alloc(buf); @@ -714,7 +714,7 @@ static HRESULT dateobj_to_date_string(DateInstance *date, jsval_t *r) LOCALE_SABBREVMONTHNAME9, LOCALE_SABBREVMONTHNAME10, LOCALE_SABBREVMONTHNAME11, LOCALE_SABBREVMONTHNAME12 };
- BOOL formatAD = TRUE; + const WCHAR *formatEra = L""; WCHAR week[64], month[64]; WCHAR buf[192]; jsstr_t *date_str; @@ -741,14 +741,13 @@ static HRESULT dateobj_to_date_string(DateInstance *date, jsval_t *r)
year = year_from_time(time); if(year<0) { - formatAD = FALSE; + formatEra = L" B.C."; year = -year+1; }
day = date_from_time(time);
- swprintf(buf, ARRAY_SIZE(buf), formatAD ? L"%s %s %d %d" : L"%s %s %d %d B.C.", week, month, - day, year); + swprintf(buf, ARRAY_SIZE(buf), L"%s %s %d %d%s", week, month, day, year, formatEra);
date_str = jsstr_alloc(buf); if(!date_str)
Hi Jeff,
For some reason, the patch status page shows Testbot status OK, while tests failed.
On 01.12.2020 23:02, Jeff Smith wrote:
@@ -510,8 +508,8 @@ static HRESULT str_to_number(jsstr_t *str, double *ret) ptr++; }
- if(!wcsncmp(ptr, infinityW, ARRAY_SIZE(infinityW))) {
ptr += ARRAY_SIZE(infinityW);
- if(!wcscmp(ptr, L"Infinity")) {
ptr += lstrlenW(L"Infinity"); while(*ptr && iswspace(*ptr)) ptr++;
There is a reason wcsncmp is used in current code: we want to check only a prefix of ptr. Also lstrlenW() has runtime cost, which should be avoided in places like this. ARRAY_SIZE()-1 will give you that in compile time. The same applies to other places.
Thanks,
Jacek