msscript: Partially implement IScriptControl::AddCode().

Signed-off-by: Jactry Zeng <jzeng@codeweavers.com>
Signed-off-by: Jacek Caban <jacek@codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard@winehq.org>
This commit is contained in:
Jactry Zeng 2019-09-23 17:17:19 +08:00 committed by Alexandre Julliard
parent 74c5fc5b32
commit 85408ea191
2 changed files with 139 additions and 22 deletions

View File

@ -977,40 +977,47 @@ static HRESULT WINAPI ScriptControl_Reset(IScriptControl *iface)
return set_script_state(This->host, SCRIPTSTATE_INITIALIZED);
}
static HRESULT parse_script_text(ScriptControl *control, BSTR script_text, DWORD flag, VARIANT *res)
{
EXCEPINFO excepinfo;
HRESULT hr;
if (!control->host || control->state != Initialized)
return E_FAIL;
if (control->host->script_state != SCRIPTSTATE_STARTED)
{
hr = set_script_state(control->host, SCRIPTSTATE_STARTED);
if (FAILED(hr))
return hr;
}
hr = IActiveScriptParse_ParseScriptText(control->host->parse, script_text, NULL,
NULL, NULL, 0, 1, flag, res, &excepinfo);
/* FIXME: more error handling */
return hr;
}
static HRESULT WINAPI ScriptControl_AddCode(IScriptControl *iface, BSTR code)
{
ScriptControl *This = impl_from_IScriptControl(iface);
FIXME("(%p)->(%s)\n", This, debugstr_w(code));
return E_NOTIMPL;
TRACE("(%p)->(%s).\n", This, debugstr_w(code));
return parse_script_text(This, code, SCRIPTTEXT_ISVISIBLE, NULL);
}
static HRESULT WINAPI ScriptControl_Eval(IScriptControl *iface, BSTR expression, VARIANT *res)
{
ScriptControl *This = impl_from_IScriptControl(iface);
EXCEPINFO excepinfo;
HRESULT hr;
FIXME("(%p)->(%s %p)\n", This, debugstr_w(expression), res);
TRACE("(%p)->(%s, %p).\n", This, debugstr_w(expression), res);
if (!res)
return E_POINTER;
V_VT(res) = VT_EMPTY;
if (!This->host || This->state != Initialized)
return E_FAIL;
if (This->host->script_state != SCRIPTSTATE_STARTED)
{
hr = set_script_state(This->host, SCRIPTSTATE_STARTED);
if (FAILED(hr))
return hr;
}
hr = IActiveScriptParse_ParseScriptText(This->host->parse, expression, NULL, NULL, NULL,
0, 1, SCRIPTTEXT_ISEXPRESSION, res, &excepinfo);
/* FIXME: more error handling */
return hr;
return parse_script_text(This, expression, SCRIPTTEXT_ISEXPRESSION, res);
}
static HRESULT WINAPI ScriptControl_ExecuteStatement(IScriptControl *iface, BSTR statement)

View File

