Commit 41782ec1 authored by Gabriel Ivăncescu's avatar Gabriel Ivăncescu Committed by Alexandre Julliard

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: 's avatarGabriel Ivăncescu <gabrielopcode@gmail.com> Signed-off-by: 's avatarJacek Caban <jacek@codeweavers.com> Signed-off-by: 's avatarAlexandre Julliard <julliard@winehq.org>
parent 8aefdf48
...@@ -524,7 +524,7 @@ static inline DWORD make_grfdex(script_ctx_t *ctx, DWORD flags) ...@@ -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_OBJECT_NONEXTENSIBLE MAKE_JSERROR(IDS_OBJECT_NONEXTENSIBLE)
#define JS_E_NONCONFIGURABLE_REDEFINED MAKE_JSERROR(IDS_NONCONFIGURABLE_REDEFINED) #define JS_E_NONCONFIGURABLE_REDEFINED MAKE_JSERROR(IDS_NONCONFIGURABLE_REDEFINED)
#define JS_E_NONWRITABLE_MODIFIED MAKE_JSERROR(IDS_NONWRITABLE_MODIFIED) #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_PROP_DESC_MISMATCH MAKE_JSERROR(IDS_PROP_DESC_MISMATCH)
#define JS_E_INVALID_WRITABLE_PROP_DESC MAKE_JSERROR(IDS_INVALID_WRITABLE_PROP_DESC) #define JS_E_INVALID_WRITABLE_PROP_DESC MAKE_JSERROR(IDS_INVALID_WRITABLE_PROP_DESC)
......
...@@ -75,7 +75,7 @@ STRINGTABLE ...@@ -75,7 +75,7 @@ STRINGTABLE
IDS_OBJECT_NONEXTENSIBLE "Cannot define property '|': object is not extensible" IDS_OBJECT_NONEXTENSIBLE "Cannot define property '|': object is not extensible"
IDS_NONCONFIGURABLE_REDEFINED "Cannot redefine non-configurable property '|'" IDS_NONCONFIGURABLE_REDEFINED "Cannot redefine non-configurable property '|'"
IDS_NONWRITABLE_MODIFIED "Cannot modify non-writable 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_PROP_DESC_MISMATCH "Property cannot have both accessors and a value"
IDS_COMPILATION_ERROR "Microsoft JScript compilation error" IDS_COMPILATION_ERROR "Microsoft JScript compilation error"
......
...@@ -416,8 +416,11 @@ static HRESULT Number_toLocaleString(script_ctx_t *ctx, jsval_t vthis, WORD flag ...@@ -416,8 +416,11 @@ static HRESULT Number_toLocaleString(script_ctx_t *ctx, jsval_t vthis, WORD flag
TRACE("\n"); TRACE("\n");
hres = numberval_this(vthis, &val); 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; return hres;
}
if(r) { if(r) {
hres = localize_number(ctx, val, ctx->version >= SCRIPTLANGUAGEVERSION_ES5, &str); hres = localize_number(ctx, val, ctx->version >= SCRIPTLANGUAGEVERSION_ES5, &str);
......
...@@ -73,7 +73,7 @@ ...@@ -73,7 +73,7 @@
#define IDS_OBJECT_NONEXTENSIBLE 0x13D5 #define IDS_OBJECT_NONEXTENSIBLE 0x13D5
#define IDS_NONCONFIGURABLE_REDEFINED 0x13D6 #define IDS_NONCONFIGURABLE_REDEFINED 0x13D6
#define IDS_NONWRITABLE_MODIFIED 0x13D7 #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 /* FIXME: This is not compatible with native, but we would
* conflict with IDS_UNSUPPORTED_ACTION otherwise */ * conflict with IDS_UNSUPPORTED_ACTION otherwise */
#define IDS_PROP_DESC_MISMATCH 0x1F00 #define IDS_PROP_DESC_MISMATCH 0x1F00
......
...@@ -94,7 +94,7 @@ static HRESULT get_map_this(script_ctx_t *ctx, jsval_t vthis, MapInstance **ret) ...@@ -94,7 +94,7 @@ static HRESULT get_map_this(script_ctx_t *ctx, jsval_t vthis, MapInstance **ret)
return JS_E_OBJECT_EXPECTED; return JS_E_OBJECT_EXPECTED;
if(!(jsdisp = to_jsdisp(get_object(vthis))) || !is_class(jsdisp, JSCLASS_MAP)) { if(!(jsdisp = to_jsdisp(get_object(vthis))) || !is_class(jsdisp, JSCLASS_MAP)) {
WARN("not a Map object passed as 'this'\n"); 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); *ret = CONTAINING_RECORD(jsdisp, MapInstance, dispex);
...@@ -109,7 +109,7 @@ static HRESULT get_set_this(script_ctx_t *ctx, jsval_t vthis, MapInstance **ret) ...@@ -109,7 +109,7 @@ static HRESULT get_set_this(script_ctx_t *ctx, jsval_t vthis, MapInstance **ret)
return JS_E_OBJECT_EXPECTED; return JS_E_OBJECT_EXPECTED;
if(!(jsdisp = to_jsdisp(get_object(vthis))) || !is_class(jsdisp, JSCLASS_SET)) { if(!(jsdisp = to_jsdisp(get_object(vthis))) || !is_class(jsdisp, JSCLASS_SET)) {
WARN("not a Set object passed as 'this'\n"); 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); *ret = CONTAINING_RECORD(jsdisp, MapInstance, dispex);
......
...@@ -97,7 +97,6 @@ sync_test("Number toLocaleString", function() { ...@@ -97,7 +97,6 @@ sync_test("Number toLocaleString", function() {
ok(false, "expected exception calling it on string"); ok(false, "expected exception calling it on string");
}catch(ex) { }catch(ex) {
var n = ex.number >>> 0; var n = ex.number >>> 0;
todo_wine.
ok(n === JS_E_WRONG_THIS, "called on string threw " + n); ok(n === JS_E_WRONG_THIS, "called on string threw " + n);
} }
try { try {
...@@ -105,7 +104,6 @@ sync_test("Number toLocaleString", function() { ...@@ -105,7 +104,6 @@ sync_test("Number toLocaleString", function() {
ok(false, "expected exception calling it on undefined"); ok(false, "expected exception calling it on undefined");
}catch(ex) { }catch(ex) {
var n = ex.number >>> 0; var n = ex.number >>> 0;
todo_wine.
ok(n === JS_E_WRONG_THIS, "called on undefined threw " + n); ok(n === JS_E_WRONG_THIS, "called on undefined threw " + n);
} }
try { try {
...@@ -113,7 +111,6 @@ sync_test("Number toLocaleString", function() { ...@@ -113,7 +111,6 @@ sync_test("Number toLocaleString", function() {
ok(false, "expected exception calling it on nullDisp"); ok(false, "expected exception calling it on nullDisp");
}catch(ex) { }catch(ex) {
var n = ex.number >>> 0; var n = ex.number >>> 0;
todo_wine.
ok(n === JS_E_WRONG_THIS, "called on nullDisp threw " + n); ok(n === JS_E_WRONG_THIS, "called on nullDisp threw " + n);
} }
}); });
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment