Jacek Caban : jscript: Add String.prototype.toLocaleUpperCase and toLocaleLowerCase implementation.

Alexandre Julliard julliard at winehq.org
Mon Mar 15 16:59:13 CDT 2021


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

Author: Jacek Caban <jacek at codeweavers.com>
Date:   Mon Mar 15 18:19:26 2021 +0100

jscript: Add String.prototype.toLocaleUpperCase and toLocaleLowerCase implementation.

They are supposed to be locale-specific, but my testing shows that it's
not the case in native.

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

---

 dlls/jscript/string.c     | 36 +++++++++++++++++++++++-------------
 dlls/jscript/tests/api.js |  8 ++++++++
 2 files changed, 31 insertions(+), 13 deletions(-)

diff --git a/dlls/jscript/string.c b/dlls/jscript/string.c
index a8bd77dc398..4f6d8cd194d 100644
--- a/dlls/jscript/string.c
+++ b/dlls/jscript/string.c
@@ -1363,13 +1363,11 @@ static HRESULT String_sup(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, unsign
     return do_attributeless_tag_format(ctx, jsthis, r, L"SUP");
 }
 
-static HRESULT String_toLowerCase(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, unsigned argc, jsval_t *argv,
-        jsval_t *r)
+static HRESULT to_upper_case(script_ctx_t *ctx, vdisp_t *jsthis, jsval_t *r)
 {
     jsstr_t *str;
-    HRESULT  hres;
+    HRESULT hres;
 
-    TRACE("\n");
 
     hres = get_string_val(ctx, jsthis, &str);
     if(FAILED(hres))
@@ -1387,7 +1385,7 @@ static HRESULT String_toLowerCase(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags
         }
 
         jsstr_flush(str, buf);
-        for (; len--; buf++) *buf = towlower(*buf);
+        for (; len--; buf++) *buf = towupper(*buf);
 
         *r = jsval_string(ret);
     }
@@ -1395,13 +1393,11 @@ static HRESULT String_toLowerCase(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags
     return S_OK;
 }
 
-static HRESULT String_toUpperCase(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, unsigned argc, jsval_t *argv,
-        jsval_t *r)
+static HRESULT to_lower_case(script_ctx_t *ctx, vdisp_t *jsthis, jsval_t *r)
 {
     jsstr_t *str;
     HRESULT hres;
 
-    TRACE("\n");
 
     hres = get_string_val(ctx, jsthis, &str);
     if(FAILED(hres))
@@ -1419,7 +1415,7 @@ static HRESULT String_toUpperCase(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags
         }
 
         jsstr_flush(str, buf);
-        for (; len--; buf++) *buf = towupper(*buf);
+        for (; len--; buf++) *buf = towlower(*buf);
 
         *r = jsval_string(ret);
     }
@@ -1427,18 +1423,32 @@ static HRESULT String_toUpperCase(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags
     return S_OK;
 }
 
+static HRESULT String_toLowerCase(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, unsigned argc, jsval_t *argv,
+        jsval_t *r)
+{
+    TRACE("\n");
+    return to_lower_case(ctx, jsthis, r);
+}
+
+static HRESULT String_toUpperCase(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, unsigned argc, jsval_t *argv,
+        jsval_t *r)
+{
+    TRACE("\n");
+    return to_upper_case(ctx, jsthis, r);
+}
+
 static HRESULT String_toLocaleLowerCase(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, unsigned argc, jsval_t *argv,
         jsval_t *r)
 {
-    FIXME("\n");
-    return E_NOTIMPL;
+    TRACE("\n");
+    return to_lower_case(ctx, jsthis, r);
 }
 
 static HRESULT String_toLocaleUpperCase(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, unsigned argc, jsval_t *argv,
         jsval_t *r)
 {
-    FIXME("\n");
-    return E_NOTIMPL;
+    TRACE("\n");
+    return to_upper_case(ctx, jsthis, r);
 }
 
 static HRESULT String_trim(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, unsigned argc,
diff --git a/dlls/jscript/tests/api.js b/dlls/jscript/tests/api.js
index da0ad1e1ebc..564dfc16f30 100644
--- a/dlls/jscript/tests/api.js
+++ b/dlls/jscript/tests/api.js
@@ -753,10 +753,14 @@ tmp = "test".toLowerCase(3);
 ok(tmp === "test", "''.toLowerCase(3) = " + tmp);
 tmp = "tEsT".toLowerCase();
 ok(tmp === "test", "''.toLowerCase() = " + tmp);
+tmp = "tEsT".toLocaleLowerCase();
+ok(tmp === "test", "''.toLocaleLowerCase() = " + tmp);
 tmp = "tEsT".toLowerCase(3);
 ok(tmp === "test", "''.toLowerCase(3) = " + tmp);
 tmp = ("tE" + String.fromCharCode(0) + "sT").toLowerCase();
 ok(tmp === "te" + String.fromCharCode(0) + "st", "''.toLowerCase() = " + tmp);
+ok(String.prototype.toLocaleLowerCase != String.prototype.toLowerCase,
+   "String.prototype.toLocaleLowerCase == String.prototype.toLowerCase");
 
 tmp = "".toUpperCase();
 ok(tmp === "", "''.toUpperCase() = " + tmp);
@@ -768,8 +772,12 @@ tmp = "tEsT".toUpperCase();
 ok(tmp === "TEST", "''.toUpperCase() = " + tmp);
 tmp = "tEsT".toUpperCase(3);
 ok(tmp === "TEST", "''.toUpperCase(3) = " + tmp);
+tmp = "tEsT".toLocaleUpperCase(3);
+ok(tmp === "TEST", "''.toLocaleUpperCase(3) = " + tmp);
 tmp = ("tE" + String.fromCharCode(0) + "sT").toUpperCase();
 ok(tmp === "TE" + String.fromCharCode(0) + "ST", "''.toUpperCase() = " + tmp);
+ok(String.prototype.toLocaleUpperCase != String.prototype.toUpperCase,
+   "String.prototype.toLocaleUpperCase == String.prototype.toUpperCase");
 
 tmp = "".anchor();
 ok(tmp === "<A NAME=\"undefined\"></A>", "''.anchor() = " + tmp);




More information about the wine-cvs mailing list