jscript: Don't allow function execution if script engine is not in started state.

This commit is contained in:
Jacek Caban 2015-01-13 21:45:56 +01:00 committed by Alexandre Julliard
parent 6bad16363b
commit 091738ffdf
2 changed files with 79 additions and 10 deletions

View File

@ -205,6 +205,11 @@ static HRESULT invoke_source(script_ctx_t *ctx, FunctionInstance *function, IDis
scope_chain_t *scope; scope_chain_t *scope;
HRESULT hres; HRESULT hres;
if(ctx->state == SCRIPTSTATE_UNINITIALIZED || ctx->state == SCRIPTSTATE_CLOSED) {
WARN("Script engine state does not allow running code.\n");
return E_UNEXPECTED;
}
if(!function->func_code) { if(!function->func_code) {
FIXME("no source\n"); FIXME("no source\n");
return E_FAIL; return E_FAIL;

View File

@ -1908,7 +1908,7 @@ static void test_isvisible(BOOL global_members)
IActiveScriptParse_Release(parser); IActiveScriptParse_Release(parser);
} }
static HRESULT parse_script_expr(const char *expr, VARIANT *res) static HRESULT parse_script_expr(const char *expr, VARIANT *res, IActiveScript **engine_ret)
{ {
IActiveScriptParse *parser; IActiveScriptParse *parser;
IActiveScript *engine; IActiveScript *engine;
@ -1939,9 +1939,14 @@ static HRESULT parse_script_expr(const char *expr, VARIANT *res)
hres = IActiveScriptParse_ParseScriptText(parser, str, NULL, NULL, NULL, 0, 0, SCRIPTTEXT_ISEXPRESSION, res, NULL); hres = IActiveScriptParse_ParseScriptText(parser, str, NULL, NULL, NULL, 0, 0, SCRIPTTEXT_ISEXPRESSION, res, NULL);
SysFreeString(str); SysFreeString(str);
IActiveScript_Release(engine);
IActiveScriptParse_Release(parser); IActiveScriptParse_Release(parser);
if(engine_ret) {
*engine_ret = engine;
}else {
IActiveScript_Close(engine);
IActiveScript_Release(engine);
}
return hres; return hres;
} }
@ -1952,7 +1957,7 @@ static void test_default_value(void)
VARIANT v; VARIANT v;
HRESULT hres; HRESULT hres;
hres = parse_script_expr("new Date()", &v); hres = parse_script_expr("new Date()", &v, NULL);
ok(hres == S_OK, "parse_script_expr failed: %08x\n", hres); ok(hres == S_OK, "parse_script_expr failed: %08x\n", hres);
ok(V_VT(&v) == VT_DISPATCH, "V_VT(v) = %d\n", V_VT(&v)); ok(V_VT(&v) == VT_DISPATCH, "V_VT(v) = %d\n", V_VT(&v));
disp = V_DISPATCH(&v); disp = V_DISPATCH(&v);
@ -1976,38 +1981,38 @@ static void test_script_exprs(void)
testing_expr = TRUE; testing_expr = TRUE;
hres = parse_script_expr("true", &v); hres = parse_script_expr("true", &v, NULL);
ok(hres == S_OK, "parse_script_expr failed: %08x\n", hres); ok(hres == S_OK, "parse_script_expr failed: %08x\n", hres);
ok(V_VT(&v) == VT_BOOL, "V_VT(v) = %d\n", V_VT(&v)); ok(V_VT(&v) == VT_BOOL, "V_VT(v) = %d\n", V_VT(&v));
ok(V_BOOL(&v) == VARIANT_TRUE, "V_BOOL(v) = %x\n", V_BOOL(&v)); ok(V_BOOL(&v) == VARIANT_TRUE, "V_BOOL(v) = %x\n", V_BOOL(&v));
hres = parse_script_expr("false, true", &v); hres = parse_script_expr("false, true", &v, NULL);
ok(hres == S_OK, "parse_script_expr failed: %08x\n", hres); ok(hres == S_OK, "parse_script_expr failed: %08x\n", hres);
ok(V_VT(&v) == VT_BOOL, "V_VT(v) = %d\n", V_VT(&v)); ok(V_VT(&v) == VT_BOOL, "V_VT(v) = %d\n", V_VT(&v));
ok(V_BOOL(&v) == VARIANT_TRUE, "V_BOOL(v) = %x\n", V_BOOL(&v)); ok(V_BOOL(&v) == VARIANT_TRUE, "V_BOOL(v) = %x\n", V_BOOL(&v));
SET_EXPECT(global_success_d); SET_EXPECT(global_success_d);
SET_EXPECT(global_success_i); SET_EXPECT(global_success_i);
hres = parse_script_expr("reportSuccess(); true", &v); hres = parse_script_expr("reportSuccess(); true", &v, NULL);
ok(hres == S_OK, "parse_script_expr failed: %08x\n", hres); ok(hres == S_OK, "parse_script_expr failed: %08x\n", hres);
ok(V_VT(&v) == VT_BOOL, "V_VT(v) = %d\n", V_VT(&v)); ok(V_VT(&v) == VT_BOOL, "V_VT(v) = %d\n", V_VT(&v));
ok(V_BOOL(&v) == VARIANT_TRUE, "V_BOOL(v) = %x\n", V_BOOL(&v)); ok(V_BOOL(&v) == VARIANT_TRUE, "V_BOOL(v) = %x\n", V_BOOL(&v));
CHECK_CALLED(global_success_d); CHECK_CALLED(global_success_d);
CHECK_CALLED(global_success_i); CHECK_CALLED(global_success_i);
hres = parse_script_expr("if(false) true", &v); hres = parse_script_expr("if(false) true", &v, NULL);
ok(hres == S_OK, "parse_script_expr failed: %08x\n", hres); ok(hres == S_OK, "parse_script_expr failed: %08x\n", hres);
ok(V_VT(&v) == VT_EMPTY, "V_VT(v) = %d\n", V_VT(&v)); ok(V_VT(&v) == VT_EMPTY, "V_VT(v) = %d\n", V_VT(&v));
hres = parse_script_expr("return testPropGet", &v); hres = parse_script_expr("return testPropGet", &v, NULL);
ok(hres == 0x800a03fa, "parse_script_expr failed: %08x\n", hres); ok(hres == 0x800a03fa, "parse_script_expr failed: %08x\n", hres);
hres = parse_script_expr("reportSuccess(); return true", &v); hres = parse_script_expr("reportSuccess(); return true", &v, NULL);
ok(hres == 0x800a03fa, "parse_script_expr failed: %08x\n", hres); ok(hres == 0x800a03fa, "parse_script_expr failed: %08x\n", hres);
SET_EXPECT(global_success_d); SET_EXPECT(global_success_d);
SET_EXPECT(global_success_i); SET_EXPECT(global_success_i);
hres = parse_script_expr("reportSuccess(); true", NULL); hres = parse_script_expr("reportSuccess(); true", NULL, NULL);
ok(hres == S_OK, "parse_script_expr failed: %08x\n", hres); ok(hres == S_OK, "parse_script_expr failed: %08x\n", hres);
CHECK_CALLED(global_success_d); CHECK_CALLED(global_success_d);
CHECK_CALLED(global_success_i); CHECK_CALLED(global_success_i);
@ -2017,6 +2022,64 @@ static void test_script_exprs(void)
testing_expr = FALSE; testing_expr = FALSE;
} }
static void test_invokeex(void)
{
DISPID func_id, prop_id;
DISPPARAMS dp = {NULL};
IActiveScript *script;
IDispatchEx *dispex;
VARIANT v;
BSTR str;
HRESULT hres;
hres = parse_script_expr("var o = {func: function() {return 3;}, prop: 6}; o", &v, &script);
ok(hres == S_OK, "parse_script_expr failed: %08x\n", hres);
ok(V_VT(&v) == VT_DISPATCH, "V_VT(v) = %d\n", V_VT(&v));
hres = IDispatch_QueryInterface(V_DISPATCH(&v), &IID_IDispatchEx, (void**)&dispex);
ok(hres == S_OK, "Could not get IDispatchEx iface: %08x\n", hres);
VariantClear(&v);
str = a2bstr("func");
hres = IDispatchEx_GetDispID(dispex, str, 0, &func_id);
SysFreeString(str);
ok(hres == S_OK, "GetDispID failed: %08x\n", hres);
str = a2bstr("prop");
hres = IDispatchEx_GetDispID(dispex, str, 0, &prop_id);
SysFreeString(str);
ok(hres == S_OK, "GetDispID failed: %08x\n", hres);
hres = IDispatchEx_InvokeEx(dispex, func_id, 0, DISPATCH_METHOD, &dp, &v, NULL, NULL);
ok(hres == S_OK, "InvokeEx failed: %08x\n", hres);
ok(V_VT(&v) == VT_I4, "V_VT(v) = %d\n", V_VT(&v));
ok(V_I4(&v) == 3, "V_I4(v) = %d\n", V_I4(&v));
hres = IDispatchEx_InvokeEx(dispex, prop_id, 0, DISPATCH_PROPERTYGET, &dp, &v, NULL, NULL);
ok(hres == S_OK, "InvokeEx failed: %08x\n", hres);
ok(V_VT(&v) == VT_I4, "V_VT(v) = %d\n", V_VT(&v));
ok(V_I4(&v) == 6, "V_I4(v) = %d\n", V_I4(&v));
hres = IActiveScript_SetScriptState(script, SCRIPTSTATE_UNINITIALIZED);
ok(hres == S_OK, "SetScriptState(SCRIPTSTATE_STARTED) failed: %08x\n", hres);
str = a2bstr("func");
hres = IDispatchEx_GetDispID(dispex, str, 0, &func_id);
SysFreeString(str);
ok(hres == S_OK, "GetDispID failed: %08x\n", hres);
hres = IDispatchEx_InvokeEx(dispex, func_id, 0, DISPATCH_METHOD, &dp, &v, NULL, NULL);
ok(hres == E_UNEXPECTED || broken(hres == 0x800a1393), "InvokeEx failed: %08x\n", hres);
hres = IDispatchEx_InvokeEx(dispex, prop_id, 0, DISPATCH_PROPERTYGET, &dp, &v, NULL, NULL);
ok(hres == S_OK, "InvokeEx failed: %08x\n", hres);
ok(V_VT(&v) == VT_I4, "V_VT(v) = %d\n", V_VT(&v));
ok(V_I4(&v) == 6, "V_I4(v) = %d\n", V_I4(&v));
IDispatchEx_Release(dispex);
IActiveScript_Release(script);
}
struct bom_test struct bom_test
{ {
WCHAR str[1024]; WCHAR str[1024];
@ -2335,6 +2398,7 @@ static BOOL run_tests(void)
ok(hres != S_OK, "ParseScriptText have not failed\n"); ok(hres != S_OK, "ParseScriptText have not failed\n");
test_script_exprs(); test_script_exprs();
test_invokeex();
parse_script_with_error_a( parse_script_with_error_a(
"?", "?",