Gabriel Ivăncescu : jscript: Return proper error in Number.toLocaleString with invalid 'this' in ES5 mode.

Alexandre Julliard julliard at winehq.org
Tue May 3 15:39:25 CDT 2022


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

Author: Gabriel Ivăncescu <gabrielopcode at gmail.com>
Date:   Tue May  3 18:17:07 2022 +0300

jscript: Return proper error in Number.toLocaleString with invalid 'this' in ES5 mode.

Note that, for example, Number.toFixed still returns JS_E_NUMBER_EXPECTED
even in ES5 mode (this is already tested).

Signed-off-by: Gabriel Ivăncescu <gabrielopcode at gmail.com>
Signed-off-by: Jacek Caban <jacek at codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard at winehq.org>

---

 dlls/jscript/jscript.h   | 2 +-
 dlls/jscript/jscript.rc  | 2 +-
 dlls/jscript/number.c    | 5 ++++-
 dlls/jscript/resource.h  | 2 +-
 dlls/jscript/set.c       | 4 ++--
 dlls/mshtml/tests/es5.js | 3 ---
 6 files changed, 9 insertions(+), 9 deletions(-)

diff --git a/dlls/jscript/jscript.h b/dlls/jscript/jscript.h
index 90d8142e5e9..513f886509c 100644
--- a/dlls/jscript/jscript.h
+++ b/dlls/jscript/jscript.h
@@ -524,7 +524,7 @@ static inline DWORD make_grfdex(script_ctx_t *ctx, DWORD flags)
 #define JS_E_OBJECT_NONEXTENSIBLE    MAKE_JSERROR(IDS_OBJECT_NONEXTENSIBLE)
 #define JS_E_NONCONFIGURABLE_REDEFINED MAKE_JSERROR(IDS_NONCONFIGURABLE_REDEFINED)
 #define JS_E_NONWRITABLE_MODIFIED    MAKE_JSERROR(IDS_NONWRITABLE_MODIFIED)
-#define JS_E_MAP_EXPECTED            MAKE_JSERROR(IDS_MAP_EXPECTED)
+#define JS_E_WRONG_THIS              MAKE_JSERROR(IDS_WRONG_THIS)
 #define JS_E_PROP_DESC_MISMATCH      MAKE_JSERROR(IDS_PROP_DESC_MISMATCH)
 #define JS_E_INVALID_WRITABLE_PROP_DESC MAKE_JSERROR(IDS_INVALID_WRITABLE_PROP_DESC)
 
diff --git a/dlls/jscript/jscript.rc b/dlls/jscript/jscript.rc
index 2fd0b33ca12..de21a4aba0b 100644
--- a/dlls/jscript/jscript.rc
+++ b/dlls/jscript/jscript.rc
@@ -75,7 +75,7 @@ STRINGTABLE
     IDS_OBJECT_NONEXTENSIBLE       "Cannot define property '|': object is not extensible"
     IDS_NONCONFIGURABLE_REDEFINED  "Cannot redefine non-configurable property '|'"
     IDS_NONWRITABLE_MODIFIED       "Cannot modify non-writable property '|'"
-    IDS_MAP_EXPECTED               "'this' is not a | object"
+    IDS_WRONG_THIS                 "'this' is not a | object"
     IDS_PROP_DESC_MISMATCH         "Property cannot have both accessors and a value"
 
     IDS_COMPILATION_ERROR   "Microsoft JScript compilation error"