@ -144,6 +144,8 @@ static HRESULT WINAPI ActiveScriptParse_AddScriptlet(IActiveScriptParse *iface,
return E_NOTIMPL;
}
static DWORD parse_flags = 0;
static HRESULT WINAPI ActiveScriptParse_ParseScriptText(IActiveScriptParse *iface,
LPCOLESTR pstrCode, LPCOLESTR pstrItemName, IUnknown *punkContext,
LPCOLESTR pstrDelimiter, CTXARG_T dwSourceContextCookie, ULONG ulStartingLine,
@ -155,9 +157,13 @@ static HRESULT WINAPI ActiveScriptParse_ParseScriptText(IActiveScriptParse *ifac
ok(!pstrDelimiter, "got wrong pointer: %p.\n", pstrDelimiter);
ok(!dwSourceContextCookie, "got wrong value: %s.\n", wine_dbgstr_longlong(dwSourceContextCookie));
ok(ulStartingLine == 1, "got wrong value: %d.\n", ulStartingLine);
ok(dwFlags == SCRIPTTEXT_ISEXPRESSION, "got wrong flags: %x.\n", dwFlags);
ok(!!pvarResult, "got wrong pointer: %p.\n", pvarResult);
ok(!!pexcepinfo, "got wrong pointer: %p.\n", pexcepinfo);
ok(dwFlags == parse_flags, "got wrong flags: %x.\n", dwFlags);
if (parse_flags == SCRIPTTEXT_ISEXPRESSION)
ok(!!pvarResult, "got wrong pointer: %p.\n", pvarResult);
else
ok(!pvarResult, "got wrong pointer: %p.\n", pvarResult);
CHECK_EXPECT(ParseScriptText);
return S_OK;
}
@ -1516,6 +1522,7 @@ static void test_IScriptControl_Eval(void)
SET_EXPECT(SetScriptState_STARTED);
SET_EXPECT(ParseScriptText);
parse_flags = SCRIPTTEXT_ISEXPRESSION;
script_str = a2bstr("var1 = 1 + 1");
V_VT(&var) = VT_NULL;
V_I4(&var) = 0xdeadbeef;
@ -1566,6 +1573,108 @@ static void test_IScriptControl_Eval(void)
}
}
static void test_IScriptControl_AddCode(void)
{
BSTR code_str, language;
IScriptControl *sc;
VARIANT var;
HRESULT hr;
hr = CoCreateInstance(&CLSID_ScriptControl, NULL, CLSCTX_INPROC_SERVER | CLSCTX_INPROC_HANDLER,
&IID_IScriptControl, (void **)&sc);
ok(hr == S_OK, "Failed to create IScriptControl interface: 0x%08x.\n", hr);
code_str = a2bstr("1 + 1");
hr = IScriptControl_AddCode(sc, code_str);
ok(hr == E_FAIL, "IScriptControl_AddCode returned: 0x%08x.\n", hr);
SysFreeString(code_str);
hr = IScriptControl_AddCode(sc, NULL);
ok(hr == E_FAIL, "IScriptControl_AddCode returned: 0x%08x.\n", hr);
language = a2bstr("jscript");
hr = IScriptControl_put_Language(sc, language);
ok(hr == S_OK, "IScriptControl_put_Language failed: 0x%08x.\n", hr);
SysFreeString(language);
code_str = a2bstr("1 + 1");
hr = IScriptControl_AddCode(sc, code_str);
ok(hr == S_OK, "IScriptControl_AddCode failed: 0x%08x.\n", hr);
SysFreeString(code_str);
todo_wine CHECK_ERROR(sc, 0);
code_str = a2bstr("invalid syntax");
hr = IScriptControl_AddCode(sc, code_str);
todo_wine ok(hr == 0x800a03ec, "IScriptControl_AddCode returned: 0x%08x.\n", hr);
SysFreeString(code_str);
todo_wine CHECK_ERROR(sc, 1004);
IScriptControl_Release(sc);
/* custom script engine */
if (have_custom_engine)
{
hr = CoCreateInstance(&CLSID_ScriptControl, NULL, CLSCTX_INPROC_SERVER | CLSCTX_INPROC_HANDLER,
&IID_IScriptControl, (void **)&sc);
ok(hr == S_OK, "Failed to create IScriptControl interface: 0x%08x.\n", hr);
SET_EXPECT(CreateInstance);
SET_EXPECT(SetInterfaceSafetyOptions);
SET_EXPECT(SetScriptSite);
SET_EXPECT(QI_IActiveScriptParse);
SET_EXPECT(InitNew);
language = a2bstr("testscript");
hr = IScriptControl_put_Language(sc, language);
ok(hr == S_OK, "IScriptControl_put_Language failed: 0x%08x.\n", hr);
SysFreeString(language);
CHECK_CALLED(CreateInstance);
CHECK_CALLED(SetInterfaceSafetyOptions);
CHECK_CALLED(SetScriptSite);
CHECK_CALLED(QI_IActiveScriptParse);
CHECK_CALLED(InitNew);
SET_EXPECT(SetScriptState_STARTED);
SET_EXPECT(ParseScriptText);
parse_flags = SCRIPTTEXT_ISVISIBLE;
code_str = a2bstr("1 + 1");
hr = IScriptControl_AddCode(sc, code_str);
ok(hr == S_OK, "IScriptControl_AddCode failed: 0x%08x.\n", hr);
SysFreeString(code_str);
CHECK_CALLED(SetScriptState_STARTED);
CHECK_CALLED(ParseScriptText);
SET_EXPECT(ParseScriptText);
code_str = a2bstr("0x100");
hr = IScriptControl_AddCode(sc, code_str);
ok(hr == S_OK, "IScriptControl_AddCode failed: 0x%08x.\n", hr);
SysFreeString(code_str);
CHECK_CALLED(ParseScriptText);
/* Call Eval() after AddCode() for checking if it will call SetScriptState() again. */
SET_EXPECT(ParseScriptText);
parse_flags = SCRIPTTEXT_ISEXPRESSION;
code_str = a2bstr("var2 = 10 + var1");
V_VT(&var) = VT_NULL;
V_I4(&var) = 0xdeadbeef;
hr = IScriptControl_Eval(sc, code_str, &var);
ok(hr == S_OK, "IScriptControl_Eval failed: 0x%08x.\n", hr);
ok((V_VT(&var) == VT_EMPTY) && (V_I4(&var) == 0xdeadbeef), "V_VT(var) = %d, V_I4(var) = %d.\n",
V_VT(&var), V_I4(&var));
SysFreeString(code_str);
CHECK_CALLED(ParseScriptText);
IActiveScriptSite_Release(site);
SET_EXPECT(Close);
IScriptControl_Release(sc);
CHECK_CALLED(Close);
}
}
START_TEST(msscript)
{
IUnknown *unk;
@ -1600,6 +1709,7 @@ START_TEST(msscript)
test_UseSafeSubset();
test_State();
test_IScriptControl_Eval();
test_IScriptControl_AddCode();
init_registry(FALSE);