[PATCH 1/2] jscript: Use wide-char string literals.
Jeff Smith
whydoubt at gmail.com
Tue Dec 1 16:02:21 CST 2020
Signed-off-by: Jeff Smith <whydoubt at 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;
}
--
2.23.0
More information about the wine-devel
mailing list