Module: wine Branch: master Commit: 1985f330f8a8790bc3b23b999b84b7f615d6f508 URL: https://source.winehq.org/git/wine.git/?a=commit;h=1985f330f8a8790bc3b23b999...
Author: Jacek Caban jacek@codeweavers.com Date: Mon Apr 12 15:47:58 2021 +0200
jscript: Add function name to its scope chain in ES5 mode.
Signed-off-by: Jacek Caban jacek@codeweavers.com Signed-off-by: Alexandre Julliard julliard@winehq.org
---
dlls/jscript/engine.c | 8 ++++++++ dlls/mshtml/tests/documentmode.js | 36 ++++++++++++++++++++++++++++++++++++ 2 files changed, 44 insertions(+)
diff --git a/dlls/jscript/engine.c b/dlls/jscript/engine.c index 06b0fd673b3..f3d9d694b2a 100644 --- a/dlls/jscript/engine.c +++ b/dlls/jscript/engine.c @@ -661,6 +661,14 @@ static HRESULT identifier_eval(script_ctx_t *ctx, BSTR identifier, exprval_t *re if(FAILED(hres)) return hres; } + + /* ECMA-262 5.1 Edition 13 */ + if(func->name && ctx->version >= SCRIPTLANGUAGEVERSION_ES5 && !wcscmp(identifier, func->name)) { + TRACE("returning a function from scope chain\n"); + ret->type = EXPRVAL_JSVAL; + ret->u.val = jsval_obj(jsdisp_addref(scope->frame->function_instance)); + return S_OK; + } } if(scope->jsobj) hres = jsdisp_get_id(scope->jsobj, identifier, fdexNameImplicit, &id); diff --git a/dlls/mshtml/tests/documentmode.js b/dlls/mshtml/tests/documentmode.js index 75a132e83a7..82f8aae4ed9 100644 --- a/dlls/mshtml/tests/documentmode.js +++ b/dlls/mshtml/tests/documentmode.js @@ -534,3 +534,39 @@ sync_test("delete_prop", function() { todo_wine. ok(!("globalprop4" in obj), "globalprop4 is still in obj"); }); + +var func_scope_val = 1; + +sync_test("func_scope", function() { + var func_scope_val = 2; + + var f = function func_scope_val() { + return func_scope_val; + }; + + func_scope_val = 3; + if(document.documentMode < 9) { + ok(f() === 3, "f() = " + f()); + return; + } + ok(f === f(), "f() = " + f()); + + f = function func_scope_val(a) { + func_scope_val = 4; + return func_scope_val; + }; + + func_scope_val = 3; + ok(f === f(), "f() = " + f()); + ok(func_scope_val === 3, "func_scope_val = " + func_scope_val); + ok(window.func_scope_val === 1, "window.func_scope_val = " + window.func_scope_val); + + f = function func_scope_val(a) { + return (function() { return a ? func_scope_val(false) : func_scope_val; })(); + }; + + ok(f === f(true), "f(true) = " + f(true)); + + window = 1; + ok(window === window.self, "window = " + window); +});