From: Francis De Brabandere <francisdb@gmail.com> Store an integer timeout value in the host. Reject negative values with E_INVALIDARG (VBScript error 5), matching Windows. Parse //T:nn on the command line into the same state, readable from the script as WScript.Timeout. Script-visible timeout expiry (terminating the script after the configured number of seconds) is not yet implemented. --- programs/wscript/host.c | 16 ++++++++++++---- programs/wscript/main.c | 9 +++++++-- programs/wscript/tests/run.js | 11 +++++++++++ programs/wscript/tests/run.vbs | 18 ++++++++++++++++++ programs/wscript/wscript.h | 2 ++ 5 files changed, 50 insertions(+), 6 deletions(-) diff --git a/programs/wscript/host.c b/programs/wscript/host.c index 2e6ed964f63..137bf046813 100644 --- a/programs/wscript/host.c +++ b/programs/wscript/host.c @@ -41,6 +41,8 @@ VARIANT_BOOL wshInteractive = VARIANT_FALSE; #endif +LONG wshTimeout = 0; + static HRESULT to_string(VARIANT *src, BSTR *dst) { VARIANT v; @@ -271,14 +273,20 @@ static HRESULT WINAPI Host_get_BuildVersion(IHost *iface, int *out_Build) static HRESULT WINAPI Host_get_Timeout(IHost *iface, LONG *out_Timeout) { - WINE_FIXME("(%p)\n", out_Timeout); - return E_NOTIMPL; + TRACE("(%p)\n", out_Timeout); + + *out_Timeout = wshTimeout; + return S_OK; } static HRESULT WINAPI Host_put_Timeout(IHost *iface, LONG v) { - WINE_FIXME("(%ld)\n", v); - return E_NOTIMPL; + TRACE("(%ld)\n", v); + + if(v < 0) + return E_INVALIDARG; + wshTimeout = v; + return S_OK; } static HRESULT WINAPI Host_CreateObject(IHost *iface, BSTR ProgID, BSTR Prefix, diff --git a/programs/wscript/main.c b/programs/wscript/main.c index 01b09030832..4d1bfd20eb6 100644 --- a/programs/wscript/main.c +++ b/programs/wscript/main.c @@ -555,8 +555,13 @@ static BOOL set_host_properties(const WCHAR *prop) WINE_FIXME("ignoring //h:\n"); else if(wcsnicmp(prop, L"job:", 4) == 0) WINE_FIXME("ignoring //job:\n"); - else if(wcsnicmp(prop, L"t:", 2) == 0) - WINE_FIXME("ignoring //t:\n"); + else if(wcsnicmp(prop, L"t:", 2) == 0) { + WCHAR *end; + LONG t = wcstol(prop + 2, &end, 10); + if(end == prop + 2 || *end || t < 0) + return FALSE; + wshTimeout = t; + } else return FALSE; return TRUE; diff --git a/programs/wscript/tests/run.js b/programs/wscript/tests/run.js index 7433f642f14..fee49c589ec 100644 --- a/programs/wscript/tests/run.js +++ b/programs/wscript/tests/run.js @@ -54,6 +54,17 @@ try { ok(false, "expected exception"); }catch(e) {} +ok(WScript.Timeout === 0, "default Timeout = " + WScript.Timeout); +WScript.Timeout = 30; +ok(WScript.Timeout === 30, "WScript.Timeout = " + WScript.Timeout); +WScript.Timeout = 0; +ok(WScript.Timeout === 0, "WScript.Timeout = " + WScript.Timeout); +try { + WScript.Timeout = -1; + ok(false, "expected exception for negative Timeout"); +}catch(e) {} +ok(WScript.Timeout === 0, "Timeout after negative = " + WScript.Timeout); + var obj = WScript.CreateObject("Wine.Test"); obj.ok(true, "Broken WScript.CreateObject object?"); diff --git a/programs/wscript/tests/run.vbs b/programs/wscript/tests/run.vbs index 785df78d4df..c29c80d9000 100644 --- a/programs/wscript/tests/run.vbs +++ b/programs/wscript/tests/run.vbs @@ -27,4 +27,22 @@ End Sub Call ok(WScript is WSH, "WScript is not WSH") +Call ok(WScript.Timeout = 0, "default Timeout = " & WScript.Timeout) +Call ok(TypeName(WScript.Timeout) = "Long", "Timeout TypeName = " & TypeName(WScript.Timeout)) + +WScript.Timeout = 30 +Call ok(WScript.Timeout = 30, "WScript.Timeout = " & WScript.Timeout) + +WScript.Timeout = 0 +Call ok(WScript.Timeout = 0, "WScript.Timeout = " & WScript.Timeout) + +Dim prev_timeout +prev_timeout = WScript.Timeout +On Error Resume Next +Err.Clear +WScript.Timeout = -1 +Call ok(Err.Number = 5, "negative Timeout err.Number = " & Err.Number) +Call ok(WScript.Timeout = prev_timeout, "negative Timeout changed value to " & WScript.Timeout) +On Error Goto 0 + Call winetest.reportSuccess() diff --git a/programs/wscript/wscript.h b/programs/wscript/wscript.h index d624a2d851e..56371d97b0c 100644 --- a/programs/wscript/wscript.h +++ b/programs/wscript/wscript.h @@ -33,3 +33,5 @@ extern WCHAR **argums; extern int numOfArgs; extern VARIANT_BOOL wshInteractive; + +extern LONG wshTimeout; -- GitLab https://gitlab.winehq.org/wine/wine/-/merge_requests/10702