Jeff Smith : jscript: Use wide-char string literals.

Alexandre Julliard julliard at winehq.org
Thu Dec 3 15:35:59 CST 2020


Module: wine
Branch: master
Commit: 4d68572aa635094717bd1bdb0165a441f6f8ca2b
URL:    https://source.winehq.org/git/wine.git/?a=commit;h=4d68572aa635094717bd1bdb0165a441f6f8ca2b

Author: Jeff Smith <whydoubt at gmail.com>
Date:   Thu Dec  3 00:04:25 2020 -0600

jscript: Use wide-char string literals.

Signed-off-by: Jeff Smith <whydoubt at gmail.com>
Signed-off-by: Jacek Caban <jacek at codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard at winehq.org>

---

 dlls/jscript/decode.c   | 12 ++++++------
 dlls/jscript/function.c | 19 +++++++++----------
 dlls/jscript/jsutils.c  |  6 +++---
 dlls/jscript/parser.y   |  4 +---
 dlls/jscript/string.c   |  4 +---
 5 files changed, 20 insertions(+), 25 deletions(-)

diff --git a/dlls/jscript/decode.c b/dlls/jscript/decode.c
index 283aa2ed947..6a87d55e0e0 100644
--- a/dlls/jscript/decode.c
+++ b/dlls/jscript/decode.c
@@ -113,14 +113,14 @@ HRESULT decode_source(WCHAR *code)
     const WCHAR *src = code;
     WCHAR *dst = code;
 
-    static const WCHAR decode_beginW[] = {'#','@','~','^'};
-    static const WCHAR decode_endW[] = {'^','#','~','@'};
+    static const WCHAR decode_beginW[] = L"#@~^";
+    static const WCHAR decode_endW[] = L"^#~@";
 
     while(*src) {
-        if(!wcsncmp(src, decode_beginW, ARRAY_SIZE(decode_beginW))) {
+        if(!wcsncmp(src, decode_beginW, ARRAY_SIZE(decode_beginW)-1)) {
             DWORD len, i, j=0, csum, s=0;
 
-            src += ARRAY_SIZE(decode_beginW);
+            src += ARRAY_SIZE(decode_beginW) - 1;
 
             if(!decode_dword(src, &len))
                 return JS_E_INVALID_CHAR;
@@ -165,9 +165,9 @@ HRESULT decode_source(WCHAR *code)
                 return JS_E_INVALID_CHAR;
             src += 8;
 
-            if(wcsncmp(src, decode_endW, ARRAY_SIZE(decode_endW)))
+            if(wcsncmp(src, decode_endW, ARRAY_SIZE(decode_endW)-1))
                 return JS_E_INVALID_CHAR;
-            src += ARRAY_SIZE(decode_endW);
+            src += ARRAY_SIZE(decode_endW) - 1;
         }else {
             *dst++ = *src++;
         }
diff --git a/dlls/jscript/function.c b/dlls/jscript/function.c
index 9f6aa4b4ec6..7a6dd4b61f3 100644
--- a/dlls/jscript/function.c
+++ b/dlls/jscript/function.c
@@ -620,17 +620,16 @@ static HRESULT NativeFunction_toString(FunctionInstance *func, jsstr_t **ret)
     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_prefixW[] = L"\nfunction ";
+    static const WCHAR native_suffixW[] = L"() {\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 = jsstr_alloc_buf(ARRAY_SIZE(native_prefixW) + ARRAY_SIZE(native_suffixW) + name_len - 2, &ptr);
     if(!str)
         return E_OUTOFMEMORY;
 
     memcpy(ptr, native_prefixW, sizeof(native_prefixW));
-    ptr += ARRAY_SIZE(native_prefixW);
+    ptr += ARRAY_SIZE(native_prefixW) - 1;
     memcpy(ptr, function->name, name_len*sizeof(WCHAR));
     ptr += name_len;
     memcpy(ptr, native_suffixW, sizeof(native_suffixW));
@@ -912,8 +911,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 +931,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 += ARRAY_SIZE(function_anonymousW) + ARRAY_SIZE(function_beginW) + ARRAY_SIZE(function_endW) - 2;
         str = heap_alloc(len*sizeof(WCHAR));
         if(str) {
             memcpy(str, function_anonymousW, sizeof(function_anonymousW));
-            ptr = str + ARRAY_SIZE(function_anonymousW);
+            ptr = str + ARRAY_SIZE(function_anonymousW) - 1;
             if(argc > 1) {
                 while(1) {
                     ptr += jsstr_flush(params[j], ptr);
@@ -947,7 +946,7 @@ static HRESULT construct_function(script_ctx_t *ctx, unsigned argc, jsval_t *arg
                 }
             }
             memcpy(ptr, function_beginW, sizeof(function_beginW));
-            ptr += ARRAY_SIZE(function_beginW);
+            ptr += ARRAY_SIZE(function_beginW) - 1;
             if(argc)
                 ptr += jsstr_flush(params[argc-1], ptr);
             memcpy(ptr, function_endW, sizeof(function_endW));
diff --git a/dlls/jscript/jsutils.c b/dlls/jscript/jsutils.c
index 56e8306ba21..a2ac53f64b9 100644
--- a/dlls/jscript/jsutils.c
+++ b/dlls/jscript/jsutils.c
@@ -494,7 +494,7 @@ 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'};
+    static const WCHAR infinityW[] = L"Infinity";
 
     ptr = jsstr_flatten(str);
     if(!ptr)
@@ -510,8 +510,8 @@ static HRESULT str_to_number(jsstr_t *str, double *ret)
         ptr++;
     }
 
-    if(!wcsncmp(ptr, infinityW, ARRAY_SIZE(infinityW))) {
-        ptr += ARRAY_SIZE(infinityW);
+    if(!wcsncmp(ptr, infinityW, ARRAY_SIZE(infinityW)-1)) {
+        ptr += ARRAY_SIZE(infinityW) - 1;
         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..a8bd77dc398 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", ARRAY_SIZE(L"undefined")-1);
                 if(FAILED(hres))
                     break;
             }




More information about the wine-cvs mailing list