From: Francis De Brabandere <francisdb@gmail.com> Eval compiles the string as an expression and returns the result. ExecuteGlobal compiles and executes the string at global scope. Both Eval and ExecuteGlobal currently run in global scope. Eval should use the calling scope on Windows, but this is not yet supported. Execute is left unimplemented as it requires calling-scope support. Wine-Bug: https://bugs.winehq.org/show_bug.cgi?id=49908 Wine-Bug: https://bugs.winehq.org/show_bug.cgi?id=53962 --- dlls/vbscript/global.c | 36 ++++++++++++++++++++++++++++++++---- dlls/vbscript/tests/lang.vbs | 18 ++++++++++++++++++ dlls/vbscript/vbscript.c | 2 +- dlls/vbscript/vbscript.h | 1 + 4 files changed, 52 insertions(+), 5 deletions(-) diff --git a/dlls/vbscript/global.c b/dlls/vbscript/global.c index f38ff895ef7..e1d0251d6b2 100644 --- a/dlls/vbscript/global.c +++ b/dlls/vbscript/global.c @@ -3333,8 +3333,22 @@ static HRESULT Global_Unescape(BuiltinDisp *This, VARIANT *arg, unsigned args_cn static HRESULT Global_Eval(BuiltinDisp *This, VARIANT *arg, unsigned args_cnt, VARIANT *res) { - FIXME("\n"); - return E_NOTIMPL; + vbscode_t *code; + HRESULT hres; + + TRACE("%s\n", debugstr_variant(arg)); + + if(V_VT(arg) != VT_BSTR) { + FIXME("arg %s not supported\n", debugstr_variant(arg)); + return E_NOTIMPL; + } + + /* FIXME: Eval should use the calling scope, not global scope. */ + hres = compile_script(This->ctx, V_BSTR(arg), NULL, NULL, 0, 0, SCRIPTTEXT_ISEXPRESSION, &code); + if(FAILED(hres)) + return hres; + + return exec_global_code(This->ctx, code, res); } static HRESULT Global_Execute(BuiltinDisp *This, VARIANT *arg, unsigned args_cnt, VARIANT *res) @@ -3343,10 +3357,24 @@ static HRESULT Global_Execute(BuiltinDisp *This, VARIANT *arg, unsigned args_cnt return E_NOTIMPL; } + static HRESULT Global_ExecuteGlobal(BuiltinDisp *This, VARIANT *arg, unsigned args_cnt, VARIANT *res) { - FIXME("\n"); - return E_NOTIMPL; + vbscode_t *code; + HRESULT hres; + + TRACE("%s\n", debugstr_variant(arg)); + + if(V_VT(arg) != VT_BSTR) { + FIXME("arg %s not supported\n", debugstr_variant(arg)); + return E_NOTIMPL; + } + + hres = compile_script(This->ctx, V_BSTR(arg), NULL, NULL, 0, 0, 0, &code); + if(FAILED(hres)) + return hres; + + return exec_global_code(This->ctx, code, res); } static HRESULT Global_GetRef(BuiltinDisp *This, VARIANT *arg, unsigned args_cnt, VARIANT *res) diff --git a/dlls/vbscript/tests/lang.vbs b/dlls/vbscript/tests/lang.vbs index 12d91a16548..9dd2b15ea76 100644 --- a/dlls/vbscript/tests/lang.vbs +++ b/dlls/vbscript/tests/lang.vbs @@ -2295,4 +2295,22 @@ f1 not 1 = 0 arr (0) = 2 xor -2 +' Eval tests +Call ok(Eval("1 + 2") = 3, "Eval(""1 + 2"") = " & Eval("1 + 2")) +Call ok(Eval("""test""") = "test", "Eval(""""""test"""""") = " & Eval("""test""")) +Call ok(Eval("true") = true, "Eval(""true"") = " & Eval("true")) + +x = 5 +Call ok(Eval("x + 1") = 6, "Eval(""x + 1"") = " & Eval("x + 1")) +Call ok(Eval("x * x") = 25, "Eval(""x * x"") = " & Eval("x * x")) + +' ExecuteGlobal tests +x = 0 +ExecuteGlobal "x = 42" +Call ok(x = 42, "ExecuteGlobal x = " & x) + +ExecuteGlobal "Function evalTestFunc : evalTestFunc = 7 : End Function" +Call ok(evalTestFunc() = 7, "evalTestFunc() = " & evalTestFunc()) + + reportSuccess() diff --git a/dlls/vbscript/vbscript.c b/dlls/vbscript/vbscript.c index 715c98d32bb..8685900fa5c 100644 --- a/dlls/vbscript/vbscript.c +++ b/dlls/vbscript/vbscript.c @@ -91,7 +91,7 @@ static inline BOOL is_started(VBScript *This) || This->state == SCRIPTSTATE_DISCONNECTED; } -static HRESULT exec_global_code(script_ctx_t *ctx, vbscode_t *code, VARIANT *res) +HRESULT exec_global_code(script_ctx_t *ctx, vbscode_t *code, VARIANT *res) { ScriptDisp *obj = ctx->script_obj; function_t *func_iter, **new_funcs; diff --git a/dlls/vbscript/vbscript.h b/dlls/vbscript/vbscript.h index 6b67c8b1bc5..da825ff3b6f 100644 --- a/dlls/vbscript/vbscript.h +++ b/dlls/vbscript/vbscript.h @@ -390,6 +390,7 @@ void release_vbscode(vbscode_t*); HRESULT compile_script(script_ctx_t*,const WCHAR*,const WCHAR*,const WCHAR*,DWORD_PTR,unsigned,DWORD,vbscode_t**); HRESULT compile_procedure(script_ctx_t*,const WCHAR*,const WCHAR*,const WCHAR*,DWORD_PTR,unsigned,DWORD,class_desc_t**); HRESULT exec_script(script_ctx_t*,BOOL,function_t*,vbdisp_t*,DISPPARAMS*,VARIANT*); +HRESULT exec_global_code(script_ctx_t*,vbscode_t*,VARIANT*); void release_dynamic_var(dynamic_var_t*); named_item_t *lookup_named_item(script_ctx_t*,const WCHAR*,unsigned); void release_named_item(named_item_t*); -- GitLab https://gitlab.winehq.org/wine/wine/-/merge_requests/10368