Gabriel Ivăncescu : jscript: Pass undefined 'this' instead of null in ES5 mode.

Alexandre Julliard julliard at winehq.org
Mon May 16 15:37:58 CDT 2022


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

Author: Gabriel Ivăncescu <gabrielopcode at gmail.com>
Date:   Mon May 16 19:18:41 2022 +0300

jscript: Pass undefined 'this' instead of null in ES5 mode.

Based on the spec (ECMA-262 5.1 Edition 11.2.3.7), whereas the ES3 spec
says it gets replaced with null.

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/function.c  | 7 ++++++-
 dlls/mshtml/tests/es5.js | 4 +++-
 2 files changed, 9 insertions(+), 2 deletions(-)

diff --git a/dlls/jscript/function.c b/dlls/jscript/function.c
index 12511bbaaa6..638d176cf2c 100644
--- a/dlls/jscript/function.c
+++ b/dlls/jscript/function.c
@@ -250,13 +250,18 @@ void detach_arguments_object(jsdisp_t *args_disp)
 HRESULT Function_invoke(jsdisp_t *func_this, IDispatch *jsthis, WORD flags, unsigned argc, jsval_t *argv, jsval_t *r)
 {
     FunctionInstance *function;
+    jsval_t vthis;
 
     TRACE("func %p this %p\n", func_this, jsthis);
 
     assert(is_class(func_this, JSCLASS_FUNCTION));
     function = function_from_jsdisp(func_this);
 
-    return function->vtbl->call(function->dispex.ctx, function, jsthis ? jsval_disp(jsthis) : jsval_null(), flags, argc, argv, r);
+    if(jsthis)
+        vthis = jsval_disp(jsthis);
+    else
+        vthis = function->dispex.ctx->version < SCRIPTLANGUAGEVERSION_ES5 ? jsval_null() : jsval_undefined();
+    return function->vtbl->call(function->dispex.ctx, function, vthis, flags, argc, argv, r);
 }
 
 static HRESULT Function_get_length(script_ctx_t *ctx, jsdisp_t *jsthis, jsval_t *r)
diff --git a/dlls/mshtml/tests/es5.js b/dlls/mshtml/tests/es5.js
index 19161998aeb..5aa186b91da 100644
--- a/dlls/mshtml/tests/es5.js
+++ b/dlls/mshtml/tests/es5.js
@@ -1800,13 +1800,15 @@ sync_test("substituted this", function() {
     }
 
     var r = ((function() { var f = Object.prototype.toString; return (function() { return f(); }); })())();
-    todo_wine.
     ok(r === "[object Undefined]", "detached scope Object.toString returned " + r);
 
     var r = (function() { this.f = Object.prototype.toString; return this.f(); })();
     todo_wine.
     ok(r === "[object Window]", "Object.toString returned " + r);
 
+    var r = (function() { var f = Object.prototype.toString; return f(); })();
+    ok(r === "[object Undefined]", "Object.toString returned " + r);
+
     var r = ((function() { return (function() { return this; }); })())();
     ok(r === window, "detached scope this = " + r);
 });




More information about the wine-cvs mailing list