From 39d345320990ea9b581963ad1b2bdb3b456cde27 Mon Sep 17 00:00:00 2001 From: Andrew Eikum Date: Wed, 10 Oct 2012 10:16:27 -0500 Subject: [PATCH] vbscript: Undefined variables resolve as EMPTY without Option Explicit. --- dlls/vbscript/interp.c | 20 +++++++++++++++++--- dlls/vbscript/tests/run.c | 10 ++++++++++ 2 files changed, 27 insertions(+), 3 deletions(-) diff --git a/dlls/vbscript/interp.c b/dlls/vbscript/interp.c index 3a5d9b2003e..eace04188ea 100644 --- a/dlls/vbscript/interp.c +++ b/dlls/vbscript/interp.c @@ -206,7 +206,8 @@ static HRESULT lookup_identifier(exec_ctx_t *ctx, BSTR name, vbdisp_invoke_type_ return S_OK; } -static HRESULT add_dynamic_var(exec_ctx_t *ctx, const WCHAR *name, BOOL is_const, VARIANT *val, BOOL own_val) +static HRESULT add_dynamic_var(exec_ctx_t *ctx, const WCHAR *name, + BOOL is_const, VARIANT *val, BOOL own_val, VARIANT **out_var) { dynamic_var_t *new_var; vbsheap_t *heap; @@ -245,6 +246,9 @@ static HRESULT add_dynamic_var(exec_ctx_t *ctx, const WCHAR *name, BOOL is_const ctx->dynamic_vars = new_var; } + if(out_var) + *out_var = &new_var->v; + return S_OK; } @@ -526,6 +530,16 @@ static HRESULT do_icall(exec_ctx_t *ctx, VARIANT *res) } break; case REF_NONE: + if(res && !ctx->func->code_ctx->option_explicit && arg_cnt == 0) { + VARIANT v, *new; + VariantInit(&v); + hres = add_dynamic_var(ctx, identifier, FALSE, &v, FALSE, &new); + if(FAILED(hres)) + return hres; + V_VT(res) = VT_BYREF|VT_VARIANT; + V_BYREF(res) = new; + break; + } FIXME("%s not found\n", debugstr_w(identifier)); return DISP_E_UNKNOWNNAME; } @@ -653,7 +667,7 @@ static HRESULT assign_ident(exec_ctx_t *ctx, BSTR name, DISPPARAMS *dp) } TRACE("creating variable %s\n", debugstr_w(name)); - hres = add_dynamic_var(ctx, name, FALSE, dp->rgvarg, FALSE); + hres = add_dynamic_var(ctx, name, FALSE, dp->rgvarg, FALSE, NULL); } } @@ -810,7 +824,7 @@ static HRESULT interp_const(exec_ctx_t *ctx) if(FAILED(hres)) return hres; - return add_dynamic_var(ctx, arg, TRUE, val.v, val.owned); + return add_dynamic_var(ctx, arg, TRUE, val.v, val.owned, NULL); } static HRESULT interp_val(exec_ctx_t *ctx) diff --git a/dlls/vbscript/tests/run.c b/dlls/vbscript/tests/run.c index 8c541bd062a..24a3c8dd0bc 100644 --- a/dlls/vbscript/tests/run.c +++ b/dlls/vbscript/tests/run.c @@ -1780,6 +1780,8 @@ static void run_from_res(const char *name) static void run_tests(void) { + HRESULT hres; + strict_dispid_check = TRUE; parse_script_a(""); @@ -1880,6 +1882,14 @@ static void run_tests(void) "End Sub\n" "Call testsub()"); + parse_script_a("Call ok(getVT(x) = \"VT_EMPTY*\", \"getVT(x) = \" & getVT(x))\n"); + parse_script_a("Call ok(x = \"\", \"x = \" & x)\n"); + parse_script_a("x = y\n" + "Call ok(getVT(x) = \"VT_EMPTY*\", \"getVT(x) = \" & getVT(x))\n" + "Call ok(getVT(y) = \"VT_EMPTY*\", \"getVT(y) = \" & getVT(y))"); + hres = parse_script_ar("x = y(\"a\")"); + ok(FAILED(hres), "script didn't fail\n"); + run_from_res("lang.vbs"); run_from_res("api.vbs");