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 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; }
HRESULT WINAPI JScriptFactory_CreateInstance(IClassFactory *iface, IUnknown *pUnkOuter, REFIID riid, void **ppv) { JScript *ret; HRESULT hres; TRACE("(%p %s %p)\n", pUnkOuter, debugstr_guid(riid), ppv); lock_module(); ret = heap_alloc_zero(sizeof(*ret)); if(!ret) return E_OUTOFMEMORY; ret->lpIActiveScriptVtbl = &JScriptVtbl; ret->lpIActiveScriptParseVtbl = &JScriptParseVtbl; ret->lpIActiveScriptParseProcedure2Vtbl = &JScriptParseProcedureVtbl; ret->lpIActiveScriptPropertyVtbl = &JScriptPropertyVtbl; ret->lpIObjectSafetyVtbl = &JScriptSafetyVtbl; ret->ref = 1; ret->safeopt = INTERFACE_USES_DISPEX; hres = IActiveScript_QueryInterface(ACTSCRIPT(ret), riid, ppv); IActiveScript_Release(ACTSCRIPT(ret)); return hres; }
static HRESULT create_engine(CLSID *clsid, IActiveScript **script_ret, IActiveScriptParse **parser) { IActiveScript *script; IUnknown *unk; HRESULT hres; hres = CoCreateInstance(clsid, NULL, CLSCTX_INPROC_SERVER|CLSCTX_INPROC_HANDLER, &IID_IUnknown, (void**)&unk); if(FAILED(hres)) return FALSE; hres = IUnknown_QueryInterface(unk, &IID_IActiveScript, (void**)&script); IUnknown_Release(unk); if(FAILED(hres)) return FALSE; hres = IActiveScript_QueryInterface(script, &IID_IActiveScriptParse, (void**)parser); if(FAILED(hres)) { IActiveScript_Release(script); return FALSE; } *script_ret = script; return TRUE; }
HRESULT create_jscript_object(BOOL is_encode, REFIID riid, void **ppv) { JScript *ret; HRESULT hres; ret = heap_alloc_zero(sizeof(*ret)); if(!ret) return E_OUTOFMEMORY; lock_module(); ret->IActiveScript_iface.lpVtbl = &JScriptVtbl; ret->IActiveScriptParse_iface.lpVtbl = &JScriptParseVtbl; ret->IActiveScriptParseProcedure2_iface.lpVtbl = &JScriptParseProcedureVtbl; ret->IActiveScriptProperty_iface.lpVtbl = &JScriptPropertyVtbl; ret->IObjectSafety_iface.lpVtbl = &JScriptSafetyVtbl; ret->IVariantChangeType_iface.lpVtbl = &VariantChangeTypeVtbl; ret->ref = 1; ret->safeopt = INTERFACE_USES_DISPEX; ret->is_encode = is_encode; hres = IActiveScript_QueryInterface(&ret->IActiveScript_iface, riid, ppv); IActiveScript_Release(&ret->IActiveScript_iface); return hres; }
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 HRESULT WINAPI InternetHostSecurityManager_QueryCustomPolicy(IInternetHostSecurityManager *iface, REFGUID guidKey, BYTE **ppPolicy, DWORD *pcbPolicy, BYTE *pContext, DWORD cbContext, DWORD dwReserved) { HTMLDocumentNode *This = impl_from_IInternetHostSecurityManager(iface); const WCHAR *url; HRESULT hres; TRACE("(%p)->(%s %p %p %p %d %x)\n", This, debugstr_guid(guidKey), ppPolicy, pcbPolicy, pContext, cbContext, dwReserved); if(!This->basedoc.window) return E_UNEXPECTED; url = This->basedoc.window->url ? This->basedoc.window->url : about_blankW; hres = IInternetSecurityManager_QueryCustomPolicy(This->basedoc.window->secmgr, url, guidKey, ppPolicy, pcbPolicy, pContext, cbContext, dwReserved); if(hres != HRESULT_FROM_WIN32(ERROR_NOT_FOUND)) return hres; if(IsEqualGUID(&GUID_CUSTOM_CONFIRMOBJECTSAFETY, guidKey)) { IActiveScript *active_script; struct CONFIRMSAFETY *cs; DWORD policy; if(cbContext != sizeof(struct CONFIRMSAFETY)) { FIXME("wrong context size\n"); return E_FAIL; } cs = (struct CONFIRMSAFETY*)pContext; TRACE("cs = {%s %p %x}\n", debugstr_guid(&cs->clsid), cs->pUnk, cs->dwFlags); hres = IUnknown_QueryInterface(cs->pUnk, &IID_IActiveScript, (void**)&active_script); if(SUCCEEDED(hres)) { FIXME("Got IAciveScript iface\n"); IActiveScript_Release(active_script); return E_FAIL; } hres = confirm_safety(This, url, cs, &policy); if(FAILED(hres)) return hres; *ppPolicy = CoTaskMemAlloc(sizeof(policy)); if(!*ppPolicy) return E_OUTOFMEMORY; *(DWORD*)*ppPolicy = policy; *pcbPolicy = sizeof(policy); TRACE("policy %x\n", policy); return S_OK; } FIXME("Unknown guidKey %s\n", debugstr_guid(guidKey)); return hres; }
static void test_vbscript(void) { IActiveScriptParse *parser; IActiveScript *vbscript; ULONG ref; HRESULT hres; vbscript = create_vbscript(); hres = IActiveScript_QueryInterface(vbscript, &IID_IActiveScriptParse, (void**)&parser); ok(hres == S_OK, "Could not get IActiveScriptParse iface: %08x\n", hres); test_state(vbscript, SCRIPTSTATE_UNINITIALIZED); test_safety(vbscript); SET_EXPECT(GetLCID); hres = IActiveScript_SetScriptSite(vbscript, &ActiveScriptSite); ok(hres == S_OK, "SetScriptSite failed: %08x\n", hres); CHECK_CALLED(GetLCID); test_state(vbscript, SCRIPTSTATE_UNINITIALIZED); SET_EXPECT(OnStateChange_INITIALIZED); hres = IActiveScriptParse64_InitNew(parser); ok(hres == S_OK, "InitNew failed: %08x\n", hres); CHECK_CALLED(OnStateChange_INITIALIZED); test_state(vbscript, SCRIPTSTATE_INITIALIZED); hres = IActiveScriptParse64_InitNew(parser); ok(hres == E_UNEXPECTED, "InitNew failed: %08x, expected E_UNEXPECTED\n", hres); SET_EXPECT(OnStateChange_CONNECTED); hres = IActiveScript_SetScriptState(vbscript, SCRIPTSTATE_CONNECTED); ok(hres == S_OK, "SetScriptState(SCRIPTSTATE_CONNECTED) failed: %08x\n", hres); CHECK_CALLED(OnStateChange_CONNECTED); test_state(vbscript, SCRIPTSTATE_CONNECTED); SET_EXPECT(OnStateChange_DISCONNECTED); SET_EXPECT(OnStateChange_INITIALIZED); SET_EXPECT(OnStateChange_CLOSED); hres = IActiveScript_Close(vbscript); ok(hres == S_OK, "Close failed: %08x\n", hres); CHECK_CALLED(OnStateChange_DISCONNECTED); CHECK_CALLED(OnStateChange_INITIALIZED); CHECK_CALLED(OnStateChange_CLOSED); test_state(vbscript, SCRIPTSTATE_CLOSED); test_no_script_dispatch(vbscript); IActiveScriptParse64_Release(parser); ref = IActiveScript_Release(vbscript); ok(!ref, "ref = %d\n", ref); }
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 BOOL check_vbscript(void) { IActiveScript *vbscript; HRESULT hres; hres = CoCreateInstance(&CLSID_VBScript, NULL, CLSCTX_INPROC_SERVER|CLSCTX_INPROC_HANDLER, &IID_IActiveScript, (void**)&vbscript); if(SUCCEEDED(hres)) IActiveScript_Release(vbscript); return hres == S_OK; }
static void test_vbscript_simplecreate(void) { IActiveScript *script; ULONG ref; HRESULT hres; script = create_vbscript(); hres = IActiveScript_SetScriptState(script, SCRIPTSTATE_UNINITIALIZED); ok(hres == S_OK, "SetScriptState(SCRIPTSTATE_UNINITIALIZED) failed: %08x\n", hres); ref = IActiveScript_Release(script); ok(!ref, "ref = %d\n", ref); }
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; }
static void test_scriptdisp(void) { IActiveScriptParse *parser; IDispatchEx *script_disp; IActiveScript *vbscript; DISPID id, id2; DISPPARAMS dp; EXCEPINFO ei; VARIANT v; ULONG ref; HRESULT hres; vbscript = create_vbscript(); hres = IActiveScript_QueryInterface(vbscript, &IID_IActiveScriptParse, (void**)&parser); ok(hres == S_OK, "Could not get IActiveScriptParse iface: %08x\n", hres); test_state(vbscript, SCRIPTSTATE_UNINITIALIZED); test_safety(vbscript); SET_EXPECT(GetLCID); hres = IActiveScript_SetScriptSite(vbscript, &ActiveScriptSite); ok(hres == S_OK, "SetScriptSite failed: %08x\n", hres); CHECK_CALLED(GetLCID); test_state(vbscript, SCRIPTSTATE_UNINITIALIZED); SET_EXPECT(OnStateChange_INITIALIZED); hres = IActiveScriptParse_InitNew(parser); ok(hres == S_OK, "InitNew failed: %08x\n", hres); CHECK_CALLED(OnStateChange_INITIALIZED); test_state(vbscript, SCRIPTSTATE_INITIALIZED); SET_EXPECT(OnStateChange_CONNECTED); hres = IActiveScript_SetScriptState(vbscript, SCRIPTSTATE_CONNECTED); ok(hres == S_OK, "SetScriptState(SCRIPTSTATE_CONNECTED) failed: %08x\n", hres); CHECK_CALLED(OnStateChange_CONNECTED); test_state(vbscript, SCRIPTSTATE_CONNECTED); script_disp = get_script_dispatch(vbscript); id = 100; get_disp_id(script_disp, "LCase", DISP_E_UNKNOWNNAME, &id); ok(id == -1, "id = %d, expected -1\n", id); get_disp_id(script_disp, "globalVariable", DISP_E_UNKNOWNNAME, &id); parse_script(parser, "dim globalVariable\nglobalVariable = 3"); get_disp_id(script_disp, "globalVariable", S_OK, &id); memset(&dp, 0, sizeof(dp)); memset(&ei, 0, sizeof(ei)); V_VT(&v) = VT_EMPTY; hres = IDispatchEx_InvokeEx(script_disp, id, 0, DISPATCH_PROPERTYGET|DISPATCH_METHOD, &dp, &v, &ei, NULL); ok(hres == S_OK, "InvokeEx failed: %08x\n", hres); ok(V_VT(&v) == VT_I2, "V_VT(v) = %d\n", V_VT(&v)); ok(V_I2(&v) == 3, "V_I2(v) = %d\n", V_I2(&v)); get_disp_id(script_disp, "globalVariable2", DISP_E_UNKNOWNNAME, &id); parse_script(parser, "globalVariable2 = 4"); get_disp_id(script_disp, "globalVariable2", S_OK, &id); get_disp_id(script_disp, "globalFunction", DISP_E_UNKNOWNNAME, &id); parse_script(parser, "function globalFunction()\nglobalFunction=5\nend function"); get_disp_id(script_disp, "globalFunction", S_OK, &id); SET_EXPECT(OnEnterScript); SET_EXPECT(OnLeaveScript); memset(&dp, 0, sizeof(dp)); memset(&ei, 0, sizeof(ei)); V_VT(&v) = VT_EMPTY; hres = IDispatchEx_InvokeEx(script_disp, id, 0, DISPATCH_PROPERTYGET|DISPATCH_METHOD, &dp, &v, &ei, NULL); ok(hres == S_OK, "InvokeEx failed: %08x\n", hres); ok(V_VT(&v) == VT_I2, "V_VT(v) = %d\n", V_VT(&v)); ok(V_I2(&v) == 5, "V_I2(v) = %d\n", V_I2(&v)); CHECK_CALLED(OnEnterScript); CHECK_CALLED(OnLeaveScript); SET_EXPECT(OnEnterScript); SET_EXPECT(OnLeaveScript); memset(&dp, 0, sizeof(dp)); memset(&ei, 0, sizeof(ei)); V_VT(&v) = VT_EMPTY; hres = IDispatchEx_Invoke(script_disp, id, &IID_NULL, 0, DISPATCH_PROPERTYGET|DISPATCH_METHOD, &dp, &v, &ei, NULL); ok(hres == S_OK, "InvokeEx failed: %08x\n", hres); ok(V_VT(&v) == VT_I2, "V_VT(v) = %d\n", V_VT(&v)); ok(V_I2(&v) == 5, "V_I2(v) = %d\n", V_I2(&v)); CHECK_CALLED(OnEnterScript); CHECK_CALLED(OnLeaveScript); get_disp_id(script_disp, "globalSub", DISP_E_UNKNOWNNAME, &id); parse_script(parser, "sub globalSub()\nend sub"); get_disp_id(script_disp, "globalSub", S_OK, &id); get_disp_id(script_disp, "globalSub", S_OK, &id2); ok(id == id2, "id != id2\n"); get_disp_id(script_disp, "constVariable", DISP_E_UNKNOWNNAME, &id); parse_script(parser, "const constVariable = 6"); get_disp_id(script_disp, "ConstVariable", S_OK, &id); get_disp_id(script_disp, "Constvariable", S_OK, &id2); ok(id == id2, "id != id2\n"); IDispatchEx_Release(script_disp); IActiveScriptParse_Release(parser); SET_EXPECT(OnStateChange_DISCONNECTED); SET_EXPECT(OnStateChange_INITIALIZED); SET_EXPECT(OnStateChange_CLOSED); hres = IActiveScript_Close(vbscript); ok(hres == S_OK, "Close failed: %08x\n", hres); CHECK_CALLED(OnStateChange_DISCONNECTED); CHECK_CALLED(OnStateChange_INITIALIZED); CHECK_CALLED(OnStateChange_CLOSED); ref = IActiveScript_Release(vbscript); ok(!ref, "ref = %d\n", ref); }
static ULONG WINAPI JScriptSafety_Release(IObjectSafety *iface) { JScript *This = impl_from_IObjectSafety(iface); return IActiveScript_Release(&This->IActiveScript_iface); }
static ULONG WINAPI JScriptProperty_Release(IActiveScriptProperty *iface) { JScript *This = impl_from_IActiveScriptProperty(iface); return IActiveScript_Release(&This->IActiveScript_iface); }
static ULONG WINAPI JScriptParseProcedure_Release(IActiveScriptParseProcedure2 *iface) { JScript *This = impl_from_IActiveScriptParseProcedure2(iface); return IActiveScript_Release(&This->IActiveScript_iface); }
static ULONG WINAPI JScriptParseProcedure_Release(IActiveScriptParseProcedure2 *iface) { JScript *This = ASPARSEPROC_THIS(iface); return IActiveScript_Release(ACTSCRIPT(This)); }
static ULONG WINAPI VariantChangeType_Release(IVariantChangeType *iface) { JScript *This = impl_from_IVariantChangeType(iface); return IActiveScript_Release(&This->IActiveScript_iface); }
int WINAPI wWinMain(HINSTANCE hInst, HINSTANCE hPrevInst, LPWSTR cmdline, int cmdshow) { const WCHAR *ext, *filename = NULL; IActiveScriptParse *parser; IActiveScript *script; WCHAR **argv; CLSID clsid; int argc, i; DWORD res; WINE_TRACE("(%p %p %s %x)\n", hInst, hPrevInst, wine_dbgstr_w(cmdline), cmdshow); argv = CommandLineToArgvW(cmdline, &argc); if(!argv) return 1; for(i=0; i<argc; i++) { if(*argv[i] == '/' || *argv[i] == '-') { if(!set_host_properties(argv[i])) return 1; }else { filename = argv[i]; argums = argv+i+1; numOfArgs = argc-i-1; break; } } if(!filename) { WINE_FIXME("No file name specified\n"); return 1; } res = GetFullPathNameW(filename, sizeof(scriptFullName)/sizeof(WCHAR), scriptFullName, NULL); if(!res || res > sizeof(scriptFullName)/sizeof(WCHAR)) return 1; ext = strchrW(filename, '.'); if(!ext) ext = filename; if(!get_engine_clsid(ext, &clsid)) { WINE_FIXME("Could not find engine for %s\n", wine_dbgstr_w(ext)); return 1; } CoInitialize(NULL); if(!create_engine(&clsid, &script, &parser)) { WINE_FIXME("Could not create script engine\n"); CoUninitialize(); return 1; } if(init_engine(script, parser)) { run_script(filename, script, parser); IActiveScript_Close(script); ITypeInfo_Release(host_ti); }else { WINE_FIXME("Script initialization failed\n"); } IActiveScript_Release(script); IActiveScriptParse_Release(parser); CoUninitialize(); return 0; }
static ULONG WINAPI JScriptProperty_Release(IActiveScriptProperty *iface) { JScript *This = ACTSCPPROP_THIS(iface); return IActiveScript_Release(ACTSCRIPT(This)); }
static void test_vbscript_uninitializing(void) { IActiveScriptParse *parse; IActiveScript *script; IDispatchEx *dispex; ULONG ref; HRESULT hres; static const WCHAR script_textW[] = {'F','u','n','c','t','i','o','n',' ','f','\n','E','n','d',' ','F','u','n','c','t','i','o','n','\n',0}; script = create_vbscript(); hres = IActiveScript_QueryInterface(script, &IID_IActiveScriptParse, (void**)&parse); ok(hres == S_OK, "Could not get IActiveScriptParse: %08x\n", hres); test_state(script, SCRIPTSTATE_UNINITIALIZED); hres = IActiveScriptParse_InitNew(parse); ok(hres == S_OK, "InitNew failed: %08x\n", hres); SET_EXPECT(GetLCID); SET_EXPECT(OnStateChange_INITIALIZED); hres = IActiveScript_SetScriptSite(script, &ActiveScriptSite); ok(hres == S_OK, "SetScriptSite failed: %08x\n", hres); CHECK_CALLED(GetLCID); CHECK_CALLED(OnStateChange_INITIALIZED); test_state(script, SCRIPTSTATE_INITIALIZED); hres = IActiveScriptParse_ParseScriptText(parse, script_textW, NULL, NULL, NULL, 0, 1, 0x42, NULL, NULL); ok(hres == S_OK, "ParseScriptText failed: %08x\n", hres); hres = IActiveScript_SetScriptSite(script, &ActiveScriptSite); ok(hres == E_UNEXPECTED, "SetScriptSite failed: %08x, expected E_UNEXPECTED\n", hres); SET_EXPECT(OnStateChange_UNINITIALIZED); hres = IActiveScript_SetScriptState(script, SCRIPTSTATE_UNINITIALIZED); ok(hres == S_OK, "SetScriptState(SCRIPTSTATE_UNINITIALIZED) failed: %08x\n", hres); CHECK_CALLED(OnStateChange_UNINITIALIZED); test_state(script, SCRIPTSTATE_UNINITIALIZED); hres = IActiveScript_SetScriptState(script, SCRIPTSTATE_UNINITIALIZED); ok(hres == S_OK, "SetScriptState(SCRIPTSTATE_UNINITIALIZED) failed: %08x\n", hres); SET_EXPECT(GetLCID); SET_EXPECT(OnStateChange_INITIALIZED); hres = IActiveScript_SetScriptSite(script, &ActiveScriptSite); ok(hres == S_OK, "SetScriptSite failed: %08x\n", hres); CHECK_CALLED(GetLCID); CHECK_CALLED(OnStateChange_INITIALIZED); SET_EXPECT(OnStateChange_CONNECTED); SET_EXPECT(OnEnterScript); SET_EXPECT(OnLeaveScript); hres = IActiveScript_SetScriptState(script, SCRIPTSTATE_CONNECTED); ok(hres == S_OK, "SetScriptState(SCRIPTSTATE_CONNECTED) failed: %08x\n", hres); CHECK_CALLED(OnStateChange_CONNECTED); CHECK_CALLED(OnEnterScript); CHECK_CALLED(OnLeaveScript); test_state(script, SCRIPTSTATE_CONNECTED); dispex = get_script_dispatch(script); ok(dispex != NULL, "dispex == NULL\n"); if(dispex) IDispatchEx_Release(dispex); SET_EXPECT(OnStateChange_DISCONNECTED); SET_EXPECT(OnStateChange_INITIALIZED); SET_EXPECT(OnStateChange_UNINITIALIZED); hres = IActiveScript_SetScriptState(script, SCRIPTSTATE_UNINITIALIZED); ok(hres == S_OK, "SetScriptState(SCRIPTSTATE_UNINITIALIZED) failed: %08x\n", hres); CHECK_CALLED(OnStateChange_DISCONNECTED); CHECK_CALLED(OnStateChange_INITIALIZED); CHECK_CALLED(OnStateChange_UNINITIALIZED); test_state(script, SCRIPTSTATE_UNINITIALIZED); hres = IActiveScript_Close(script); ok(hres == S_OK, "Close failed: %08x\n", hres); test_state(script, SCRIPTSTATE_CLOSED); hres = IActiveScript_SetScriptState(script, SCRIPTSTATE_UNINITIALIZED); ok(hres == E_UNEXPECTED, "SetScriptState(SCRIPTSTATE_UNINITIALIZED) failed: %08x, expected E_UNEXPECTED\n", hres); test_state(script, SCRIPTSTATE_CLOSED); SET_EXPECT(GetLCID); SET_EXPECT(OnStateChange_INITIALIZED); hres = IActiveScript_SetScriptSite(script, &ActiveScriptSite); ok(hres == S_OK, "SetScriptSite failed: %08x\n", hres); CHECK_CALLED(GetLCID); CHECK_CALLED(OnStateChange_INITIALIZED); test_state(script, SCRIPTSTATE_INITIALIZED); SET_EXPECT(OnStateChange_CLOSED); hres = IActiveScript_Close(script); ok(hres == S_OK, "Close failed: %08x\n", hres); CHECK_CALLED(OnStateChange_CLOSED); test_state(script, SCRIPTSTATE_CLOSED); IActiveScriptParse_Release(parse); ref = IActiveScript_Release(script); ok(!ref, "ref = %d\n", ref); }
/* * 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; }
static ULONG WINAPI JScriptSafety_Release(IObjectSafety *iface) { JScript *This = OBJSAFETY_THIS(iface); return IActiveScript_Release(ACTSCRIPT(This)); }
static void test_jscript(void) { IActiveScriptParse *parse; IActiveScript *script; IDispatchEx *dispex; ULONG ref; HRESULT hres; script = create_jscript(); hres = IActiveScript_QueryInterface(script, &IID_IActiveScriptParse, (void**)&parse); ok(hres == S_OK, "Could not get IActiveScriptParse: %08x\n", hres); test_state(script, SCRIPTSTATE_UNINITIALIZED); test_safety((IUnknown*)script); test_invoke_versioning(script); hres = IActiveScriptParse_InitNew(parse); ok(hres == S_OK, "InitNew failed: %08x\n", hres); hres = IActiveScriptParse_InitNew(parse); ok(hres == E_UNEXPECTED, "InitNew failed: %08x, expected E_UNEXPECTED\n", hres); hres = IActiveScript_SetScriptSite(script, NULL); ok(hres == E_POINTER, "SetScriptSite failed: %08x, expected E_POINTER\n", hres); test_state(script, SCRIPTSTATE_UNINITIALIZED); test_no_script_dispatch(script); SET_EXPECT(GetLCID); SET_EXPECT(OnStateChange_INITIALIZED); hres = IActiveScript_SetScriptSite(script, &ActiveScriptSite); ok(hres == S_OK, "SetScriptSite failed: %08x\n", hres); CHECK_CALLED(GetLCID); CHECK_CALLED(OnStateChange_INITIALIZED); test_state(script, SCRIPTSTATE_INITIALIZED); hres = IActiveScript_SetScriptSite(script, &ActiveScriptSite); ok(hres == E_UNEXPECTED, "SetScriptSite failed: %08x, expected E_UNEXPECTED\n", hres); dispex = get_script_dispatch(script); test_script_dispatch(dispex); SET_EXPECT(OnStateChange_STARTED); hres = IActiveScript_SetScriptState(script, SCRIPTSTATE_STARTED); ok(hres == S_OK, "SetScriptState(SCRIPTSTATE_STARTED) failed: %08x\n", hres); CHECK_CALLED(OnStateChange_STARTED); test_state(script, SCRIPTSTATE_STARTED); SET_EXPECT(OnStateChange_CLOSED); hres = IActiveScript_Close(script); ok(hres == S_OK, "Close failed: %08x\n", hres); CHECK_CALLED(OnStateChange_CLOSED); test_state(script, SCRIPTSTATE_CLOSED); test_no_script_dispatch(script); test_script_dispatch(dispex); IDispatchEx_Release(dispex); IActiveScriptParse_Release(parse); ref = IActiveScript_Release(script); ok(!ref, "ref = %d\n", ref); }
static void test_jscript2(void) { IActiveScriptParse *parse; IActiveScript *script; IUnknown *unk; ULONG ref; HRESULT hres; hres = CoCreateInstance(&CLSID_JScript, NULL, CLSCTX_INPROC_SERVER|CLSCTX_INPROC_HANDLER, &IID_IUnknown, (void**)&unk); ok(hres == S_OK, "CoCreateInstance failed: %08x\n", hres); if(FAILED(hres)) return; hres = IUnknown_QueryInterface(unk, &IID_IActiveScript, (void**)&script); ok(hres == S_OK, "Could not get IActiveScript: %08x\n", hres); hres = IUnknown_QueryInterface(unk, &IID_IActiveScriptParse, (void**)&parse); ok(hres == S_OK, "Could not get IActiveScriptParse: %08x\n", hres); if (FAILED(hres)) { IActiveScript_Release(script); return; } test_state(script, SCRIPTSTATE_UNINITIALIZED); SET_EXPECT(GetLCID); hres = IActiveScript_SetScriptSite(script, &ActiveScriptSite); ok(hres == S_OK, "SetScriptSite failed: %08x\n", hres); CHECK_CALLED(GetLCID); test_state(script, SCRIPTSTATE_UNINITIALIZED); SET_EXPECT(OnStateChange_INITIALIZED); hres = IActiveScriptParse64_InitNew(parse); ok(hres == S_OK, "InitNew failed: %08x\n", hres); CHECK_CALLED(OnStateChange_INITIALIZED); hres = IActiveScriptParse64_InitNew(parse); ok(hres == E_UNEXPECTED, "InitNew failed: %08x, expected E_UNEXPECTED\n", hres); SET_EXPECT(OnStateChange_CONNECTED); hres = IActiveScript_SetScriptState(script, SCRIPTSTATE_CONNECTED); ok(hres == S_OK, "SetScriptState(SCRIPTSTATE_CONNECTED) failed: %08x\n", hres); CHECK_CALLED(OnStateChange_CONNECTED); test_state(script, SCRIPTSTATE_CONNECTED); SET_EXPECT(OnStateChange_DISCONNECTED); SET_EXPECT(OnStateChange_INITIALIZED); SET_EXPECT(OnStateChange_CLOSED); hres = IActiveScript_Close(script); ok(hres == S_OK, "Close failed: %08x\n", hres); CHECK_CALLED(OnStateChange_DISCONNECTED); CHECK_CALLED(OnStateChange_INITIALIZED); CHECK_CALLED(OnStateChange_CLOSED); test_state(script, SCRIPTSTATE_CLOSED); test_no_script_dispatch(script); IUnknown_Release(parse); IActiveScript_Release(script); ref = IUnknown_Release(unk); ok(!ref, "ref = %d\n", ref); }