static HRESULT init_engine(IActiveScript *script, IActiveScriptParse *parser) { HRESULT hres; if(!load_typelib()) return FALSE; hres = IActiveScript_SetScriptSite(script, &script_site); if(FAILED(hres)) return FALSE; hres = IActiveScriptParse_InitNew(parser); if(FAILED(hres)) return FALSE; hres = IActiveScript_AddNamedItem(script, wscriptW, SCRIPTITEM_ISVISIBLE); if(FAILED(hres)) return FALSE; hres = IActiveScript_AddNamedItem(script, wshW, SCRIPTITEM_ISVISIBLE); if(FAILED(hres)) return FALSE; hres = IActiveScript_SetScriptState(script, SCRIPTSTATE_INITIALIZED); return SUCCEEDED(hres); }
static IActiveScriptParse *create_script(BOOL skip_tests, BOOL use_sec_mgr) { IActiveScriptParse *parser; IActiveScript *script; HRESULT hres; QS_SecMgr_hres = S_OK; ProcessUrlAction_hres = S_OK; ProcessUrlAction_policy = URLPOLICY_ALLOW; CreateInstance_hres = S_OK; QueryCustomPolicy_hres = S_OK; QueryCustomPolicy_psize = sizeof(DWORD); QueryCustomPolicy_policy = URLPOLICY_ALLOW; QI_IDispatch_hres = S_OK; SetSite_hres = S_OK; hres = CoCreateInstance(&CLSID_JScript, NULL, CLSCTX_INPROC_SERVER|CLSCTX_INPROC_HANDLER, &IID_IActiveScript, (void**)&script); if(!skip_tests) ok(hres == S_OK, "CoCreateInstance failed: %08x\n", hres); if(FAILED(hres)) return NULL; if(!skip_tests) set_safety_options((IUnknown*)script, use_sec_mgr); hres = IActiveScript_QueryInterface(script, &IID_IActiveScriptParse, (void**)&parser); ok(hres == S_OK, "Could not get IActiveScriptParse: %08x\n", hres); hres = IActiveScriptParse64_InitNew(parser); ok(hres == S_OK, "InitNew failed: %08x\n", hres); hres = IActiveScript_SetScriptSite(script, &ActiveScriptSite); ok(hres == S_OK, "SetScriptSite failed: %08x\n", hres); hres = IActiveScript_AddNamedItem(script, testW, SCRIPTITEM_ISVISIBLE|SCRIPTITEM_ISSOURCE|SCRIPTITEM_GLOBALMEMBERS); ok(hres == S_OK, "AddNamedItem failed: %08x\n", hres); hres = IActiveScript_SetScriptState(script, SCRIPTSTATE_STARTED); ok(hres == S_OK, "SetScriptState(SCRIPTSTATE_STARTED) failed: %08x\n", hres); IActiveScript_Release(script); if(!skip_tests) { parse_script_a(parser, "function testException(func, type, number) {\n" " try {\n" " func();\n" " }catch(e) {\n" " ok(e.name === type, 'e.name = ' + e.name + ', expected ' + type)\n" " ok(e.number === number, 'e.number = ' + e.number + ', expected ' + number);\n" " return;\n" " }\n" " ok(false, 'exception expected');\n" "}"); } return parser; }
static IActiveScriptParse *create_script(void) { IActiveScriptParse *parser; IActiveScript *script; HRESULT hres; hres = CoCreateInstance(&CLSID_JScript, NULL, CLSCTX_INPROC_SERVER|CLSCTX_INPROC_HANDLER, &IID_IActiveScript, (void**)&script); if(FAILED(hres)) return NULL; hres = IActiveScript_QueryInterface(script, &IID_IActiveScriptParse, (void**)&parser); ok(hres == S_OK, "Could not get IActiveScriptParse: %08x\n", hres); hres = IActiveScriptParse64_InitNew(parser); ok(hres == S_OK, "InitNew failed: %08x\n", hres); hres = IActiveScript_SetScriptSite(script, &ActiveScriptSite); ok(hres == S_OK, "SetScriptSite failed: %08x\n", hres); hres = IActiveScript_AddNamedItem(script, testW, SCRIPTITEM_ISVISIBLE|SCRIPTITEM_ISSOURCE|SCRIPTITEM_GLOBALMEMBERS); ok(hres == S_OK, "AddNamedItem failed: %08x\n", hres); hres = IActiveScript_SetScriptState(script, SCRIPTSTATE_STARTED); ok(hres == S_OK, "SetScriptState(SCRIPTSTATE_STARTED) failed: %08x\n", hres); IActiveScript_Release(script); return parser; }
static void test_gc(void) { IActiveScriptParse *parser; IActiveScript *engine; BSTR src; HRESULT hres; strict_dispid_check = FALSE; engine = create_script(); if(!engine) return; hres = IActiveScript_QueryInterface(engine, &IID_IActiveScriptParse, (void**)&parser); ok(hres == S_OK, "Could not get IActiveScriptParse: %08x\n", hres); hres = IActiveScriptParse64_InitNew(parser); ok(hres == S_OK, "InitNew failed: %08x\n", hres); hres = IActiveScript_SetScriptSite(engine, &ActiveScriptSite); ok(hres == S_OK, "SetScriptSite failed: %08x\n", hres); hres = IActiveScript_AddNamedItem(engine, testW, SCRIPTITEM_ISVISIBLE|SCRIPTITEM_ISSOURCE|SCRIPTITEM_GLOBALMEMBERS); ok(hres == S_OK, "AddNamedItem failed: %08x\n", hres); hres = IActiveScript_SetScriptState(engine, SCRIPTSTATE_STARTED); ok(hres == S_OK, "SetScriptState(SCRIPTSTATE_STARTED) failed: %08x\n", hres); src = a2bstr( "class C\n" " Public ref\n" " Public Sub Class_Terminate\n" " Call reportSuccess()\n" " End Sub\n" "End Class\n" "Dim x\n" "set x = new C\n" "set x.ref = x\n" "set x = nothing\n"); hres = IActiveScriptParse64_ParseScriptText(parser, src, NULL, NULL, NULL, 0, 0, 0, NULL, NULL); ok(hres == S_OK, "ParseScriptText failed: %08x\n", hres); SysFreeString(src); SET_EXPECT(global_success_d); SET_EXPECT(global_success_i); IActiveScript_Close(engine); CHECK_CALLED(global_success_d); CHECK_CALLED(global_success_i); IActiveScript_Release(engine); IUnknown_Release(parser); }
static HRESULT parse_script(DWORD flags, BSTR script_str) { IActiveScriptParse *parser; IActiveScript *engine; IDispatch *script_disp; HRESULT hres; engine = create_script(); if(!engine) return S_OK; hres = IActiveScript_QueryInterface(engine, &IID_IActiveScriptParse, (void**)&parser); ok(hres == S_OK, "Could not get IActiveScriptParse: %08x\n", hres); if (FAILED(hres)) { IActiveScript_Release(engine); return hres; } hres = IActiveScriptParse64_InitNew(parser); ok(hres == S_OK, "InitNew failed: %08x\n", hres); hres = IActiveScript_SetScriptSite(engine, &ActiveScriptSite); ok(hres == S_OK, "SetScriptSite failed: %08x\n", hres); hres = IActiveScript_AddNamedItem(engine, testW, SCRIPTITEM_ISVISIBLE|SCRIPTITEM_ISSOURCE|flags); ok(hres == S_OK, "AddNamedItem failed: %08x\n", hres); hres = IActiveScript_SetScriptState(engine, SCRIPTSTATE_STARTED); ok(hres == S_OK, "SetScriptState(SCRIPTSTATE_STARTED) failed: %08x\n", hres); hres = IActiveScript_GetScriptDispatch(engine, NULL, &script_disp); ok(hres == S_OK, "GetScriptDispatch failed: %08x\n", hres); ok(script_disp != NULL, "script_disp == NULL\n"); ok(script_disp != (IDispatch*)&Global, "script_disp == Global\n"); hres = IActiveScriptParse64_ParseScriptText(parser, script_str, NULL, NULL, NULL, 0, 0, 0, NULL, NULL); IActiveScript_Close(engine); IDispatch_Release(script_disp); IActiveScript_Release(engine); IUnknown_Release(parser); return hres; }
static IActiveScriptParse *create_script(BOOL use_sec_mgr) { IActiveScriptParse *parser; IActiveScript *script; HRESULT hres; QS_SecMgr_hres = S_OK; ProcessUrlAction_hres = S_OK; ProcessUrlAction_policy = URLPOLICY_ALLOW; CreateInstance_hres = S_OK; QueryCustomPolicy_hres = S_OK; QueryCustomPolicy_psize = sizeof(DWORD); QueryCustomPolicy_policy = URLPOLICY_ALLOW; QI_IDispatch_hres = S_OK; QI_IObjectWithSite_hres = S_OK; SetSite_hres = S_OK; hres = CoCreateInstance(&CLSID_VBScript, NULL, CLSCTX_INPROC_SERVER|CLSCTX_INPROC_HANDLER, &IID_IActiveScript, (void**)&script); ok(hres == S_OK, "CoCreateInstance failed: %08x\n", hres); if(FAILED(hres)) return NULL; set_safety_options((IUnknown*)script, use_sec_mgr); hres = IActiveScript_QueryInterface(script, &IID_IActiveScriptParse, (void**)&parser); ok(hres == S_OK, "Could not get IActiveScriptParse: %08x\n", hres); hres = IActiveScriptParse_InitNew(parser); ok(hres == S_OK, "InitNew failed: %08x\n", hres); hres = IActiveScript_SetScriptSite(script, &ActiveScriptSite); ok(hres == S_OK, "SetScriptSite failed: %08x\n", hres); hres = IActiveScript_AddNamedItem(script, testW, SCRIPTITEM_ISVISIBLE|SCRIPTITEM_ISSOURCE|SCRIPTITEM_GLOBALMEMBERS); ok(hres == S_OK, "AddNamedItem failed: %08x\n", hres); hres = IActiveScript_SetScriptState(script, SCRIPTSTATE_STARTED); ok(hres == S_OK, "SetScriptState(SCRIPTSTATE_STARTED) failed: %08x\n", hres); IActiveScript_Release(script); return parser; }
/* * Call a script. */ DWORD call_script(MSIHANDLE hPackage, INT type, LPCWSTR script, LPCWSTR function, LPCWSTR action) { HRESULT hr; IActiveScript *pActiveScript = NULL; IActiveScriptParse *pActiveScriptParse = NULL; MsiActiveScriptSite *pActiveScriptSite = NULL; IDispatch *pDispatch = NULL; DISPPARAMS dispparamsNoArgs = {NULL, NULL, 0, 0}; DISPID dispid; CLSID clsid; VARIANT var; /* Return success by default (if Windows Script not installed) - not native behavior. This * should be here until we implement wine scripting. */ DWORD ret = ERROR_SUCCESS; CoInitialize(NULL); /* Create MsiActiveScriptSite object */ hr = create_ActiveScriptSite(NULL, (void **)&pActiveScriptSite); if (hr != S_OK) goto done; /* Create an installer object */ hr = create_msiserver(NULL, (LPVOID *)&pActiveScriptSite->pInstaller); if (hr != S_OK) goto done; /* Create a session object */ hr = create_session(hPackage, pActiveScriptSite->pInstaller, &pActiveScriptSite->pSession); if (hr != S_OK) goto done; /* Create the scripting engine */ if ((type & 7) == msidbCustomActionTypeJScript) hr = CLSIDFromProgID(szJScript, &clsid); else if ((type & 7) == msidbCustomActionTypeVBScript) hr = CLSIDFromProgID(szVBScript, &clsid); else { ERR("Unknown script type %d\n", type); goto done; } if (FAILED(hr)) { ERR("Could not find CLSID for Windows Script\n"); goto done; } hr = CoCreateInstance(&clsid, NULL, CLSCTX_INPROC_SERVER, &IID_IActiveScript, (void **)&pActiveScript); if (FAILED(hr)) { ERR("Could not instantiate class for Windows Script\n"); goto done; } /* If we got this far, Windows Script is installed, so don't return success by default anymore */ ret = ERROR_INSTALL_FAILURE; /* Get the IActiveScriptParse engine interface */ hr = IActiveScript_QueryInterface(pActiveScript, &IID_IActiveScriptParse, (void **)&pActiveScriptParse); if (FAILED(hr)) goto done; /* Give our host to the engine */ hr = IActiveScript_SetScriptSite(pActiveScript, (IActiveScriptSite *)pActiveScriptSite); if (FAILED(hr)) goto done; /* Initialize the script engine */ hr = IActiveScriptParse64_InitNew(pActiveScriptParse); if (FAILED(hr)) goto done; /* Add the session object */ hr = IActiveScript_AddNamedItem(pActiveScript, szSession, SCRIPTITEM_ISVISIBLE); /* Pass the script to the engine */ hr = IActiveScriptParse64_ParseScriptText(pActiveScriptParse, script, NULL, NULL, NULL, 0, 0, 0L, NULL, NULL); if (FAILED(hr)) goto done; /* Start processing the script */ hr = IActiveScript_SetScriptState(pActiveScript, SCRIPTSTATE_CONNECTED); if (FAILED(hr)) goto done; /* Call a function if necessary through the IDispatch interface */ if (function != NULL && strlenW(function) > 0) { TRACE("Calling function %s\n", debugstr_w(function)); hr = IActiveScript_GetScriptDispatch(pActiveScript, NULL, &pDispatch); if (FAILED(hr)) goto done; hr = IDispatch_GetIDsOfNames(pDispatch, &IID_NULL, (WCHAR **)&function, 1,LOCALE_USER_DEFAULT, &dispid); if (FAILED(hr)) goto done; hr = IDispatch_Invoke(pDispatch, dispid, &IID_NULL, LOCALE_USER_DEFAULT, DISPATCH_METHOD, &dispparamsNoArgs, &var, NULL, NULL); if (FAILED(hr)) goto done; /* Check return value, if it's not IDOK we failed */ hr = VariantChangeType(&var, &var, 0, VT_I4); if (FAILED(hr)) goto done; if (V_I4(&var) == IDOK) ret = ERROR_SUCCESS; else ret = ERROR_INSTALL_FAILURE; VariantClear(&var); } else { /* If no function to be called, MSI behavior is to succeed */ ret = ERROR_SUCCESS; } done: /* Free everything that needs to be freed */ if (pDispatch) IDispatch_Release(pDispatch); if (pActiveScript) IActiveScriptSite_Release(pActiveScript); if (pActiveScriptSite && pActiveScriptSite->pSession) IUnknown_Release((IUnknown *)pActiveScriptSite->pSession); if (pActiveScriptSite && pActiveScriptSite->pInstaller) IUnknown_Release((IUnknown *)pActiveScriptSite->pInstaller); if (pActiveScriptSite) IUnknown_Release((IUnknown *)pActiveScriptSite); CoUninitialize(); /* must call even if CoInitialize failed */ return ret; }
/* * Call a script. */ DWORD call_script(MSIHANDLE hPackage, INT type, LPCWSTR script, LPCWSTR function, LPCWSTR action) { HRESULT hr; IActiveScript *pActiveScript = NULL; IActiveScriptParse *pActiveScriptParse = NULL; MsiActiveScriptSite *scriptsite; IDispatch *pDispatch = NULL; DISPPARAMS dispparamsNoArgs = {NULL, NULL, 0, 0}; DISPID dispid; CLSID clsid; VARIANT var; DWORD ret = ERROR_INSTALL_FAILURE; CoInitialize(NULL); /* Create MsiActiveScriptSite object */ hr = create_activescriptsite(&scriptsite); if (hr != S_OK) goto done; /* Create an installer object */ hr = create_msiserver(NULL, (void**)&scriptsite->installer); if (hr != S_OK) goto done; /* Create a session object */ hr = create_session(hPackage, scriptsite->installer, &scriptsite->session); if (hr != S_OK) goto done; /* Create the scripting engine */ type &= msidbCustomActionTypeJScript|msidbCustomActionTypeVBScript; if (type == msidbCustomActionTypeJScript) hr = CLSIDFromProgID(szJScript, &clsid); else if (type == msidbCustomActionTypeVBScript) hr = CLSIDFromProgID(szVBScript, &clsid); else { ERR("Unknown script type %d\n", type); goto done; } if (FAILED(hr)) { ERR("Could not find CLSID for Windows Script\n"); goto done; } hr = CoCreateInstance(&clsid, NULL, CLSCTX_INPROC_SERVER, &IID_IActiveScript, (void **)&pActiveScript); if (FAILED(hr)) { ERR("Could not instantiate class for Windows Script\n"); goto done; } hr = IActiveScript_QueryInterface(pActiveScript, &IID_IActiveScriptParse, (void **)&pActiveScriptParse); if (FAILED(hr)) goto done; hr = IActiveScript_SetScriptSite(pActiveScript, &scriptsite->IActiveScriptSite_iface); if (FAILED(hr)) goto done; hr = IActiveScriptParse_InitNew(pActiveScriptParse); if (FAILED(hr)) goto done; hr = IActiveScript_AddNamedItem(pActiveScript, szSession, SCRIPTITEM_GLOBALMEMBERS|SCRIPTITEM_ISVISIBLE); if (FAILED(hr)) goto done; hr = IActiveScriptParse_ParseScriptText(pActiveScriptParse, script, NULL, NULL, NULL, 0, 0, 0L, NULL, NULL); if (FAILED(hr)) goto done; hr = IActiveScript_SetScriptState(pActiveScript, SCRIPTSTATE_CONNECTED); if (FAILED(hr)) goto done; /* Call a function if necessary through the IDispatch interface */ if (function && function[0]) { TRACE("Calling function %s\n", debugstr_w(function)); hr = IActiveScript_GetScriptDispatch(pActiveScript, NULL, &pDispatch); if (FAILED(hr)) goto done; hr = IDispatch_GetIDsOfNames(pDispatch, &IID_NULL, (WCHAR **)&function, 1,LOCALE_USER_DEFAULT, &dispid); if (FAILED(hr)) goto done; hr = IDispatch_Invoke(pDispatch, dispid, &IID_NULL, LOCALE_USER_DEFAULT, DISPATCH_METHOD, &dispparamsNoArgs, &var, NULL, NULL); if (FAILED(hr)) goto done; hr = VariantChangeType(&var, &var, 0, VT_I4); if (FAILED(hr)) goto done; ret = map_return_value(V_I4(&var)); VariantClear(&var); } else { /* If no function to be called, MSI behavior is to succeed */ ret = ERROR_SUCCESS; } done: if (pDispatch) IDispatch_Release(pDispatch); if (pActiveScript) IActiveScript_Release(pActiveScript); if (pActiveScriptParse) IActiveScriptParse_Release(pActiveScriptParse); if (scriptsite) { if (scriptsite->session) IDispatch_Release(scriptsite->session); if (scriptsite->installer) IDispatch_Release(scriptsite->installer); IActiveScriptSite_Release(&scriptsite->IActiveScriptSite_iface); } CoUninitialize(); /* must call even if CoInitialize failed */ return ret; }