diff --git a/dlls/jscript/number.c b/dlls/jscript/number.c
index 9470fbf15a0..90c1401bad3 100644
--- a/dlls/jscript/number.c
+++ b/dlls/jscript/number.c
@@ -416,8 +416,11 @@ static HRESULT Number_toLocaleString(script_ctx_t *ctx, jsval_t vthis, WORD flag
     TRACE("\n");
 
     hres = numberval_this(vthis, &val);
-    if(FAILED(hres))
+    if(FAILED(hres)) {
+        if(hres == JS_E_NUMBER_EXPECTED && ctx->version >= SCRIPTLANGUAGEVERSION_ES5)
+            return throw_error(ctx, JS_E_WRONG_THIS, L"Number");
         return hres;
+    }
 
     if(r) {
         hres = localize_number(ctx, val, ctx->version >= SCRIPTLANGUAGEVERSION_ES5, &str);
diff --git a/dlls/jscript/resource.h b/dlls/jscript/resource.h
index 1338ac58f6c..f84d77c198f 100644
--- a/dlls/jscript/resource.h
+++ b/dlls/jscript/resource.h
@@ -73,7 +73,7 @@
 #define IDS_OBJECT_NONEXTENSIBLE            0x13D5
 #define IDS_NONCONFIGURABLE_REDEFINED       0x13D6
 #define IDS_NONWRITABLE_MODIFIED            0x13D7
-#define IDS_MAP_EXPECTED                    0x13FC
+#define IDS_WRONG_THIS                      0x13FC
 /* FIXME: This is not compatible with native, but we would
  * conflict with IDS_UNSUPPORTED_ACTION otherwise */
 #define IDS_PROP_DESC_MISMATCH              0x1F00
diff --git a/dlls/jscript/set.c b/dlls/jscript/set.c
index dbb4a5dac8f..d1ea6637956 100644
--- a/dlls/jscript/set.c
+++ b/dlls/jscript/set.c
@@ -94,7 +94,7 @@ static HRESULT get_map_this(script_ctx_t *ctx, jsval_t vthis, MapInstance **ret)
         return JS_E_OBJECT_EXPECTED;
     if(!(jsdisp = to_jsdisp(get_object(vthis))) || !is_class(jsdisp, JSCLASS_MAP)) {
         WARN("not a Map object passed as 'this'\n");
-        return throw_error(ctx, JS_E_MAP_EXPECTED, L"Map");
+        return throw_error(ctx, JS_E_WRONG_THIS, L"Map");
     }
 
     *ret = CONTAINING_RECORD(jsdisp, MapInstance, dispex);
@@ -109,7 +109,7 @@ static HRESULT get_set_this(script_ctx_t *ctx, jsval_t vthis, MapInstance **ret)
         return JS_E_OBJECT_EXPECTED;
     if(!(jsdisp = to_jsdisp(get_object(vthis))) || !is_class(jsdisp, JSCLASS_SET)) {
         WARN("not a Set object passed as 'this'\n");
-        return throw_error(ctx, JS_E_MAP_EXPECTED, L"Set");
+        return throw_error(ctx, JS_E_WRONG_THIS, L"Set");
     }
 
     *ret = CONTAINING_RECORD(jsdisp, MapInstance, dispex);
diff --git a/dlls/mshtml/tests/es5.js b/dlls/mshtml/tests/es5.js
index 43640543851..3ac099b23be 100644
--- a/dlls/mshtml/tests/es5.js
+++ b/dlls/mshtml/tests/es5.js
@@ -97,7 +97,6 @@ sync_test("Number toLocaleString", function() {
         ok(false, "expected exception calling it on string");
     }catch(ex) {
         var n = ex.number >>> 0;
-        todo_wine.
         ok(n === JS_E_WRONG_THIS, "called on string threw " + n);
     }
     try {
@@ -105,7 +104,6 @@ sync_test("Number toLocaleString", function() {
         ok(false, "expected exception calling it on undefined");
     }catch(ex) {
         var n = ex.number >>> 0;
-        todo_wine.
         ok(n === JS_E_WRONG_THIS, "called on undefined threw " + n);
     }
     try {
@@ -113,7 +111,6 @@ sync_test("Number toLocaleString", function() {
         ok(false, "expected exception calling it on nullDisp");
     }catch(ex) {
         var n = ex.number >>> 0;
-        todo_wine.
         ok(n === JS_E_WRONG_THIS, "called on nullDisp threw " + n);
     }
 });




More information about the wine-cvs mailing list