[PATCH v10 5/5] jscript: Return the correct string for Object.toString(null) in ES5+ modes.
Gabriel Ivăncescu
gabrielopcode at gmail.com
Mon Nov 29 07:14:31 CST 2021
This has to be special cased for Object_toString because null is otherwise
replaced by the global object for any other case.
Signed-off-by: Gabriel Ivăncescu <gabrielopcode at gmail.com>
---
dlls/jscript/function.c | 10 ++++++++++
dlls/jscript/jscript.h | 1 +
dlls/jscript/object.c | 2 +-
dlls/mshtml/tests/documentmode.js | 2 +-
dlls/mshtml/tests/es5.js | 1 -
5 files changed, 13 insertions(+), 3 deletions(-)
diff --git a/dlls/jscript/function.c b/dlls/jscript/function.c
index 3eef1aa..c0eb847 100644
--- a/dlls/jscript/function.c
+++ b/dlls/jscript/function.c
@@ -604,6 +604,16 @@ static HRESULT NativeFunction_call(script_ctx_t *ctx, FunctionInstance *func, ID
if(this_disp)
set_disp(&vthis, this_disp);
+ else if(function->proc == Object_toString && ctx->version >= SCRIPTLANGUAGEVERSION_ES5) {
+ jsstr_t *ret;
+ if(!r)
+ return S_OK;
+ ret = jsstr_alloc(L"[object Null]");
+ if(!ret)
+ return E_OUTOFMEMORY;
+ *r = jsval_string(ret);
+ return S_OK;
+ }
else
set_disp(&vthis, lookup_global_host(ctx));
diff --git a/dlls/jscript/jscript.h b/dlls/jscript/jscript.h
index c192ec7..8a9bcf4 100644
--- a/dlls/jscript/jscript.h
+++ b/dlls/jscript/jscript.h
@@ -514,6 +514,7 @@ BOOL bool_obj_value(jsdisp_t*) DECLSPEC_HIDDEN;
unsigned array_get_length(jsdisp_t*) DECLSPEC_HIDDEN;
HRESULT JSGlobal_eval(script_ctx_t*,vdisp_t*,WORD,unsigned,jsval_t*,jsval_t*) DECLSPEC_HIDDEN;
+HRESULT Object_toString(script_ctx_t*,vdisp_t*,WORD,unsigned,jsval_t*,jsval_t*) DECLSPEC_HIDDEN;
static inline BOOL is_class(jsdisp_t *jsdisp, jsclass_t class)
{
diff --git a/dlls/jscript/object.c b/dlls/jscript/object.c
index 24692f8..c008469 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, vdisp_t *jsthis, WORD flags, unsigned argc, jsval_t *argv,
+HRESULT Object_toString(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, unsigned argc, jsval_t *argv,
jsval_t *r)
{
jsdisp_t *jsdisp;
diff --git a/dlls/mshtml/tests/documentmode.js b/dlls/mshtml/tests/documentmode.js
index bc6d1ee..1a52140 100644
--- a/dlls/mshtml/tests/documentmode.js
+++ b/dlls/mshtml/tests/documentmode.js
@@ -1226,7 +1226,7 @@ sync_test("elem_attr", function() {
r = elem.removeAttribute("ondblclick");
ok(r === (v < 8 ? false : (v < 9 ? true : undefined)), "ondblclick removeAttribute returned " + r);
r = Object.prototype.toString.call(elem.ondblclick);
- todo_wine_if(v >= 9).
+ todo_wine_if(v >= 11).
ok(r === (v < 8 ? "[object Array]" : (v < 9 ? "[object Object]" : (v < 11 ? "[object Null]" : "[object Function]"))),
"removed ondblclick Object.toString returned " + r);
diff --git a/dlls/mshtml/tests/es5.js b/dlls/mshtml/tests/es5.js
index 58b0d43..84b5f36 100644
--- a/dlls/mshtml/tests/es5.js
+++ b/dlls/mshtml/tests/es5.js
@@ -797,7 +797,6 @@ sync_test("toString", function() {
todo_wine.
ok(tmp === "[object Window]", "toString.call(null) = " + tmp);
tmp = Object.prototype.toString.call(null);
- todo_wine.
ok(tmp === "[object Null]", "toString.call(null) = " + tmp);
tmp = Object.prototype.toString.call(undefined);
todo_wine.
--
2.31.1
More information about the wine-devel
mailing list