From: Gabriel Ivăncescu gabrielopcode@gmail.com
Signed-off-by: Gabriel Ivăncescu gabrielopcode@gmail.com --- dlls/jscript/array.c | 8 +++++- dlls/jscript/jscript.h | 1 + dlls/jscript/object.c | 2 +- dlls/jscript/tests/api.js | 1 + dlls/mshtml/tests/documentmode.js | 46 +++++++++++++++++++++++++++++++ 5 files changed, 56 insertions(+), 2 deletions(-)
diff --git a/dlls/jscript/array.c b/dlls/jscript/array.c index dfd9eda75cc..80fb52f486f 100644 --- a/dlls/jscript/array.c +++ b/dlls/jscript/array.c @@ -948,8 +948,14 @@ static HRESULT Array_toString(script_ctx_t *ctx, jsval_t vthis, WORD flags, unsi TRACE("\n");
array = array_this(vthis); - if(!array) + if(!array) { + if(ctx->version >= SCRIPTLANGUAGEVERSION_ES5) { + if(is_undefined(vthis) || is_null(vthis)) + return JS_E_OBJECT_EXPECTED; + return Object_toString(ctx, vthis, flags, argc, argv, r); + } return JS_E_ARRAY_EXPECTED; + }
return array_join(ctx, &array->dispex, array->length, L",", 1, to_string, r); } diff --git a/dlls/jscript/jscript.h b/dlls/jscript/jscript.h index 30f3d8d6bfa..6175dea9c49 100644 --- a/dlls/jscript/jscript.h +++ b/dlls/jscript/jscript.h @@ -496,6 +496,7 @@ HRESULT localize_number(script_ctx_t*,DOUBLE,BOOL,jsstr_t**); BOOL is_builtin_eval_func(jsdisp_t*); HRESULT builtin_eval(script_ctx_t*,struct _call_frame_t*,WORD,unsigned,jsval_t*,jsval_t*); HRESULT JSGlobal_eval(script_ctx_t*,jsval_t,WORD,unsigned,jsval_t*,jsval_t*); +HRESULT Object_toString(script_ctx_t*,jsval_t,WORD,unsigned,jsval_t*,jsval_t*); HRESULT Object_get_proto_(script_ctx_t*,jsval_t,WORD,unsigned,jsval_t*,jsval_t*); HRESULT Object_set_proto_(script_ctx_t*,jsval_t,WORD,unsigned,jsval_t*,jsval_t*);
diff --git a/dlls/jscript/object.c b/dlls/jscript/object.c index feeff5c294a..a1ba990695b 100644 --- a/dlls/jscript/object.c +++ b/dlls/jscript/object.c @@ -24,7 +24,7 @@
WINE_DEFAULT_DEBUG_CHANNEL(jscript);
-static HRESULT Object_toString(script_ctx_t *ctx, jsval_t vthis, WORD flags, unsigned argc, jsval_t *argv, +HRESULT Object_toString(script_ctx_t *ctx, jsval_t vthis, WORD flags, unsigned argc, jsval_t *argv, jsval_t *r) { const WCHAR *str = NULL; diff --git a/dlls/jscript/tests/api.js b/dlls/jscript/tests/api.js index 8c054fff058..9158e31fd8a 100644 --- a/dlls/jscript/tests/api.js +++ b/dlls/jscript/tests/api.js @@ -2704,6 +2704,7 @@ testException(function() {date.setTime();}, "E_ARG_NOT_OPT"); testException(function() {date.setYear();}, "E_ARG_NOT_OPT"); testException(function() {arr.test();}, "E_NO_PROPERTY"); testException(function() {[1,2,3].sort(nullDisp);}, "E_JSCRIPT_EXPECTED"); +testException(function() {var o = new Object(); o.length = 1; o[0] = "a"; Array.prototype.toString.call(o);}, "E_NOT_ARRAY"); testException(function() {var o = new Object(); o.length = 1; o[0] = "a"; Array.prototype.toLocaleString.call(o);}, "E_NOT_ARRAY"); testException(function() {Number.prototype.toString.call(arr);}, "E_NOT_NUM"); testException(function() {Number.prototype.toFixed.call(arr);}, "E_NOT_NUM"); diff --git a/dlls/mshtml/tests/documentmode.js b/dlls/mshtml/tests/documentmode.js index 3a9fb8319bb..59801936ecd 100644 --- a/dlls/mshtml/tests/documentmode.js +++ b/dlls/mshtml/tests/documentmode.js @@ -505,6 +505,52 @@ sync_test("builtin_obj", function() {
e = Array.isArray(document.body.childNodes); ok(e === false, "isArray(childNodes) returned " + e); + e = Array.prototype.toString.call(Number); + ok(e === "[object Function]", "Array.toString(Number) = " + e); + } + + function test_toString(msg, constr, err) { + var e = 0; + if(typeof(err) === "string") { + e = constr.prototype.toString.call(document.body); + ok(e === err, msg + ".toString(body) = " + e); + return; + } + try { + constr.prototype.toString.call(document.body); + }catch(ex) { + e = ex.number; + } + ok(e === err - 0x80000000, "[" + msg + ".toString(body)] e = " + e); + } + + test_toString("Array", Array, v < 9 ? 0xa13a7 : "[object HTMLBodyElement]"); + test_toString("Boolean", Boolean, 0xa1392); + test_toString("Date", Date, 0xa138e); + test_toString("RegExp", RegExp, 0xa1398); + test_toString("Number", Number, 0xa1389); + + if(v >= 9) { + var obj = { length: 2 }; + obj[0] = "foo"; + obj[1] = "bar"; + e = Array.prototype.toString.call(obj); + ok(e === "[object Object]", "Array.toString(array-like object) = " + e); + + obj = Object.create(null); + obj.length = 2; + obj[0] = "foo"; + obj[1] = "bar"; + e = Array.prototype.toString.call(obj); + ok(e === "[object Object]", "Array.toString(array-like object with no prototype) = " + e); + + e = 0; + try { + Array.prototype.toString.call(null); + }catch(ex) { + e = ex.number; + } + ok(e === 0xa138f - 0x80000000, "Array.toString(null) e = " + e); }
(function(a, b, c) {