[PATCH 0/2] MR10980: vbscript: Propagate errors from a script-invoked function reference.
FuncRef_Invoke always ran the referenced function as an external caller, so an error raised through a GetRef reference was reported to the host via IActiveScriptSite::OnScriptError even when the reference was called from within running script. A direct call propagates the error as an HRESULT to the caller's On Error Resume Next instead. Treat the reference as an external caller only when the engine is not already executing script. -- https://gitlab.winehq.org/wine/wine/-/merge_requests/10980
From: Francis De Brabandere <francisdb@gmail.com> An error raised inside a function obtained from GetRef and invoked from script under the caller's On Error Resume Next must propagate to that caller, not be reported to the host via IActiveScriptSite::OnScriptError. --- dlls/vbscript/tests/run.c | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/dlls/vbscript/tests/run.c b/dlls/vbscript/tests/run.c index decde599d0c..8f7eb301c09 100644 --- a/dlls/vbscript/tests/run.c +++ b/dlls/vbscript/tests/run.c @@ -3540,6 +3540,32 @@ static void test_redefine_scope(void) } } +static void test_getref_error_reporting(void) +{ + /* An error raised inside a function reference obtained from GetRef, when + * the reference is called from script under the caller's On Error Resume + * Next, must propagate to that caller rather than be reported to the host. */ + static const WCHAR *src = + L"Dim cb : Set cb = GetRef(\"RaisesError\")\n" + L"Sub CallIndirect\n" + L" On Error Resume Next\n" + L" cb\n" + L" On Error Goto 0\n" + L"End Sub\n" + L"Sub RaisesError\n" + L" Err.Raise 5\n" + L"End Sub\n" + L"CallIndirect\n"; + HRESULT hres; + + SET_EXPECT(OnScriptError); + hres = parse_script_wr(src); + ok(hres == S_OK, "parse_script_wr returned %08lx\n", hres); + todo_wine ok(!called_OnScriptError, + "error in a GetRef reference under the caller's On Error Resume Next was reported to the host\n"); + CLEAR_CALLED(OnScriptError); +} + static void test_msgbox(void) { HRESULT hres; @@ -4237,6 +4263,7 @@ static void run_tests(void) test_option_explicit_errors(); test_parse_errors(); test_redefine_scope(); + test_getref_error_reporting(); test_parse_context(); test_callbacks(); test_multiple_parse(); -- GitLab https://gitlab.winehq.org/wine/wine/-/merge_requests/10980
From: Francis De Brabandere <francisdb@gmail.com> FuncRef_Invoke always ran the referenced function as an external caller, so an error raised through a GetRef reference was reported to the host via IActiveScriptSite::OnScriptError even when the reference was called from within running script. A direct call propagates the error as an HRESULT to the caller's On Error Resume Next instead. Treat the reference as an external caller only when the engine is not already executing script. --- dlls/vbscript/tests/run.c | 2 +- dlls/vbscript/vbdisp.c | 6 +++++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/dlls/vbscript/tests/run.c b/dlls/vbscript/tests/run.c index 8f7eb301c09..42cf2ecd7d6 100644 --- a/dlls/vbscript/tests/run.c +++ b/dlls/vbscript/tests/run.c @@ -3561,7 +3561,7 @@ static void test_getref_error_reporting(void) SET_EXPECT(OnScriptError); hres = parse_script_wr(src); ok(hres == S_OK, "parse_script_wr returned %08lx\n", hres); - todo_wine ok(!called_OnScriptError, + ok(!called_OnScriptError, "error in a GetRef reference under the caller's On Error Resume Next was reported to the host\n"); CLEAR_CALLED(OnScriptError); } diff --git a/dlls/vbscript/vbdisp.c b/dlls/vbscript/vbdisp.c index 554d410b57e..3d31542a046 100644 --- a/dlls/vbscript/vbdisp.c +++ b/dlls/vbscript/vbdisp.c @@ -857,7 +857,11 @@ static HRESULT WINAPI FuncRef_Invoke(IDispatch *iface, DISPID dispIdMember, REFI if(dispIdMember != DISPID_VALUE) return DISP_E_MEMBERNOTFOUND; - return exec_script(This->ctx, TRUE, This->func, NULL, pDispParams, pVarResult); + /* When the reference is invoked from within running script (e.g. under the + * caller's On Error Resume Next), the error must propagate back to that + * caller as an HRESULT rather than be reported to the host. Only a call + * originating outside the engine acts as an external caller. */ + return exec_script(This->ctx, !This->ctx->current_exec, This->func, NULL, pDispParams, pVarResult); } static const IDispatchVtbl FuncRefVtbl = { -- GitLab https://gitlab.winehq.org/wine/wine/-/merge_requests/10980
participants (2)
-
Francis De Brabandere -
Francis De Brabandere (@francisdb)