gdi32: Try to parse font names without FreeType.
[wine/zf.git] / dlls / jscript / tests / jscript.c
blobc1b83d47799243355458253cdaa51c3b32deea3b
1 /*
2 * Copyright 2008 Jacek Caban for CodeWeavers
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
19 #define COBJMACROS
20 #define CONST_VTABLE
22 #include <initguid.h>
23 #include <ole2.h>
24 #include <activscp.h>
25 #include <objsafe.h>
26 #include <dispex.h>
28 #include "wine/test.h"
30 #ifdef _WIN64
32 #define IActiveScriptParse_QueryInterface IActiveScriptParse64_QueryInterface
33 #define IActiveScriptParse_Release IActiveScriptParse64_Release
34 #define IActiveScriptParse_InitNew IActiveScriptParse64_InitNew
35 #define IActiveScriptParse_ParseScriptText IActiveScriptParse64_ParseScriptText
36 #define IActiveScriptParseProcedure2_Release IActiveScriptParseProcedure2_64_Release
37 #define IActiveScriptParseProcedure2_ParseProcedureText IActiveScriptParseProcedure2_64_ParseProcedureText
39 #else
41 #define IActiveScriptParse_QueryInterface IActiveScriptParse32_QueryInterface
42 #define IActiveScriptParse_Release IActiveScriptParse32_Release
43 #define IActiveScriptParse_InitNew IActiveScriptParse32_InitNew
44 #define IActiveScriptParse_ParseScriptText IActiveScriptParse32_ParseScriptText
45 #define IActiveScriptParseProcedure2_Release IActiveScriptParseProcedure2_32_Release
46 #define IActiveScriptParseProcedure2_ParseProcedureText IActiveScriptParseProcedure2_32_ParseProcedureText
48 #endif
50 DEFINE_GUID(GUID_NULL,0,0,0,0,0,0,0,0,0,0,0);
51 DEFINE_GUID(IID_IScriptTypeInfo, 0xc59c6b12, 0xf6c1, 0x11cf, 0x88,0x35, 0x00,0xa0,0xc9,0x11,0xe8,0xb2);
53 static const CLSID CLSID_JScript =
54 {0xf414c260,0x6ac0,0x11cf,{0xb6,0xd1,0x00,0xaa,0x00,0xbb,0xbb,0x58}};
55 static const CLSID CLSID_JScriptEncode =
56 {0xf414c262,0x6ac0,0x11cf,{0xb6,0xd1,0x00,0xaa,0x00,0xbb,0xbb,0x58}};
58 #define DEFINE_EXPECT(func) \
59 static int expect_ ## func = 0, called_ ## func = 0
61 #define SET_EXPECT(func) \
62 expect_ ## func = 1
64 #define SET_EXPECT_MULTI(func, num) \
65 expect_ ## func = num
67 #define CHECK_EXPECT2(func) \
68 do { \
69 ok(expect_ ##func, "unexpected call " #func "\n"); \
70 called_ ## func++; \
71 }while(0)
73 #define CHECK_EXPECT(func) \
74 do { \
75 CHECK_EXPECT2(func); \
76 expect_ ## func--; \
77 }while(0)
79 #define CHECK_CALLED(func) \
80 do { \
81 ok(called_ ## func, "expected " #func "\n"); \
82 expect_ ## func = called_ ## func = 0; \
83 }while(0)
85 #define CHECK_NOT_CALLED(func) \
86 do { \
87 ok(!called_ ## func, "unexpected " #func "\n"); \
88 expect_ ## func = called_ ## func = FALSE; \
89 }while(0)
91 #define CHECK_CALLED_MULTI(func, num) \
92 do { \
93 ok(called_ ## func == num, "expected " #func " %d times (got %d)\n", num, called_ ## func); \
94 expect_ ## func = called_ ## func = 0; \
95 }while(0)
97 DEFINE_EXPECT(GetLCID);
98 DEFINE_EXPECT(OnStateChange_UNINITIALIZED);
99 DEFINE_EXPECT(OnStateChange_STARTED);
100 DEFINE_EXPECT(OnStateChange_CONNECTED);
101 DEFINE_EXPECT(OnStateChange_DISCONNECTED);
102 DEFINE_EXPECT(OnStateChange_CLOSED);
103 DEFINE_EXPECT(OnStateChange_INITIALIZED);
104 DEFINE_EXPECT(OnEnterScript);
105 DEFINE_EXPECT(OnLeaveScript);
106 DEFINE_EXPECT(OnScriptError);
107 DEFINE_EXPECT(GetIDsOfNames);
108 DEFINE_EXPECT(GetIDsOfNames_visible);
109 DEFINE_EXPECT(GetIDsOfNames_persistent);
110 DEFINE_EXPECT(GetItemInfo_global);
111 DEFINE_EXPECT(GetItemInfo_global_code);
112 DEFINE_EXPECT(GetItemInfo_visible);
113 DEFINE_EXPECT(GetItemInfo_visible_code);
114 DEFINE_EXPECT(GetItemInfo_persistent);
115 DEFINE_EXPECT(testCall);
117 static const CLSID *engine_clsid = &CLSID_JScript;
119 #define test_state(s,ss) _test_state(__LINE__,s,ss)
120 static void _test_state(unsigned line, IActiveScript *script, SCRIPTSTATE exstate)
122 SCRIPTSTATE state = -1;
123 HRESULT hres;
125 hres = IActiveScript_GetScriptState(script, &state);
126 ok_(__FILE__,line) (hres == S_OK, "GetScriptState failed: %08x\n", hres);
127 ok_(__FILE__,line) (state == exstate, "state=%d, expected %d\n", state, exstate);
130 static HRESULT WINAPI Dispatch_QueryInterface(IDispatch *iface, REFIID riid, void **ppv)
132 if(IsEqualGUID(&IID_IUnknown, riid) || IsEqualGUID(&IID_IDispatch, riid)) {
133 *ppv = iface;
134 IDispatch_AddRef(iface);
135 return S_OK;
138 *ppv = NULL;
139 return E_NOINTERFACE;
142 static ULONG WINAPI Dispatch_AddRef(IDispatch *iface)
144 return 2;
147 static ULONG WINAPI Dispatch_Release(IDispatch *iface)
149 return 1;
152 static ULONG global_named_item_ref, visible_named_item_ref, visible_code_named_item_ref, persistent_named_item_ref;
154 static ULONG WINAPI global_AddRef(IDispatch *iface)
156 return ++global_named_item_ref;
159 static ULONG WINAPI global_Release(IDispatch *iface)
161 return --global_named_item_ref;
164 static ULONG WINAPI visible_AddRef(IDispatch *iface)
166 return ++visible_named_item_ref;
169 static ULONG WINAPI visible_Release(IDispatch *iface)
171 return --visible_named_item_ref;
174 static ULONG WINAPI visible_code_AddRef(IDispatch *iface)
176 return ++visible_code_named_item_ref;
179 static ULONG WINAPI visible_code_Release(IDispatch *iface)
181 return --visible_code_named_item_ref;
184 static ULONG WINAPI persistent_AddRef(IDispatch *iface)
186 return ++persistent_named_item_ref;
189 static ULONG WINAPI persistent_Release(IDispatch *iface)
191 return --persistent_named_item_ref;
194 static HRESULT WINAPI Dispatch_GetTypeInfoCount(IDispatch *iface, UINT *pctinfo)
196 ok(0, "unexpected call\n");
197 return E_NOTIMPL;
200 static HRESULT WINAPI Dispatch_GetTypeInfo(IDispatch *iface, UINT iTInfo, LCID lcid, ITypeInfo **ppTInfo)
202 return DISP_E_BADINDEX;
205 static HRESULT WINAPI Dispatch_GetIDsOfNames(IDispatch *iface, REFIID riid, LPOLESTR *names, UINT name_cnt,
206 LCID lcid, DISPID *ids)
208 ok(name_cnt == 1, "name_cnt = %u\n", name_cnt);
209 if(!wcscmp(names[0], L"testCall")) {
210 *ids = 1;
211 return S_OK;
214 CHECK_EXPECT2(GetIDsOfNames);
215 return DISP_E_UNKNOWNNAME;
218 static HRESULT WINAPI visible_GetIDsOfNames(IDispatch *iface, REFIID riid, LPOLESTR *names, UINT name_cnt,
219 LCID lcid, DISPID *ids)
221 ok(name_cnt == 1, "name_cnt = %u\n", name_cnt);
222 if(!wcscmp(names[0], L"testCall")) {
223 *ids = 1;
224 return S_OK;
227 CHECK_EXPECT2(GetIDsOfNames_visible);
228 return DISP_E_UNKNOWNNAME;
231 static HRESULT WINAPI persistent_GetIDsOfNames(IDispatch *iface, REFIID riid, LPOLESTR *names, UINT name_cnt,
232 LCID lcid, DISPID *ids)
234 ok(name_cnt == 1, "name_cnt = %u\n", name_cnt);
236 CHECK_EXPECT2(GetIDsOfNames_persistent);
237 return DISP_E_UNKNOWNNAME;
240 static HRESULT WINAPI Dispatch_Invoke(IDispatch *iface, DISPID id, REFIID riid, LCID lcid, WORD flags,
241 DISPPARAMS *dp, VARIANT *res, EXCEPINFO *ei, UINT *err)
243 CHECK_EXPECT(testCall);
244 ok(id == 1, "id = %u\n", id);
245 ok(flags == DISPATCH_METHOD, "flags = %x\n", flags);
246 ok(!dp->cArgs, "cArgs = %u\n", dp->cArgs);
247 ok(!res, "res = %p\n", res);
248 return S_OK;
251 static const IDispatchVtbl dispatch_vtbl = {
252 Dispatch_QueryInterface,
253 Dispatch_AddRef,
254 Dispatch_Release,
255 Dispatch_GetTypeInfoCount,
256 Dispatch_GetTypeInfo,
257 Dispatch_GetIDsOfNames,
258 Dispatch_Invoke
261 static IDispatch dispatch_object = { &dispatch_vtbl };
263 static const IDispatchVtbl global_named_item_vtbl = {
264 Dispatch_QueryInterface,
265 global_AddRef,
266 global_Release,
267 Dispatch_GetTypeInfoCount,
268 Dispatch_GetTypeInfo,
269 Dispatch_GetIDsOfNames,
270 Dispatch_Invoke
273 static IDispatch global_named_item = { &global_named_item_vtbl };
275 static const IDispatchVtbl visible_named_item_vtbl = {
276 Dispatch_QueryInterface,
277 visible_AddRef,
278 visible_Release,
279 Dispatch_GetTypeInfoCount,
280 Dispatch_GetTypeInfo,
281 visible_GetIDsOfNames,
282 Dispatch_Invoke
285 static IDispatch visible_named_item = { &visible_named_item_vtbl };
287 static const IDispatchVtbl visible_code_named_item_vtbl = {
288 Dispatch_QueryInterface,
289 visible_code_AddRef,
290 visible_code_Release,
291 Dispatch_GetTypeInfoCount,
292 Dispatch_GetTypeInfo,
293 Dispatch_GetIDsOfNames,
294 Dispatch_Invoke
297 static IDispatch visible_code_named_item = { &visible_code_named_item_vtbl };
299 static const IDispatchVtbl persistent_named_item_vtbl = {
300 Dispatch_QueryInterface,
301 persistent_AddRef,
302 persistent_Release,
303 Dispatch_GetTypeInfoCount,
304 Dispatch_GetTypeInfo,
305 persistent_GetIDsOfNames,
306 Dispatch_Invoke
309 static IDispatch persistent_named_item = { &persistent_named_item_vtbl };
311 static HRESULT WINAPI ActiveScriptSite_QueryInterface(IActiveScriptSite *iface, REFIID riid, void **ppv)
313 *ppv = NULL;
315 if(IsEqualGUID(&IID_IUnknown, riid))
316 *ppv = iface;
317 else if(IsEqualGUID(&IID_IActiveScriptSite, riid))
318 *ppv = iface;
319 else
320 return E_NOINTERFACE;
322 IUnknown_AddRef((IUnknown*)*ppv);
323 return S_OK;
326 static ULONG WINAPI ActiveScriptSite_AddRef(IActiveScriptSite *iface)
328 return 2;
331 static ULONG WINAPI ActiveScriptSite_Release(IActiveScriptSite *iface)
333 return 1;
336 static HRESULT WINAPI ActiveScriptSite_GetLCID(IActiveScriptSite *iface, LCID *plcid)
338 CHECK_EXPECT(GetLCID);
339 return E_NOTIMPL;
342 static HRESULT WINAPI ActiveScriptSite_GetItemInfo(IActiveScriptSite *iface, LPCOLESTR pstrName,
343 DWORD dwReturnMask, IUnknown **ppiunkItem, ITypeInfo **ppti)
345 ok(dwReturnMask == SCRIPTINFO_IUNKNOWN, "dwReturnMask = %x\n", dwReturnMask);
346 if(!wcscmp(pstrName, L"globalItem")) {
347 CHECK_EXPECT(GetItemInfo_global);
348 IDispatch_AddRef(&global_named_item);
349 *ppiunkItem = (IUnknown*)&global_named_item;
350 return S_OK;
352 if(!wcscmp(pstrName, L"globalCodeItem")) {
353 CHECK_EXPECT(GetItemInfo_global_code);
354 IDispatch_AddRef(&dispatch_object);
355 *ppiunkItem = (IUnknown*)&dispatch_object;
356 return S_OK;
358 if(!wcscmp(pstrName, L"visibleItem")) {
359 CHECK_EXPECT(GetItemInfo_visible);
360 IDispatch_AddRef(&visible_named_item);
361 *ppiunkItem = (IUnknown*)&visible_named_item;
362 return S_OK;
364 if(!wcscmp(pstrName, L"visibleCodeItem")) {
365 CHECK_EXPECT(GetItemInfo_visible_code);
366 IDispatch_AddRef(&visible_code_named_item);
367 *ppiunkItem = (IUnknown*)&visible_code_named_item;
368 return S_OK;
370 if(!wcscmp(pstrName, L"persistent")) {
371 CHECK_EXPECT(GetItemInfo_persistent);
372 IDispatch_AddRef(&persistent_named_item);
373 *ppiunkItem = (IUnknown*)&persistent_named_item;
374 return S_OK;
376 ok(0, "unexpected call %s\n", wine_dbgstr_w(pstrName));
377 return E_NOTIMPL;
380 static HRESULT WINAPI ActiveScriptSite_GetDocVersionString(IActiveScriptSite *iface, BSTR *pbstrVersion)
382 ok(0, "unexpected call\n");
383 return E_NOTIMPL;
386 static HRESULT WINAPI ActiveScriptSite_OnScriptTerminate(IActiveScriptSite *iface,
387 const VARIANT *pvarResult, const EXCEPINFO *pexcepinfo)
389 ok(0, "unexpected call\n");
390 return E_NOTIMPL;
393 static HRESULT WINAPI ActiveScriptSite_OnStateChange(IActiveScriptSite *iface, SCRIPTSTATE ssScriptState)
395 switch(ssScriptState) {
396 case SCRIPTSTATE_UNINITIALIZED:
397 CHECK_EXPECT(OnStateChange_UNINITIALIZED);
398 return S_OK;
399 case SCRIPTSTATE_STARTED:
400 CHECK_EXPECT(OnStateChange_STARTED);
401 return S_OK;
402 case SCRIPTSTATE_CONNECTED:
403 CHECK_EXPECT(OnStateChange_CONNECTED);
404 return S_OK;
405 case SCRIPTSTATE_DISCONNECTED:
406 CHECK_EXPECT(OnStateChange_DISCONNECTED);
407 return S_OK;
408 case SCRIPTSTATE_CLOSED:
409 CHECK_EXPECT(OnStateChange_CLOSED);
410 return S_OK;
411 case SCRIPTSTATE_INITIALIZED:
412 CHECK_EXPECT(OnStateChange_INITIALIZED);
413 return S_OK;
414 default:
415 ok(0, "unexpected call %d\n", ssScriptState);
418 return E_NOTIMPL;
421 static HRESULT WINAPI ActiveScriptSite_OnScriptError(IActiveScriptSite *iface, IActiveScriptError *pscripterror)
423 CHECK_EXPECT(OnScriptError);
424 return S_OK;
427 static HRESULT WINAPI ActiveScriptSite_OnEnterScript(IActiveScriptSite *iface)
429 CHECK_EXPECT(OnEnterScript);
430 return S_OK;
433 static HRESULT WINAPI ActiveScriptSite_OnLeaveScript(IActiveScriptSite *iface)
435 CHECK_EXPECT(OnLeaveScript);
436 return S_OK;
439 static const IActiveScriptSiteVtbl ActiveScriptSiteVtbl = {
440 ActiveScriptSite_QueryInterface,
441 ActiveScriptSite_AddRef,
442 ActiveScriptSite_Release,
443 ActiveScriptSite_GetLCID,
444 ActiveScriptSite_GetItemInfo,
445 ActiveScriptSite_GetDocVersionString,
446 ActiveScriptSite_OnScriptTerminate,
447 ActiveScriptSite_OnStateChange,
448 ActiveScriptSite_OnScriptError,
449 ActiveScriptSite_OnEnterScript,
450 ActiveScriptSite_OnLeaveScript
453 static IActiveScriptSite ActiveScriptSite = { &ActiveScriptSiteVtbl };
455 static void test_script_dispatch(IDispatchEx *dispex)
457 DISPPARAMS dp = {NULL,NULL,0,0};
458 EXCEPINFO ei;
459 BSTR str;
460 DISPID id;
461 VARIANT v;
462 HRESULT hres;
464 str = SysAllocString(L"ActiveXObject");
465 hres = IDispatchEx_GetDispID(dispex, str, fdexNameCaseSensitive, &id);
466 SysFreeString(str);
467 ok(hres == S_OK, "GetDispID failed: %08x\n", hres);
469 str = SysAllocString(L"Math");
470 hres = IDispatchEx_GetDispID(dispex, str, fdexNameCaseSensitive, &id);
471 SysFreeString(str);
472 ok(hres == S_OK, "GetDispID failed: %08x\n", hres);
474 memset(&ei, 0, sizeof(ei));
475 hres = IDispatchEx_InvokeEx(dispex, id, 0, DISPATCH_PROPERTYGET, &dp, &v, &ei, NULL);
476 ok(hres == S_OK, "InvokeEx failed: %08x\n", hres);
477 ok(V_VT(&v) == VT_DISPATCH, "V_VT(v) = %d\n", V_VT(&v));
478 ok(V_DISPATCH(&v) != NULL, "V_DISPATCH(v) = NULL\n");
479 VariantClear(&v);
481 str = SysAllocString(L"String");
482 hres = IDispatchEx_GetDispID(dispex, str, fdexNameCaseSensitive, &id);
483 SysFreeString(str);
484 ok(hres == S_OK, "GetDispID failed: %08x\n", hres);
486 memset(&ei, 0, sizeof(ei));
487 hres = IDispatchEx_InvokeEx(dispex, id, 0, DISPATCH_PROPERTYGET, &dp, &v, &ei, NULL);
488 ok(hres == S_OK, "InvokeEx failed: %08x\n", hres);
489 ok(V_VT(&v) == VT_DISPATCH, "V_VT(v) = %d\n", V_VT(&v));
490 ok(V_DISPATCH(&v) != NULL, "V_DISPATCH(v) = NULL\n");
491 VariantClear(&v);
494 static IDispatchEx *get_script_dispatch(IActiveScript *script, const WCHAR *item_name)
496 IDispatchEx *dispex;
497 IDispatch *disp;
498 HRESULT hres;
500 disp = (void*)0xdeadbeef;
501 hres = IActiveScript_GetScriptDispatch(script, item_name, &disp);
502 ok(hres == S_OK, "GetScriptDispatch failed: %08x\n", hres);
504 hres = IDispatch_QueryInterface(disp, &IID_IDispatchEx, (void**)&dispex);
505 IDispatch_Release(disp);
506 ok(hres == S_OK, "Could not get IDispatch iface: %08x\n", hres);
507 return dispex;
510 static void parse_script(IActiveScriptParse *parser, const WCHAR *src)
512 HRESULT hres;
514 SET_EXPECT(OnEnterScript);
515 SET_EXPECT(OnLeaveScript);
517 hres = IActiveScriptParse_ParseScriptText(parser, src, NULL, NULL, NULL, 0, 0, 0, NULL, NULL);
518 ok(hres == S_OK, "ParseScriptText failed: %08x\n", hres);
520 CHECK_CALLED(OnEnterScript);
521 CHECK_CALLED(OnLeaveScript);
524 #define get_disp_id(a,b,c,d) _get_disp_id(__LINE__,a,b,c,d)
525 static void _get_disp_id(unsigned line, IDispatchEx *dispex, const WCHAR *name, HRESULT exhr, DISPID *id)
527 DISPID id2;
528 HRESULT hr;
529 BSTR str;
531 str = SysAllocString(name);
532 hr = IDispatchEx_GetDispID(dispex, str, 0, id);
533 ok_(__FILE__,line)(hr == exhr, "GetDispID(%s) returned %08x, expected %08x\n",
534 wine_dbgstr_w(name), hr, exhr);
536 hr = IDispatchEx_GetIDsOfNames(dispex, &IID_NULL, &str, 1, 0, &id2);
537 SysFreeString(str);
538 ok_(__FILE__,line)(hr == exhr, "GetIDsOfNames(%s) returned %08x, expected %08x\n",
539 wine_dbgstr_w(name), hr, exhr);
540 ok_(__FILE__,line)(*id == id2, "GetIDsOfNames(%s) id != id2\n", wine_dbgstr_w(name));
543 static void test_no_script_dispatch(IActiveScript *script)
545 IDispatch *disp;
546 HRESULT hres;
548 disp = (void*)0xdeadbeef;
549 hres = IActiveScript_GetScriptDispatch(script, NULL, &disp);
550 ok(hres == E_UNEXPECTED, "hres = %08x, expected E_UNEXPECTED\n", hres);
551 ok(!disp, "disp != NULL\n");
554 static void test_safety(IUnknown *unk)
556 IObjectSafety *safety;
557 DWORD supported, enabled;
558 HRESULT hres;
560 hres = IUnknown_QueryInterface(unk, &IID_IObjectSafety, (void**)&safety);
561 ok(hres == S_OK, "Could not get IObjectSafety: %08x\n", hres);
562 if(FAILED(hres))
563 return;
565 hres = IObjectSafety_GetInterfaceSafetyOptions(safety, &IID_NULL, &supported, NULL);
566 ok(hres == E_POINTER, "GetInterfaceSafetyOptions failed: %08x, expected E_POINTER\n", hres);
567 hres = IObjectSafety_GetInterfaceSafetyOptions(safety, &IID_NULL, NULL, &enabled);
568 ok(hres == E_POINTER, "GetInterfaceSafetyOptions failed: %08x, expected E_POINTER\n", hres);
570 supported = enabled = 0xdeadbeef;
571 hres = IObjectSafety_GetInterfaceSafetyOptions(safety, &IID_NULL, &supported, &enabled);
572 ok(hres == S_OK, "GetInterfaceSafetyOptions failed: %08x\n", hres);
573 ok(supported == (INTERFACESAFE_FOR_UNTRUSTED_DATA|INTERFACE_USES_DISPEX|INTERFACE_USES_SECURITY_MANAGER),
574 "supported=%x\n", supported);
575 ok(enabled == INTERFACE_USES_DISPEX, "enabled=%x\n", enabled);
577 supported = enabled = 0xdeadbeef;
578 hres = IObjectSafety_GetInterfaceSafetyOptions(safety, &IID_IActiveScript, &supported, &enabled);
579 ok(hres == S_OK, "GetInterfaceSafetyOptions failed: %08x\n", hres);
580 ok(supported == (INTERFACESAFE_FOR_UNTRUSTED_DATA|INTERFACE_USES_DISPEX|INTERFACE_USES_SECURITY_MANAGER),
581 "supported=%x\n", supported);
582 ok(enabled == INTERFACE_USES_DISPEX, "enabled=%x\n", enabled);
584 supported = enabled = 0xdeadbeef;
585 hres = IObjectSafety_GetInterfaceSafetyOptions(safety, &IID_IActiveScriptParse, &supported, &enabled);
586 ok(hres == S_OK, "GetInterfaceSafetyOptions failed: %08x\n", hres);
587 ok(supported == (INTERFACESAFE_FOR_UNTRUSTED_DATA|INTERFACE_USES_DISPEX|INTERFACE_USES_SECURITY_MANAGER),
588 "supported=%x\n", supported);
589 ok(enabled == INTERFACE_USES_DISPEX, "enabled=%x\n", enabled);
591 hres = IObjectSafety_SetInterfaceSafetyOptions(safety, &IID_IActiveScriptParse,
592 INTERFACESAFE_FOR_UNTRUSTED_DATA|INTERFACE_USES_DISPEX|INTERFACE_USES_SECURITY_MANAGER
593 |INTERFACESAFE_FOR_UNTRUSTED_CALLER,
594 INTERFACESAFE_FOR_UNTRUSTED_DATA|INTERFACE_USES_DISPEX|INTERFACE_USES_SECURITY_MANAGER);
595 ok(hres == E_FAIL, "SetInterfaceSafetyOptions failed: %08x, expected E_FAIL\n", hres);
597 hres = IObjectSafety_SetInterfaceSafetyOptions(safety, &IID_IActiveScriptParse,
598 INTERFACESAFE_FOR_UNTRUSTED_DATA|INTERFACE_USES_DISPEX|INTERFACE_USES_SECURITY_MANAGER,
599 INTERFACESAFE_FOR_UNTRUSTED_DATA|INTERFACE_USES_DISPEX|INTERFACE_USES_SECURITY_MANAGER);
600 ok(hres == S_OK, "SetInterfaceSafetyOptions failed: %08x\n", hres);
602 supported = enabled = 0xdeadbeef;
603 hres = IObjectSafety_GetInterfaceSafetyOptions(safety, &IID_IActiveScriptParse, &supported, &enabled);
604 ok(hres == S_OK, "GetInterfaceSafetyOptions failed: %08x\n", hres);
605 ok(supported == (INTERFACESAFE_FOR_UNTRUSTED_DATA|INTERFACE_USES_DISPEX|INTERFACE_USES_SECURITY_MANAGER),
606 "supported=%x\n", supported);
607 ok(enabled == (INTERFACESAFE_FOR_UNTRUSTED_DATA|INTERFACE_USES_DISPEX|INTERFACE_USES_SECURITY_MANAGER),
608 "enabled=%x\n", enabled);
610 hres = IObjectSafety_SetInterfaceSafetyOptions(safety, &IID_IActiveScriptParse, INTERFACESAFE_FOR_UNTRUSTED_DATA, 0);
611 ok(hres == S_OK, "SetInterfaceSafetyOptions failed: %08x\n", hres);
613 supported = enabled = 0xdeadbeef;
614 hres = IObjectSafety_GetInterfaceSafetyOptions(safety, &IID_IActiveScriptParse, &supported, &enabled);
615 ok(hres == S_OK, "GetInterfaceSafetyOptions failed: %08x\n", hres);
616 ok(supported == (INTERFACESAFE_FOR_UNTRUSTED_DATA|INTERFACE_USES_DISPEX|INTERFACE_USES_SECURITY_MANAGER),
617 "supported=%x\n", supported);
618 ok(enabled == (INTERFACE_USES_DISPEX|INTERFACE_USES_SECURITY_MANAGER), "enabled=%x\n", enabled);
620 hres = IObjectSafety_SetInterfaceSafetyOptions(safety, &IID_IActiveScriptParse,
621 INTERFACESAFE_FOR_UNTRUSTED_DATA|INTERFACE_USES_DISPEX|INTERFACE_USES_SECURITY_MANAGER, 0);
622 ok(hres == S_OK, "SetInterfaceSafetyOptions failed: %08x\n", hres);
624 supported = enabled = 0xdeadbeef;
625 hres = IObjectSafety_GetInterfaceSafetyOptions(safety, &IID_IActiveScriptParse, &supported, &enabled);
626 ok(hres == S_OK, "GetInterfaceSafetyOptions failed: %08x\n", hres);
627 ok(supported == (INTERFACESAFE_FOR_UNTRUSTED_DATA|INTERFACE_USES_DISPEX|INTERFACE_USES_SECURITY_MANAGER),
628 "supported=%x\n", supported);
629 ok(enabled == INTERFACE_USES_DISPEX, "enabled=%x\n", enabled);
631 hres = IObjectSafety_SetInterfaceSafetyOptions(safety, &IID_IActiveScriptParse,
632 INTERFACE_USES_DISPEX, 0);
633 ok(hres == S_OK, "SetInterfaceSafetyOptions failed: %08x\n", hres);
635 supported = enabled = 0xdeadbeef;
636 hres = IObjectSafety_GetInterfaceSafetyOptions(safety, &IID_IActiveScriptParse, &supported, &enabled);
637 ok(hres == S_OK, "GetInterfaceSafetyOptions failed: %08x\n", hres);
638 ok(supported == (INTERFACESAFE_FOR_UNTRUSTED_DATA|INTERFACE_USES_DISPEX|INTERFACE_USES_SECURITY_MANAGER),
639 "supported=%x\n", supported);
640 ok(enabled == INTERFACE_USES_DISPEX, "enabled=%x\n", enabled);
642 IObjectSafety_Release(safety);
645 static HRESULT set_script_prop(IActiveScript *engine, DWORD property, VARIANT *val)
647 IActiveScriptProperty *script_prop;
648 HRESULT hres;
650 hres = IActiveScript_QueryInterface(engine, &IID_IActiveScriptProperty,
651 (void**)&script_prop);
652 ok(hres == S_OK, "Could not get IActiveScriptProperty: %08x\n", hres);
653 if(FAILED(hres))
654 return hres;
656 hres = IActiveScriptProperty_SetProperty(script_prop, property, NULL, val);
657 IActiveScriptProperty_Release(script_prop);
658 return hres;
661 static void test_invoke_versioning(IActiveScript *script)
663 VARIANT v;
664 HRESULT hres;
666 V_VT(&v) = VT_NULL;
667 hres = set_script_prop(script, SCRIPTPROP_INVOKEVERSIONING, &v);
668 if(hres == E_NOTIMPL) {
669 win_skip("SCRIPTPROP_INVOKESTRING not supported\n");
670 return;
672 ok(hres == E_INVALIDARG, "SetProperty(SCRIPTPROP_INVOKEVERSIONING) failed: %08x\n", hres);
674 V_VT(&v) = VT_I2;
675 V_I2(&v) = 0;
676 hres = set_script_prop(script, SCRIPTPROP_INVOKEVERSIONING, &v);
677 ok(hres == E_INVALIDARG, "SetProperty(SCRIPTPROP_INVOKEVERSIONING) failed: %08x\n", hres);
679 V_VT(&v) = VT_I4;
680 V_I4(&v) = 16;
681 hres = set_script_prop(script, SCRIPTPROP_INVOKEVERSIONING, &v);
682 ok(hres == E_INVALIDARG, "SetProperty(SCRIPTPROP_INVOKEVERSIONING) failed: %08x\n", hres);
684 V_VT(&v) = VT_I4;
685 V_I4(&v) = 2;
686 hres = set_script_prop(script, SCRIPTPROP_INVOKEVERSIONING, &v);
687 ok(hres == S_OK, "SetProperty(SCRIPTPROP_INVOKEVERSIONING) failed: %08x\n", hres);
690 static IActiveScript *create_jscript(void)
692 IActiveScript *ret;
693 HRESULT hres;
695 hres = CoCreateInstance(engine_clsid, NULL, CLSCTX_INPROC_SERVER|CLSCTX_INPROC_HANDLER,
696 &IID_IActiveScript, (void**)&ret);
697 ok(hres == S_OK, "CoCreateInstance failed: %08x\n", hres);
699 return ret;
702 static void test_jscript(void)
704 IActiveScriptParse *parse;
705 IActiveScript *script;
706 IDispatchEx *dispex;
707 ULONG ref;
708 HRESULT hres;
710 script = create_jscript();
712 hres = IActiveScript_QueryInterface(script, &IID_IActiveScriptParse, (void**)&parse);
713 ok(hres == S_OK, "Could not get IActiveScriptParse: %08x\n", hres);
715 test_state(script, SCRIPTSTATE_UNINITIALIZED);
716 test_safety((IUnknown*)script);
717 test_invoke_versioning(script);
719 hres = IActiveScriptParse_InitNew(parse);
720 ok(hres == S_OK, "InitNew failed: %08x\n", hres);
722 hres = IActiveScriptParse_InitNew(parse);
723 ok(hres == E_UNEXPECTED, "InitNew failed: %08x, expected E_UNEXPECTED\n", hres);
725 hres = IActiveScript_SetScriptSite(script, NULL);
726 ok(hres == E_POINTER, "SetScriptSite failed: %08x, expected E_POINTER\n", hres);
728 test_state(script, SCRIPTSTATE_UNINITIALIZED);
729 test_no_script_dispatch(script);
731 SET_EXPECT(GetLCID);
732 SET_EXPECT(OnStateChange_INITIALIZED);
733 hres = IActiveScript_SetScriptSite(script, &ActiveScriptSite);
734 ok(hres == S_OK, "SetScriptSite failed: %08x\n", hres);
735 CHECK_CALLED(GetLCID);
736 CHECK_CALLED(OnStateChange_INITIALIZED);
738 test_state(script, SCRIPTSTATE_INITIALIZED);
740 hres = IActiveScript_SetScriptSite(script, &ActiveScriptSite);
741 ok(hres == E_UNEXPECTED, "SetScriptSite failed: %08x, expected E_UNEXPECTED\n", hres);
743 dispex = get_script_dispatch(script, NULL);
744 test_script_dispatch(dispex);
746 SET_EXPECT(OnStateChange_STARTED);
747 hres = IActiveScript_SetScriptState(script, SCRIPTSTATE_STARTED);
748 ok(hres == S_OK, "SetScriptState(SCRIPTSTATE_STARTED) failed: %08x\n", hres);
749 CHECK_CALLED(OnStateChange_STARTED);
751 test_state(script, SCRIPTSTATE_STARTED);
753 SET_EXPECT(OnStateChange_CLOSED);
754 hres = IActiveScript_Close(script);
755 ok(hres == S_OK, "Close failed: %08x\n", hres);
756 CHECK_CALLED(OnStateChange_CLOSED);
758 test_state(script, SCRIPTSTATE_CLOSED);
759 test_no_script_dispatch(script);
760 test_script_dispatch(dispex);
761 IDispatchEx_Release(dispex);
763 IActiveScriptParse_Release(parse);
765 ref = IActiveScript_Release(script);
766 ok(!ref, "ref = %d\n", ref);
769 static void test_jscript2(void)
771 IActiveScriptParse *parse;
772 IActiveScript *script;
773 ULONG ref;
774 HRESULT hres;
776 script = create_jscript();
778 hres = IActiveScript_QueryInterface(script, &IID_IActiveScriptParse, (void**)&parse);
779 ok(hres == S_OK, "Could not get IActiveScriptParse: %08x\n", hres);
781 test_state(script, SCRIPTSTATE_UNINITIALIZED);
783 SET_EXPECT(GetLCID);
784 hres = IActiveScript_SetScriptSite(script, &ActiveScriptSite);
785 ok(hres == S_OK, "SetScriptSite failed: %08x\n", hres);
786 CHECK_CALLED(GetLCID);
788 test_state(script, SCRIPTSTATE_UNINITIALIZED);
790 SET_EXPECT(OnStateChange_INITIALIZED);
791 hres = IActiveScriptParse_InitNew(parse);
792 ok(hres == S_OK, "InitNew failed: %08x\n", hres);
793 CHECK_CALLED(OnStateChange_INITIALIZED);
795 hres = IActiveScriptParse_InitNew(parse);
796 ok(hres == E_UNEXPECTED, "InitNew failed: %08x, expected E_UNEXPECTED\n", hres);
798 SET_EXPECT(OnStateChange_CONNECTED);
799 hres = IActiveScript_SetScriptState(script, SCRIPTSTATE_CONNECTED);
800 ok(hres == S_OK, "SetScriptState(SCRIPTSTATE_CONNECTED) failed: %08x\n", hres);
801 CHECK_CALLED(OnStateChange_CONNECTED);
803 test_state(script, SCRIPTSTATE_CONNECTED);
805 SET_EXPECT(OnStateChange_DISCONNECTED);
806 SET_EXPECT(OnStateChange_INITIALIZED);
807 SET_EXPECT(OnStateChange_CLOSED);
808 hres = IActiveScript_Close(script);
809 ok(hres == S_OK, "Close failed: %08x\n", hres);
810 CHECK_CALLED(OnStateChange_DISCONNECTED);
811 CHECK_CALLED(OnStateChange_INITIALIZED);
812 CHECK_CALLED(OnStateChange_CLOSED);
814 test_state(script, SCRIPTSTATE_CLOSED);
815 test_no_script_dispatch(script);
817 IActiveScriptParse_Release(parse);
819 ref = IActiveScript_Release(script);
820 ok(!ref, "ref = %d\n", ref);
823 static void test_jscript_uninitializing(void)
825 IActiveScriptParse *parse;
826 IActiveScript *script;
827 IDispatchEx *dispex;
828 ULONG ref;
829 HRESULT hres;
831 static const WCHAR script_textW[] =
832 {'f','u','n','c','t','i','o','n',' ','f','(',')',' ','{','}',0};
834 script = create_jscript();
836 hres = IActiveScript_QueryInterface(script, &IID_IActiveScriptParse, (void**)&parse);
837 ok(hres == S_OK, "Could not get IActiveScriptParse: %08x\n", hres);
839 test_state(script, SCRIPTSTATE_UNINITIALIZED);
841 hres = IActiveScriptParse_InitNew(parse);
842 ok(hres == S_OK, "InitNew failed: %08x\n", hres);
844 SET_EXPECT(GetLCID);
845 SET_EXPECT(OnStateChange_INITIALIZED);
846 hres = IActiveScript_SetScriptSite(script, &ActiveScriptSite);
847 ok(hres == S_OK, "SetScriptSite failed: %08x\n", hres);
848 CHECK_CALLED(GetLCID);
849 CHECK_CALLED(OnStateChange_INITIALIZED);
851 test_state(script, SCRIPTSTATE_INITIALIZED);
853 hres = IActiveScriptParse_ParseScriptText(parse, script_textW, NULL, NULL, NULL, 0, 1, 0x42, NULL, NULL);
854 ok(hres == S_OK, "ParseScriptText failed: %08x\n", hres);
856 hres = IActiveScript_SetScriptSite(script, &ActiveScriptSite);
857 ok(hres == E_UNEXPECTED, "SetScriptSite failed: %08x, expected E_UNEXPECTED\n", hres);
859 SET_EXPECT(OnStateChange_UNINITIALIZED);
860 hres = IActiveScript_SetScriptState(script, SCRIPTSTATE_UNINITIALIZED);
861 ok(hres == S_OK, "SetScriptState(SCRIPTSTATE_UNINITIALIZED) failed: %08x\n", hres);
862 CHECK_CALLED(OnStateChange_UNINITIALIZED);
864 test_state(script, SCRIPTSTATE_UNINITIALIZED);
866 hres = IActiveScript_SetScriptState(script, SCRIPTSTATE_UNINITIALIZED);
867 ok(hres == S_OK, "SetScriptState(SCRIPTSTATE_UNINITIALIZED) failed: %08x\n", hres);
869 SET_EXPECT(GetLCID);
870 SET_EXPECT(OnStateChange_INITIALIZED);
871 hres = IActiveScript_SetScriptSite(script, &ActiveScriptSite);
872 ok(hres == S_OK, "SetScriptSite failed: %08x\n", hres);
873 CHECK_CALLED(GetLCID);
874 CHECK_CALLED(OnStateChange_INITIALIZED);
876 SET_EXPECT(OnStateChange_CONNECTED);
877 SET_EXPECT(OnEnterScript);
878 SET_EXPECT(OnLeaveScript);
879 hres = IActiveScript_SetScriptState(script, SCRIPTSTATE_CONNECTED);
880 ok(hres == S_OK, "SetScriptState(SCRIPTSTATE_CONNECTED) failed: %08x\n", hres);
881 CHECK_CALLED(OnStateChange_CONNECTED);
882 CHECK_CALLED(OnEnterScript);
883 CHECK_CALLED(OnLeaveScript);
885 test_state(script, SCRIPTSTATE_CONNECTED);
887 dispex = get_script_dispatch(script, NULL);
888 ok(dispex != NULL, "dispex == NULL\n");
889 IDispatchEx_Release(dispex);
891 SET_EXPECT(OnStateChange_DISCONNECTED);
892 SET_EXPECT(OnStateChange_INITIALIZED);
893 SET_EXPECT(OnStateChange_UNINITIALIZED);
894 hres = IActiveScript_SetScriptState(script, SCRIPTSTATE_UNINITIALIZED);
895 ok(hres == S_OK, "SetScriptState(SCRIPTSTATE_UNINITIALIZED) failed: %08x\n", hres);
896 CHECK_CALLED(OnStateChange_DISCONNECTED);
897 CHECK_CALLED(OnStateChange_INITIALIZED);
898 CHECK_CALLED(OnStateChange_UNINITIALIZED);
900 test_state(script, SCRIPTSTATE_UNINITIALIZED);
902 hres = IActiveScript_Close(script);
903 ok(hres == S_OK, "Close failed: %08x\n", hres);
905 test_state(script, SCRIPTSTATE_CLOSED);
907 hres = IActiveScript_SetScriptState(script, SCRIPTSTATE_UNINITIALIZED);
908 ok(hres == E_UNEXPECTED, "SetScriptState(SCRIPTSTATE_UNINITIALIZED) failed: %08x, expected E_UNEXPECTED\n", hres);
910 test_state(script, SCRIPTSTATE_CLOSED);
912 IActiveScriptParse_Release(parse);
914 ref = IActiveScript_Release(script);
915 ok(!ref, "ref = %d\n", ref);
918 static void test_aggregation(void)
920 IUnknown *unk = (IUnknown*)0xdeadbeef;
921 HRESULT hres;
923 hres = CoCreateInstance(&CLSID_JScript, (IUnknown*)0xdeadbeef, CLSCTX_INPROC_SERVER|CLSCTX_INPROC_HANDLER,
924 &IID_IUnknown, (void**)&unk);
925 ok(hres == CLASS_E_NOAGGREGATION,
926 "CoCreateInstance failed: %08x, expected CLASS_E_NOAGGREGATION\n", hres);
927 ok(!unk || broken(unk != NULL), "unk = %p\n", unk);
930 static void test_code_persistence(void)
932 IActiveScriptParse *parse;
933 IActiveScript *script;
934 IDispatchEx *dispex;
935 VARIANT var;
936 HRESULT hr;
937 DISPID id;
938 ULONG ref;
940 script = create_jscript();
942 hr = IActiveScript_QueryInterface(script, &IID_IActiveScriptParse, (void**)&parse);
943 ok(hr == S_OK, "Could not get IActiveScriptParse iface: %08x\n", hr);
944 test_state(script, SCRIPTSTATE_UNINITIALIZED);
945 test_safety((IUnknown*)script);
947 SET_EXPECT(GetLCID);
948 hr = IActiveScript_SetScriptSite(script, &ActiveScriptSite);
949 ok(hr == S_OK, "SetScriptSite failed: %08x\n", hr);
950 CHECK_CALLED(GetLCID);
952 SET_EXPECT(OnStateChange_INITIALIZED);
953 hr = IActiveScriptParse_InitNew(parse);
954 ok(hr == S_OK, "InitNew failed: %08x\n", hr);
955 CHECK_CALLED(OnStateChange_INITIALIZED);
956 test_state(script, SCRIPTSTATE_INITIALIZED);
958 hr = IActiveScriptParse_ParseScriptText(parse,
959 L"var x = 1;\n"
960 L"var y = 2;\n",
961 NULL, NULL, NULL, 0, 0, 0, NULL, NULL);
962 ok(hr == S_OK, "ParseScriptText failed: %08x\n", hr);
964 hr = IActiveScriptParse_ParseScriptText(parse,
965 L"var z = 3;\n"
966 L"var y = 42;\n"
967 L"var v = 10;\n",
968 NULL, NULL, NULL, 0, 0, SCRIPTTEXT_ISPERSISTENT, NULL, NULL);
969 ok(hr == S_OK, "ParseScriptText failed: %08x\n", hr);
971 /* Pending code does not add identifiers to the global scope */
972 dispex = get_script_dispatch(script, NULL);
973 id = 0;
974 get_disp_id(dispex, L"x", DISP_E_UNKNOWNNAME, &id);
975 ok(id == -1, "id = %d, expected -1\n", id);
976 id = 0;
977 get_disp_id(dispex, L"y", DISP_E_UNKNOWNNAME, &id);
978 ok(id == -1, "id = %d, expected -1\n", id);
979 id = 0;
980 get_disp_id(dispex, L"z", DISP_E_UNKNOWNNAME, &id);
981 ok(id == -1, "id = %d, expected -1\n", id);
982 IDispatchEx_Release(dispex);
984 /* Uninitialized state removes code without SCRIPTTEXT_ISPERSISTENT */
985 SET_EXPECT(OnStateChange_UNINITIALIZED);
986 hr = IActiveScript_SetScriptState(script, SCRIPTSTATE_UNINITIALIZED);
987 ok(hr == S_OK, "SetScriptState(SCRIPTSTATE_UNINITIALIZED) failed: %08x\n", hr);
988 CHECK_CALLED(OnStateChange_UNINITIALIZED);
989 test_no_script_dispatch(script);
991 SET_EXPECT(GetLCID);
992 SET_EXPECT(OnStateChange_INITIALIZED);
993 hr = IActiveScript_SetScriptSite(script, &ActiveScriptSite);
994 ok(hr == S_OK, "SetScriptSite failed: %08x\n", hr);
995 CHECK_CALLED(GetLCID);
996 CHECK_CALLED(OnStateChange_INITIALIZED);
998 hr = IActiveScriptParse_ParseScriptText(parse, L"v = 20;\n", NULL, NULL, NULL, 0, 0, 0, NULL, NULL);
999 ok(hr == S_OK, "ParseScriptText failed: %08x\n", hr);
1001 SET_EXPECT(OnStateChange_CONNECTED);
1002 SET_EXPECT_MULTI(OnEnterScript, 2);
1003 SET_EXPECT_MULTI(OnLeaveScript, 2);
1004 hr = IActiveScript_SetScriptState(script, SCRIPTSTATE_CONNECTED);
1005 ok(hr == S_OK, "SetScriptState(SCRIPTSTATE_CONNECTED) failed: %08x\n", hr);
1006 CHECK_CALLED(OnStateChange_CONNECTED);
1007 CHECK_CALLED_MULTI(OnEnterScript, 2);
1008 CHECK_CALLED_MULTI(OnLeaveScript, 2);
1009 test_state(script, SCRIPTSTATE_CONNECTED);
1011 dispex = get_script_dispatch(script, NULL);
1012 id = 0;
1013 get_disp_id(dispex, L"x", DISP_E_UNKNOWNNAME, &id);
1014 ok(id == -1, "id = %d, expected -1\n", id);
1015 id = 0;
1016 get_disp_id(dispex, L"y", S_OK, &id);
1017 ok(id != -1, "id = -1\n");
1018 id = 0;
1019 get_disp_id(dispex, L"z", S_OK, &id);
1020 ok(id != -1, "id = -1\n");
1021 IDispatchEx_Release(dispex);
1023 SET_EXPECT(OnEnterScript);
1024 SET_EXPECT(OnLeaveScript);
1025 hr = IActiveScriptParse_ParseScriptText(parse, L"y", NULL, NULL, NULL, 0, 0, SCRIPTTEXT_ISEXPRESSION, &var, NULL);
1026 ok(hr == S_OK, "ParseScriptText failed: %08x\n", hr);
1027 ok(V_VT(&var) == VT_I4 && V_I2(&var) == 42, "V_VT(y) = %d, V_I2(y) = %d\n", V_VT(&var), V_I2(&var));
1028 CHECK_CALLED(OnEnterScript);
1029 CHECK_CALLED(OnLeaveScript);
1031 SET_EXPECT(OnEnterScript);
1032 SET_EXPECT(OnLeaveScript);
1033 hr = IActiveScriptParse_ParseScriptText(parse, L"v", NULL, NULL, NULL, 0, 0, SCRIPTTEXT_ISEXPRESSION, &var, NULL);
1034 ok(hr == S_OK, "ParseScriptText failed: %08x\n", hr);
1035 ok(V_VT(&var) == VT_I4 && V_I2(&var) == 20, "V_VT(var) = %d, V_I2(var) = %d\n", V_VT(&var), V_I2(&var));
1036 CHECK_CALLED(OnEnterScript);
1037 CHECK_CALLED(OnLeaveScript);
1039 /* Uninitialized state does not remove persistent code, even if it was executed */
1040 SET_EXPECT(OnStateChange_DISCONNECTED);
1041 SET_EXPECT(OnStateChange_INITIALIZED);
1042 SET_EXPECT(OnStateChange_UNINITIALIZED);
1043 hr = IActiveScript_SetScriptState(script, SCRIPTSTATE_UNINITIALIZED);
1044 ok(hr == S_OK, "SetScriptState(SCRIPTSTATE_UNINITIALIZED) failed: %08x\n", hr);
1045 CHECK_CALLED(OnStateChange_DISCONNECTED);
1046 CHECK_CALLED(OnStateChange_INITIALIZED);
1047 CHECK_CALLED(OnStateChange_UNINITIALIZED);
1048 test_no_script_dispatch(script);
1050 SET_EXPECT(GetLCID);
1051 SET_EXPECT(OnStateChange_INITIALIZED);
1052 hr = IActiveScript_SetScriptSite(script, &ActiveScriptSite);
1053 ok(hr == S_OK, "SetScriptSite failed: %08x\n", hr);
1054 CHECK_CALLED(GetLCID);
1055 CHECK_CALLED(OnStateChange_INITIALIZED);
1057 dispex = get_script_dispatch(script, NULL);
1058 id = 0;
1059 get_disp_id(dispex, L"z", DISP_E_UNKNOWNNAME, &id);
1060 ok(id == -1, "id = %d, expected -1\n", id);
1061 IDispatchEx_Release(dispex);
1063 SET_EXPECT(OnStateChange_CONNECTED);
1064 SET_EXPECT(OnEnterScript);
1065 SET_EXPECT(OnLeaveScript);
1066 hr = IActiveScript_SetScriptState(script, SCRIPTSTATE_CONNECTED);
1067 ok(hr == S_OK, "SetScriptState(SCRIPTSTATE_CONNECTED) failed: %08x\n", hr);
1068 CHECK_CALLED(OnStateChange_CONNECTED);
1069 CHECK_CALLED(OnEnterScript);
1070 CHECK_CALLED(OnLeaveScript);
1071 test_state(script, SCRIPTSTATE_CONNECTED);
1073 dispex = get_script_dispatch(script, NULL);
1074 id = 0;
1075 get_disp_id(dispex, L"z", S_OK, &id);
1076 ok(id != -1, "id = -1\n");
1077 IDispatchEx_Release(dispex);
1079 SET_EXPECT(OnEnterScript);
1080 SET_EXPECT(OnLeaveScript);
1081 hr = IActiveScriptParse_ParseScriptText(parse, L"y", NULL, NULL, NULL, 0, 0, SCRIPTTEXT_ISEXPRESSION, &var, NULL);
1082 ok(hr == S_OK, "ParseScriptText failed: %08x\n", hr);
1083 ok(V_VT(&var) == VT_I4 && V_I2(&var) == 42, "V_VT(y) = %d, V_I2(y) = %d\n", V_VT(&var), V_I2(&var));
1084 CHECK_CALLED(OnEnterScript);
1085 CHECK_CALLED(OnLeaveScript);
1087 SET_EXPECT(OnEnterScript);
1088 SET_EXPECT(OnLeaveScript);
1089 hr = IActiveScriptParse_ParseScriptText(parse, L"v", NULL, NULL, NULL, 0, 0, SCRIPTTEXT_ISEXPRESSION, &var, NULL);
1090 ok(hr == S_OK, "ParseScriptText failed: %08x\n", hr);
1091 ok(V_VT(&var) == VT_I4 && V_I2(&var) == 10, "V_VT(var) = %d, V_I2(var) = %d\n", V_VT(&var), V_I2(&var));
1092 CHECK_CALLED(OnEnterScript);
1093 CHECK_CALLED(OnLeaveScript);
1095 SET_EXPECT(OnStateChange_DISCONNECTED);
1096 SET_EXPECT(OnStateChange_INITIALIZED);
1097 SET_EXPECT(OnStateChange_UNINITIALIZED);
1098 hr = IActiveScript_SetScriptState(script, SCRIPTSTATE_UNINITIALIZED);
1099 ok(hr == S_OK, "SetScriptState(SCRIPTSTATE_UNINITIALIZED) failed: %08x\n", hr);
1100 CHECK_CALLED(OnStateChange_DISCONNECTED);
1101 CHECK_CALLED(OnStateChange_INITIALIZED);
1102 CHECK_CALLED(OnStateChange_UNINITIALIZED);
1104 SET_EXPECT(GetLCID);
1105 SET_EXPECT(OnStateChange_INITIALIZED);
1106 hr = IActiveScript_SetScriptSite(script, &ActiveScriptSite);
1107 ok(hr == S_OK, "SetScriptSite failed: %08x\n", hr);
1108 CHECK_CALLED(GetLCID);
1109 CHECK_CALLED(OnStateChange_INITIALIZED);
1111 hr = IActiveScriptParse_ParseScriptText(parse, L"y = 2;\n", NULL, NULL, NULL, 0, 0, SCRIPTTEXT_ISPERSISTENT, NULL, NULL);
1112 ok(hr == S_OK, "ParseScriptText failed: %08x\n", hr);
1114 /* Closing the script engine removes all code (even if it's pending and persistent) */
1115 SET_EXPECT(OnStateChange_CLOSED);
1116 hr = IActiveScript_Close(script);
1117 ok(hr == S_OK, "Close failed: %08x\n", hr);
1118 CHECK_CALLED(OnStateChange_CLOSED);
1119 test_state(script, SCRIPTSTATE_CLOSED);
1120 test_no_script_dispatch(script);
1122 SET_EXPECT(OnStateChange_INITIALIZED);
1123 SET_EXPECT(GetLCID);
1124 hr = IActiveScript_SetScriptSite(script, &ActiveScriptSite);
1125 ok(hr == S_OK, "SetScriptSite failed: %08x\n", hr);
1126 CHECK_CALLED(OnStateChange_INITIALIZED);
1127 CHECK_CALLED(GetLCID);
1128 test_state(script, SCRIPTSTATE_INITIALIZED);
1130 SET_EXPECT(OnStateChange_CONNECTED);
1131 hr = IActiveScript_SetScriptState(script, SCRIPTSTATE_CONNECTED);
1132 ok(hr == S_OK, "SetScriptState(SCRIPTSTATE_CONNECTED) failed: %08x\n", hr);
1133 CHECK_CALLED(OnStateChange_CONNECTED);
1134 test_state(script, SCRIPTSTATE_CONNECTED);
1136 dispex = get_script_dispatch(script, NULL);
1137 id = 0;
1138 get_disp_id(dispex, L"y", DISP_E_UNKNOWNNAME, &id);
1139 ok(id == -1, "id = %d, expected -1\n", id);
1140 id = 0;
1141 get_disp_id(dispex, L"z", DISP_E_UNKNOWNNAME, &id);
1142 ok(id == -1, "id = %d, expected -1\n", id);
1143 IDispatchEx_Release(dispex);
1145 IActiveScriptParse_Release(parse);
1147 SET_EXPECT(OnStateChange_DISCONNECTED);
1148 SET_EXPECT(OnStateChange_INITIALIZED);
1149 SET_EXPECT(OnStateChange_CLOSED);
1150 ref = IActiveScript_Release(script);
1151 ok(!ref, "ref = %d\n", ref);
1152 CHECK_CALLED(OnStateChange_DISCONNECTED);
1153 CHECK_CALLED(OnStateChange_INITIALIZED);
1154 CHECK_CALLED(OnStateChange_CLOSED);
1157 static void test_named_items(void)
1159 static const WCHAR *global_idents[] =
1161 L"ActiveXObject",
1162 L"Array",
1163 L"Boolean",
1164 L"ReferenceError",
1165 L"RegExp",
1166 L"decodeURI",
1167 L"isNaN",
1169 L"global_this",
1170 L"globalCode_this",
1171 L"testFunc_global",
1172 L"testVar_global"
1174 static const WCHAR *global_code_test[] =
1176 L"testFunc_global();",
1177 L"if(testVar_global != 5) throw new Error();",
1178 L"var testObj = new testClassFunc();",
1179 L"eval(\"testFunc_global();\");",
1180 L"if(Math.abs(-17) != 17) throw new Error();"
1182 static const WCHAR *context_idents[] =
1184 L"testFunc",
1185 L"testVar",
1186 L"testFuncConstr"
1188 static const WCHAR *context_code_test[] =
1190 L"testFunc();",
1191 L"if(testVar != 42) throw new Error();",
1192 L"if(Math.abs(-testVar) != 42) throw new Error();",
1193 L"if(testFuncConstr() != testVar) throw new Error();"
1195 IDispatchEx *dispex, *dispex2;
1196 IActiveScriptParse *parse;
1197 IActiveScript *script;
1198 IDispatch *disp;
1199 VARIANT var;
1200 unsigned i;
1201 HRESULT hr;
1202 DISPID id;
1203 ULONG ref;
1204 BSTR bstr;
1206 script = create_jscript();
1208 hr = IActiveScript_QueryInterface(script, &IID_IActiveScriptParse, (void**)&parse);
1209 ok(hr == S_OK, "Could not get IActiveScriptParse: %08x\n", hr);
1211 test_state(script, SCRIPTSTATE_UNINITIALIZED);
1213 hr = IActiveScript_AddNamedItem(script, L"visibleItem", SCRIPTITEM_ISVISIBLE);
1214 ok(hr == E_UNEXPECTED, "AddNamedItem returned: %08x\n", hr);
1215 hr = IActiveScript_AddNamedItem(script, L"globalItem", SCRIPTITEM_GLOBALMEMBERS);
1216 ok(hr == E_UNEXPECTED, "AddNamedItem returned: %08x\n", hr);
1217 hr = IActiveScript_AddNamedItem(script, L"codeOnlyItem", SCRIPTITEM_CODEONLY);
1218 ok(hr == E_UNEXPECTED, "AddNamedItem returned: %08x\n", hr);
1219 hr = IActiveScript_AddNamedItem(script, L"persistent", SCRIPTITEM_ISPERSISTENT | SCRIPTITEM_CODEONLY);
1220 ok(hr == E_UNEXPECTED, "AddNamedItem returned: %08x\n", hr);
1222 SET_EXPECT(GetLCID);
1223 hr = IActiveScript_SetScriptSite(script, &ActiveScriptSite);
1224 ok(hr == S_OK, "SetScriptSite failed: %08x\n", hr);
1225 CHECK_CALLED(GetLCID);
1227 SET_EXPECT(GetItemInfo_global);
1228 hr = IActiveScript_AddNamedItem(script, L"globalItem", SCRIPTITEM_GLOBALMEMBERS);
1229 ok(hr == S_OK, "AddNamedItem failed: %08x\n", hr);
1230 CHECK_CALLED(GetItemInfo_global);
1232 hr = IActiveScript_AddNamedItem(script, L"visibleItem", SCRIPTITEM_ISVISIBLE);
1233 ok(hr == S_OK, "AddNamedItem failed: %08x\n", hr);
1234 hr = IActiveScript_AddNamedItem(script, L"visibleCodeItem", SCRIPTITEM_ISVISIBLE | SCRIPTITEM_CODEONLY);
1235 ok(hr == S_OK, "AddNamedItem failed: %08x\n", hr);
1236 hr = IActiveScript_AddNamedItem(script, L"codeOnlyItem", SCRIPTITEM_CODEONLY);
1237 ok(hr == S_OK, "AddNamedItem failed: %08x\n", hr);
1238 hr = IActiveScript_AddNamedItem(script, L"persistent", SCRIPTITEM_ISPERSISTENT | SCRIPTITEM_CODEONLY);
1239 ok(hr == S_OK, "AddNamedItem failed: %08x\n", hr);
1241 ok(global_named_item_ref > 0, "global_named_item_ref = %u\n", global_named_item_ref);
1242 ok(visible_named_item_ref == 0, "visible_named_item_ref = %u\n", visible_named_item_ref);
1243 ok(visible_code_named_item_ref == 0, "visible_code_named_item_ref = %u\n", visible_code_named_item_ref);
1244 ok(persistent_named_item_ref == 0, "persistent_named_item_ref = %u\n", persistent_named_item_ref);
1246 hr = IActiveScript_GetScriptDispatch(script, L"noContext", &disp);
1247 ok(hr == E_INVALIDARG, "GetScriptDispatch returned: %08x\n", hr);
1248 hr = IActiveScript_GetScriptDispatch(script, L"codeONLYItem", &disp);
1249 ok(hr == E_INVALIDARG, "GetScriptDispatch returned: %08x\n", hr);
1251 SET_EXPECT(GetItemInfo_global_code);
1252 hr = IActiveScript_AddNamedItem(script, L"globalCodeItem", SCRIPTITEM_GLOBALMEMBERS | SCRIPTITEM_CODEONLY);
1253 ok(hr == S_OK, "AddNamedItem failed: %08x\n", hr);
1254 CHECK_CALLED(GetItemInfo_global_code);
1256 dispex = get_script_dispatch(script, NULL);
1257 dispex2 = get_script_dispatch(script, L"globalItem");
1258 ok(dispex == dispex2, "get_script_dispatch returned different dispatch objects.\n");
1259 IDispatchEx_Release(dispex2);
1260 dispex2 = get_script_dispatch(script, L"globalCodeItem");
1261 ok(dispex == dispex2, "get_script_dispatch returned different dispatch objects.\n");
1262 IDispatchEx_Release(dispex2);
1263 dispex2 = get_script_dispatch(script, L"codeOnlyItem");
1264 ok(dispex != dispex2, "get_script_dispatch returned same dispatch objects.\n");
1266 SET_EXPECT(OnStateChange_INITIALIZED);
1267 hr = IActiveScriptParse_InitNew(parse);
1268 ok(hr == S_OK, "InitNew failed: %08x\n", hr);
1269 CHECK_CALLED(OnStateChange_INITIALIZED);
1271 SET_EXPECT(OnStateChange_CONNECTED);
1272 hr = IActiveScript_SetScriptState(script, SCRIPTSTATE_CONNECTED);
1273 ok(hr == S_OK, "SetScriptState(SCRIPTSTATE_CONNECTED) failed: %08x\n", hr);
1274 CHECK_CALLED(OnStateChange_CONNECTED);
1276 SET_EXPECT(testCall);
1277 parse_script(parse, L"testCall();");
1278 CHECK_CALLED(testCall);
1280 SET_EXPECT(GetItemInfo_visible);
1281 SET_EXPECT(testCall);
1282 parse_script(parse, L"visibleItem.testCall();");
1283 CHECK_CALLED(GetItemInfo_visible);
1284 CHECK_CALLED(testCall);
1286 SET_EXPECT(OnEnterScript);
1287 SET_EXPECT(OnLeaveScript);
1288 SET_EXPECT(testCall);
1289 hr = IActiveScriptParse_ParseScriptText(parse, L"testCall();", L"visibleCodeItem", NULL, NULL, 0, 0, 0, NULL, NULL);
1290 ok(hr == S_OK, "ParseScriptText failed: %08x\n", hr);
1291 CHECK_CALLED(OnEnterScript);
1292 CHECK_CALLED(OnLeaveScript);
1293 CHECK_CALLED(testCall);
1295 SET_EXPECT(OnEnterScript);
1296 SET_EXPECT(GetIDsOfNames);
1297 SET_EXPECT(OnScriptError);
1298 SET_EXPECT(OnLeaveScript);
1299 hr = IActiveScriptParse_ParseScriptText(parse, L"codeOnlyItem();", L"codeOnlyItem", NULL, NULL, 0, 0, 0, NULL, NULL);
1300 ok(FAILED(hr), "ParseScriptText returned: %08x\n", hr);
1301 CHECK_CALLED(OnEnterScript);
1302 CHECK_CALLED(GetIDsOfNames);
1303 CHECK_CALLED(OnScriptError);
1304 CHECK_CALLED(OnLeaveScript);
1306 hr = IActiveScript_GetScriptDispatch(script, L"visibleCodeItem", &disp);
1307 ok(hr == S_OK, "GetScriptDispatch returned: %08x\n", hr);
1308 SET_EXPECT(OnEnterScript);
1309 SET_EXPECT(OnLeaveScript);
1310 hr = IActiveScriptParse_ParseScriptText(parse, L"this", L"visibleCodeItem", NULL, NULL, 0, 0, SCRIPTTEXT_ISEXPRESSION, &var, NULL);
1311 ok(hr == S_OK, "ParseScriptText failed: %08x\n", hr);
1312 ok(V_VT(&var) == VT_DISPATCH && V_DISPATCH(&var) == disp,
1313 "Unexpected 'this': V_VT = %d, V_DISPATCH = %p\n", V_VT(&var), V_DISPATCH(&var));
1314 VariantClear(&var);
1315 CHECK_CALLED(OnEnterScript);
1316 CHECK_CALLED(OnLeaveScript);
1317 IDispatch_Release(disp);
1319 SET_EXPECT(GetItemInfo_visible_code);
1320 SET_EXPECT(testCall);
1321 parse_script(parse, L"visibleCodeItem.testCall();");
1322 CHECK_CALLED(GetItemInfo_visible_code);
1323 CHECK_CALLED(testCall);
1325 ok(global_named_item_ref > 0, "global_named_item_ref = %u\n", global_named_item_ref);
1326 ok(visible_named_item_ref > 0, "visible_named_item_ref = %u\n", visible_named_item_ref);
1327 ok(visible_code_named_item_ref > 0, "visible_code_named_item_ref = %u\n", visible_code_named_item_ref);
1328 ok(persistent_named_item_ref == 0, "persistent_named_item_ref = %u\n", persistent_named_item_ref);
1330 SET_EXPECT(testCall);
1331 parse_script(parse, L"visibleItem.testCall();");
1332 CHECK_CALLED(testCall);
1334 hr = IActiveScriptParse_ParseScriptText(parse, L"function testFunc() { }", L"CodeOnlyItem", NULL, NULL, 0, 0, 0, NULL, NULL);
1335 ok(hr == E_INVALIDARG, "ParseScriptText returned: %08x\n", hr);
1337 SET_EXPECT(OnEnterScript);
1338 SET_EXPECT(GetIDsOfNames);
1339 SET_EXPECT(OnLeaveScript);
1340 hr = IActiveScriptParse_ParseScriptText(parse, L""
1341 "var global_this = 0;\n"
1342 "var globalCode_this = 0;\n"
1343 "function testFunc_global() { }\n"
1344 "var testVar_global = 10;\n"
1345 "function testClassFunc() { this.x = 10; }\n",
1346 NULL, NULL, NULL, 0, 0, SCRIPTTEXT_ISPERSISTENT, NULL, NULL);
1347 ok(hr == S_OK, "ParseScriptText failed: %08x\n", hr);
1348 CHECK_CALLED(OnEnterScript);
1349 CHECK_CALLED(GetIDsOfNames);
1350 CHECK_CALLED(OnLeaveScript);
1352 SET_EXPECT(OnEnterScript);
1353 SET_EXPECT(OnLeaveScript);
1354 hr = IActiveScriptParse_ParseScriptText(parse, L"function testFunc() { }\n", L"codeOnlyItem", NULL, NULL, 0, 0, 0, NULL, NULL);
1355 ok(hr == S_OK, "ParseScriptText failed: %08x\n", hr);
1356 CHECK_CALLED(OnEnterScript);
1357 CHECK_CALLED(OnLeaveScript);
1359 SET_EXPECT(OnEnterScript);
1360 SET_EXPECT(OnLeaveScript);
1361 hr = IActiveScriptParse_ParseScriptText(parse, L""
1362 "var testVar = 42;\n"
1363 "testVar_global = 5;\n"
1364 "var testFuncConstr = new Function(\"return testVar;\");\n",
1365 L"codeOnlyItem", NULL, NULL, 0, 0, SCRIPTTEXT_ISPERSISTENT, NULL, NULL);
1366 ok(hr == S_OK, "ParseScriptText failed: %08x\n", hr);
1367 CHECK_CALLED(OnEnterScript);
1368 CHECK_CALLED(OnLeaveScript);
1370 SET_EXPECT(OnEnterScript);
1371 SET_EXPECT(GetIDsOfNames_visible);
1372 SET_EXPECT(OnLeaveScript);
1373 hr = IActiveScriptParse_ParseScriptText(parse, L"var abc;\n", L"visibleItem", NULL, NULL, 0, 0, 0, NULL, NULL);
1374 ok(hr == S_OK, "ParseScriptText failed: %08x\n", hr);
1375 CHECK_CALLED(OnEnterScript);
1376 CHECK_CALLED(GetIDsOfNames_visible);
1377 CHECK_CALLED(OnLeaveScript);
1379 SET_EXPECT(OnEnterScript);
1380 SET_EXPECT(OnLeaveScript);
1381 hr = IActiveScriptParse_ParseScriptText(parse, L"abc = 5;\n", L"visibleItem", NULL, NULL, 0, 0, 0, NULL, NULL);
1382 ok(hr == S_OK, "ParseScriptText failed: %08x\n", hr);
1383 CHECK_CALLED(OnEnterScript);
1384 CHECK_CALLED(OnLeaveScript);
1385 SET_EXPECT(OnEnterScript);
1386 SET_EXPECT(GetIDsOfNames_visible);
1387 SET_EXPECT(OnLeaveScript);
1388 hr = IActiveScriptParse_ParseScriptText(parse, L"testVar_global = 5;\n", L"visibleItem", NULL, NULL, 0, 0, 0, NULL, NULL);
1389 ok(hr == S_OK, "ParseScriptText failed: %08x\n", hr);
1390 CHECK_CALLED(OnEnterScript);
1391 CHECK_CALLED(GetIDsOfNames_visible);
1392 CHECK_CALLED(OnLeaveScript);
1394 SET_EXPECT(OnEnterScript);
1395 SET_EXPECT(OnLeaveScript);
1396 hr = IActiveScriptParse_ParseScriptText(parse, L"var abc; testVar_global = 5;\n", L"visibleCodeItem", NULL, NULL, 0, 0, 0, NULL, NULL);
1397 ok(hr == S_OK, "ParseScriptText failed: %08x\n", hr);
1398 CHECK_CALLED(OnEnterScript);
1399 CHECK_CALLED(OnLeaveScript);
1401 SET_EXPECT(OnEnterScript);
1402 SET_EXPECT(OnLeaveScript);
1403 hr = IActiveScriptParse_ParseScriptText(parse, L"global_this = this;\n", L"globalItem", NULL, NULL, 0, 0, SCRIPTTEXT_ISPERSISTENT, NULL, NULL);
1404 ok(hr == S_OK, "ParseScriptText failed: %08x\n", hr);
1405 CHECK_CALLED(OnEnterScript);
1406 CHECK_CALLED(OnLeaveScript);
1408 SET_EXPECT(OnEnterScript);
1409 SET_EXPECT(OnLeaveScript);
1410 hr = IActiveScriptParse_ParseScriptText(parse, L"globalCode_this = this;\n", L"globalCodeItem", NULL, NULL, 0, 0, SCRIPTTEXT_ISPERSISTENT, NULL, NULL);
1411 ok(hr == S_OK, "ParseScriptText failed: %08x\n", hr);
1412 CHECK_CALLED(OnEnterScript);
1413 CHECK_CALLED(OnLeaveScript);
1415 for (i = 0; i < ARRAY_SIZE(global_idents); i++)
1417 bstr = SysAllocString(global_idents[i]);
1418 id = 0;
1419 hr = IDispatchEx_GetDispID(dispex, bstr, 0, &id);
1420 ok(hr == S_OK, "GetDispID(%s) returned %08x\n", wine_dbgstr_w(global_idents[i]), hr);
1421 ok(id != -1, "[%s] id = -1\n", wine_dbgstr_w(global_idents[i]));
1423 id = 0;
1424 hr = IDispatchEx_GetDispID(dispex2, bstr, 0, &id);
1425 ok(hr == DISP_E_UNKNOWNNAME, "GetDispID(%s) returned %08x\n", wine_dbgstr_w(global_idents[i]), hr);
1426 ok(id == -1, "[%s] id = %d, expected -1\n", wine_dbgstr_w(global_idents[i]), id);
1427 SysFreeString(bstr);
1430 for (i = 0; i < ARRAY_SIZE(context_idents); i++)
1432 bstr = SysAllocString(context_idents[i]);
1433 id = 0;
1434 hr = IDispatchEx_GetDispID(dispex, bstr, 0, &id);
1435 ok(hr == DISP_E_UNKNOWNNAME, "GetDispID(%s) returned %08x\n", wine_dbgstr_w(context_idents[i]), hr);
1436 ok(id == -1, "[%s] id = %d, expected -1\n", wine_dbgstr_w(context_idents[i]), id);
1437 id = 0;
1438 hr = IDispatchEx_GetDispID(dispex2, bstr, 0, &id);
1439 ok(hr == S_OK, "GetDispID(%s) returned %08x\n", wine_dbgstr_w(context_idents[i]), hr);
1440 ok(id != -1, "[%s] id = -1\n", wine_dbgstr_w(context_idents[i]));
1441 SysFreeString(bstr);
1444 for (i = 0; i < ARRAY_SIZE(global_code_test); i++)
1446 SET_EXPECT(OnEnterScript);
1447 SET_EXPECT(OnLeaveScript);
1448 hr = IActiveScriptParse_ParseScriptText(parse, global_code_test[i], NULL, NULL, NULL, 0, 0, 0, NULL, NULL);
1449 ok(hr == S_OK, "ParseScriptText(%s) failed: %08x\n", wine_dbgstr_w(global_code_test[i]), hr);
1450 CHECK_CALLED(OnEnterScript);
1451 CHECK_CALLED(OnLeaveScript);
1453 SET_EXPECT(OnEnterScript);
1454 SET_EXPECT(GetIDsOfNames);
1455 SET_EXPECT(OnLeaveScript);
1456 hr = IActiveScriptParse_ParseScriptText(parse, global_code_test[i], L"codeOnlyItem", NULL, NULL, 0, 0, 0, NULL, NULL);
1457 ok(hr == S_OK, "ParseScriptText(%s) failed: %08x\n", wine_dbgstr_w(global_code_test[i]), hr);
1458 CHECK_CALLED(OnEnterScript);
1459 CHECK_CALLED(OnLeaveScript);
1462 for (i = 0; i < ARRAY_SIZE(context_code_test); i++)
1464 SET_EXPECT(OnEnterScript);
1465 SET_EXPECT(GetIDsOfNames);
1466 SET_EXPECT(OnScriptError);
1467 SET_EXPECT(OnLeaveScript);
1468 hr = IActiveScriptParse_ParseScriptText(parse, context_code_test[i], NULL, NULL, NULL, 0, 0, 0, NULL, NULL);
1469 ok(FAILED(hr), "ParseScriptText(%s) returned: %08x\n", wine_dbgstr_w(context_code_test[i]), hr);
1470 CHECK_CALLED(OnEnterScript);
1471 CHECK_CALLED(GetIDsOfNames);
1472 CHECK_CALLED(OnScriptError);
1473 CHECK_CALLED(OnLeaveScript);
1475 SET_EXPECT(OnEnterScript);
1476 SET_EXPECT(OnLeaveScript);
1477 hr = IActiveScriptParse_ParseScriptText(parse, context_code_test[i], L"codeOnlyItem", NULL, NULL, 0, 0, 0, NULL, NULL);
1478 ok(hr == S_OK, "ParseScriptText(%s) failed: %08x\n", wine_dbgstr_w(context_code_test[i]), hr);
1479 CHECK_CALLED(OnEnterScript);
1480 CHECK_CALLED(OnLeaveScript);
1483 SET_EXPECT(OnEnterScript);
1484 SET_EXPECT(OnLeaveScript);
1485 hr = IActiveScriptParse_ParseScriptText(parse, L"this", NULL, NULL, NULL, 0, 0, SCRIPTTEXT_ISEXPRESSION, &var, NULL);
1486 ok(hr == S_OK, "ParseScriptText failed: %08x\n", hr);
1487 ok(V_VT(&var) == VT_DISPATCH && V_DISPATCH(&var) == &global_named_item,
1488 "Unexpected 'this': V_VT = %d, V_DISPATCH = %p\n", V_VT(&var), V_DISPATCH(&var));
1489 VariantClear(&var);
1490 CHECK_CALLED(OnEnterScript);
1491 CHECK_CALLED(OnLeaveScript);
1493 SET_EXPECT(OnEnterScript);
1494 SET_EXPECT(OnLeaveScript);
1495 hr = IActiveScriptParse_ParseScriptText(parse, L"this", L"visibleItem", NULL, NULL, 0, 0, SCRIPTTEXT_ISEXPRESSION, &var, NULL);
1496 ok(hr == S_OK, "ParseScriptText failed: %08x\n", hr);
1497 ok(V_VT(&var) == VT_DISPATCH && V_DISPATCH(&var) == &visible_named_item,
1498 "Unexpected 'this': V_VT = %d, V_DISPATCH = %p\n", V_VT(&var), V_DISPATCH(&var));
1499 VariantClear(&var);
1500 CHECK_CALLED(OnEnterScript);
1501 CHECK_CALLED(OnLeaveScript);
1503 SET_EXPECT(OnEnterScript);
1504 SET_EXPECT(OnLeaveScript);
1505 hr = IActiveScriptParse_ParseScriptText(parse, L"this", L"codeOnlyItem", NULL, NULL, 0, 0, SCRIPTTEXT_ISEXPRESSION, &var, NULL);
1506 ok(hr == S_OK, "ParseScriptText failed: %08x\n", hr);
1507 ok(V_VT(&var) == VT_DISPATCH && V_DISPATCH(&var) == (IDispatch*)dispex2,
1508 "Unexpected 'this': V_VT = %d, V_DISPATCH = %p\n", V_VT(&var), V_DISPATCH(&var));
1509 VariantClear(&var);
1510 CHECK_CALLED(OnEnterScript);
1511 CHECK_CALLED(OnLeaveScript);
1513 SET_EXPECT(OnEnterScript);
1514 SET_EXPECT(OnLeaveScript);
1515 hr = IActiveScriptParse_ParseScriptText(parse, L"globalCode_this", NULL, NULL, NULL, 0, 0, SCRIPTTEXT_ISEXPRESSION, &var, NULL);
1516 ok(hr == S_OK, "ParseScriptText failed: %08x\n", hr);
1517 ok(V_VT(&var) == VT_DISPATCH && V_DISPATCH(&var) == &global_named_item,
1518 "Unexpected 'this': V_VT = %d, V_DISPATCH = %p\n", V_VT(&var), V_DISPATCH(&var));
1519 VariantClear(&var);
1520 CHECK_CALLED(OnEnterScript);
1521 CHECK_CALLED(OnLeaveScript);
1523 IDispatchEx_Release(dispex2);
1524 IDispatchEx_Release(dispex);
1526 dispex = get_script_dispatch(script, L"persistent");
1527 SET_EXPECT(OnEnterScript);
1528 SET_EXPECT(OnLeaveScript);
1529 hr = IActiveScriptParse_ParseScriptText(parse, L"this", L"persistent", NULL, NULL, 0, 0, SCRIPTTEXT_ISEXPRESSION, &var, NULL);
1530 ok(hr == S_OK, "ParseScriptText failed: %08x\n", hr);
1531 ok(V_VT(&var) == VT_DISPATCH && V_DISPATCH(&var) == (IDispatch*)dispex,
1532 "Unexpected 'this': V_VT = %d, V_DISPATCH = %p\n", V_VT(&var), V_DISPATCH(&var));
1533 VariantClear(&var);
1534 CHECK_CALLED(OnEnterScript);
1535 CHECK_CALLED(OnLeaveScript);
1536 IDispatchEx_Release(dispex);
1538 SET_EXPECT(OnEnterScript);
1539 SET_EXPECT(OnLeaveScript);
1540 hr = IActiveScriptParse_ParseScriptText(parse, L"var x = 13;\n", L"persistent", NULL, NULL, 0, 0, SCRIPTTEXT_ISPERSISTENT, NULL, NULL);
1541 ok(hr == S_OK, "ParseScriptText failed: %08x\n", hr);
1542 CHECK_CALLED(OnEnterScript);
1543 CHECK_CALLED(OnLeaveScript);
1544 SET_EXPECT(OnEnterScript);
1545 SET_EXPECT(OnLeaveScript);
1546 hr = IActiveScriptParse_ParseScriptText(parse, L"x = 10;\n", L"persistent", NULL, NULL, 0, 0, 0, NULL, NULL);
1547 ok(hr == S_OK, "ParseScriptText failed: %08x\n", hr);
1548 CHECK_CALLED(OnEnterScript);
1549 CHECK_CALLED(OnLeaveScript);
1550 SET_EXPECT(OnEnterScript);
1551 SET_EXPECT(OnLeaveScript);
1552 hr = IActiveScriptParse_ParseScriptText(parse, L"x", L"persistent", NULL, NULL, 0, 0, SCRIPTTEXT_ISEXPRESSION, &var, NULL);
1553 ok(hr == S_OK, "ParseScriptText failed: %08x\n", hr);
1554 ok(V_VT(&var) == VT_I4 && V_I4(&var) == 10, "Unexpected 'x': V_VT = %d, V_I4 = %d\n", V_VT(&var), V_I4(&var));
1555 CHECK_CALLED(OnEnterScript);
1556 CHECK_CALLED(OnLeaveScript);
1558 dispex = get_script_dispatch(script, L"persistent");
1560 /* reinitialize script engine */
1562 SET_EXPECT(OnStateChange_DISCONNECTED);
1563 SET_EXPECT(OnStateChange_INITIALIZED);
1564 SET_EXPECT(OnStateChange_UNINITIALIZED);
1565 hr = IActiveScript_SetScriptState(script, SCRIPTSTATE_UNINITIALIZED);
1566 ok(hr == S_OK, "SetScriptState(SCRIPTSTATE_UNINITIALIZED) failed: %08x\n", hr);
1567 CHECK_CALLED(OnStateChange_DISCONNECTED);
1568 CHECK_CALLED(OnStateChange_INITIALIZED);
1569 CHECK_CALLED(OnStateChange_UNINITIALIZED);
1570 test_no_script_dispatch(script);
1572 ok(global_named_item_ref == 0, "global_named_item_ref = %u\n", global_named_item_ref);
1573 ok(visible_named_item_ref == 0, "visible_named_item_ref = %u\n", visible_named_item_ref);
1574 ok(visible_code_named_item_ref == 0, "visible_code_named_item_ref = %u\n", visible_code_named_item_ref);
1575 ok(persistent_named_item_ref == 0, "persistent_named_item_ref = %u\n", persistent_named_item_ref);
1577 hr = IActiveScript_GetScriptDispatch(script, L"codeOnlyItem", &disp);
1578 ok(hr == E_UNEXPECTED, "hr = %08x, expected E_UNEXPECTED\n", hr);
1580 SET_EXPECT(GetLCID);
1581 SET_EXPECT(OnStateChange_INITIALIZED);
1582 SET_EXPECT(GetItemInfo_persistent);
1583 hr = IActiveScript_SetScriptSite(script, &ActiveScriptSite);
1584 ok(hr == S_OK, "SetScriptSite failed: %08x\n", hr);
1585 CHECK_CALLED(GetLCID);
1586 CHECK_CALLED(OnStateChange_INITIALIZED);
1587 CHECK_CALLED(GetItemInfo_persistent);
1588 ok(persistent_named_item_ref > 0, "persistent_named_item_ref = %u\n", persistent_named_item_ref);
1590 hr = IActiveScript_AddNamedItem(script, L"codeOnlyItem", SCRIPTITEM_CODEONLY);
1591 ok(hr == S_OK, "AddNamedItem failed: %08x\n", hr);
1593 SET_EXPECT(OnStateChange_CONNECTED);
1594 SET_EXPECT_MULTI(OnEnterScript, 5);
1595 SET_EXPECT_MULTI(OnLeaveScript, 5);
1596 SET_EXPECT(GetIDsOfNames_persistent);
1597 hr = IActiveScript_SetScriptState(script, SCRIPTSTATE_CONNECTED);
1598 ok(hr == S_OK, "SetScriptState(SCRIPTSTATE_CONNECTED) failed: %08x\n", hr);
1599 CHECK_CALLED(OnStateChange_CONNECTED);
1600 CHECK_CALLED_MULTI(OnEnterScript, 5);
1601 CHECK_CALLED_MULTI(OnLeaveScript, 5);
1602 CHECK_CALLED(GetIDsOfNames_persistent);
1603 test_state(script, SCRIPTSTATE_CONNECTED);
1605 dispex2 = get_script_dispatch(script, L"persistent");
1606 ok(dispex != dispex2, "Same script dispatch returned for \"persistent\" named item\n");
1607 IDispatchEx_Release(dispex2);
1608 IDispatchEx_Release(dispex);
1609 SET_EXPECT(OnEnterScript);
1610 SET_EXPECT(OnLeaveScript);
1611 hr = IActiveScriptParse_ParseScriptText(parse, L"x", L"persistent", NULL, NULL, 0, 0, SCRIPTTEXT_ISEXPRESSION, &var, NULL);
1612 ok(hr == S_OK, "ParseScriptText failed: %08x\n", hr);
1613 ok(V_VT(&var) == VT_I4 && V_I4(&var) == 13, "Unexpected 'x': V_VT = %d, V_I4 = %d\n", V_VT(&var), V_I4(&var));
1614 CHECK_CALLED(OnEnterScript);
1615 CHECK_CALLED(OnLeaveScript);
1617 /* this object it set to named idem when persistent items are re-initialized, even for CODEONLY items */
1618 SET_EXPECT(OnEnterScript);
1619 SET_EXPECT(OnLeaveScript);
1620 hr = IActiveScriptParse_ParseScriptText(parse, L"this", L"persistent", NULL, NULL, 0, 0, SCRIPTTEXT_ISEXPRESSION, &var, NULL);
1621 ok(hr == S_OK, "ParseScriptText failed: %08x\n", hr);
1622 ok(V_VT(&var) == VT_DISPATCH && V_DISPATCH(&var) == &persistent_named_item,
1623 "Unexpected 'this': V_VT = %d, V_DISPATCH = %p\n", V_VT(&var), V_DISPATCH(&var));
1624 VariantClear(&var);
1625 CHECK_CALLED(OnEnterScript);
1626 CHECK_CALLED(OnLeaveScript);
1628 /* lookups also query named items */
1629 SET_EXPECT(OnEnterScript);
1630 SET_EXPECT(OnLeaveScript);
1631 SET_EXPECT(GetIDsOfNames_persistent);
1632 hr = IActiveScriptParse_ParseScriptText(parse, L"var abc123;", L"persistent", NULL, NULL, 0, 0, 0, NULL, NULL);
1633 ok(hr == S_OK, "ParseScriptText failed: %08x\n", hr);
1634 CHECK_CALLED(OnEnterScript);
1635 CHECK_CALLED(OnLeaveScript);
1636 CHECK_CALLED(GetIDsOfNames_persistent);
1638 SET_EXPECT(OnEnterScript);
1639 SET_EXPECT(OnLeaveScript);
1640 SET_EXPECT(GetIDsOfNames_persistent);
1641 SET_EXPECT(OnScriptError);
1642 hr = IActiveScriptParse_ParseScriptText(parse, L"testCall();", L"persistent", NULL, NULL, 0, 0, 0, NULL, NULL);
1643 ok(FAILED(hr), "ParseScriptText returned: %08x\n", hr);
1644 CHECK_CALLED(OnEnterScript);
1645 CHECK_CALLED(OnLeaveScript);
1646 CHECK_CALLED(GetIDsOfNames_persistent);
1647 CHECK_CALLED(OnScriptError);
1649 dispex = get_script_dispatch(script, NULL);
1650 for (i = 0; i < ARRAY_SIZE(global_idents); i++)
1652 bstr = SysAllocString(global_idents[i]);
1653 id = 0;
1654 hr = IDispatchEx_GetDispID(dispex, bstr, 0, &id);
1655 ok(hr == S_OK, "GetDispID(%s) returned %08x\n", wine_dbgstr_w(global_idents[i]), hr);
1656 ok(id != -1, "[%s] id = -1\n", wine_dbgstr_w(global_idents[i]));
1657 SysFreeString(bstr);
1660 for (i = 0; i < ARRAY_SIZE(context_idents); i++)
1662 bstr = SysAllocString(context_idents[i]);
1663 id = 0;
1664 hr = IDispatchEx_GetDispID(dispex, bstr, 0, &id);
1665 ok(hr == DISP_E_UNKNOWNNAME, "GetDispID(%s) returned %08x\n", wine_dbgstr_w(context_idents[i]), hr);
1666 ok(id == -1, "[%s] id = %d, expected -1\n", wine_dbgstr_w(context_idents[i]), id);
1667 SysFreeString(bstr);
1670 SET_EXPECT(OnEnterScript);
1671 SET_EXPECT(OnLeaveScript);
1672 hr = IActiveScriptParse_ParseScriptText(parse, L"global_this", NULL, NULL, NULL, 0, 0, SCRIPTTEXT_ISEXPRESSION, &var, NULL);
1673 ok(hr == S_OK, "ParseScriptText failed: %08x\n", hr);
1674 ok(V_VT(&var) == VT_DISPATCH && V_DISPATCH(&var) == (IDispatch*)dispex,
1675 "Unexpected 'this': V_VT = %d, V_DISPATCH = %p\n", V_VT(&var), V_DISPATCH(&var));
1676 VariantClear(&var);
1677 CHECK_CALLED(OnEnterScript);
1678 CHECK_CALLED(OnLeaveScript);
1680 SET_EXPECT(OnEnterScript);
1681 SET_EXPECT(OnLeaveScript);
1682 hr = IActiveScriptParse_ParseScriptText(parse, L"globalCode_this", NULL, NULL, NULL, 0, 0, SCRIPTTEXT_ISEXPRESSION, &var, NULL);
1683 ok(hr == S_OK, "ParseScriptText failed: %08x\n", hr);
1684 ok(V_VT(&var) == VT_DISPATCH && V_DISPATCH(&var) == (IDispatch*)dispex,
1685 "Unexpected 'this': V_VT = %d, V_DISPATCH = %p\n", V_VT(&var), V_DISPATCH(&var));
1686 VariantClear(&var);
1687 CHECK_CALLED(OnEnterScript);
1688 CHECK_CALLED(OnLeaveScript);
1690 SET_EXPECT(OnEnterScript);
1691 SET_EXPECT(OnLeaveScript);
1692 hr = IActiveScriptParse_ParseScriptText(parse, L"global_this = 0; globalCode_this = 0;\n", NULL, NULL, NULL, 0, 0, 0, NULL, NULL);
1693 ok(hr == S_OK, "ParseScriptText failed: %08x\n", hr);
1694 CHECK_CALLED(OnEnterScript);
1695 CHECK_CALLED(OnLeaveScript);
1696 IDispatchEx_Release(dispex);
1698 dispex = get_script_dispatch(script, L"codeOnlyItem");
1699 for (i = 0; i < ARRAY_SIZE(global_idents); i++)
1701 bstr = SysAllocString(global_idents[i]);
1702 id = 0;
1703 hr = IDispatchEx_GetDispID(dispex, bstr, 0, &id);
1704 ok(hr == DISP_E_UNKNOWNNAME, "GetDispID(%s) returned %08x\n", wine_dbgstr_w(global_idents[i]), hr);
1705 ok(id == -1, "[%s] id = %d, expected -1\n", wine_dbgstr_w(global_idents[i]), id);
1706 SysFreeString(bstr);
1709 for (i = 0; i < ARRAY_SIZE(context_idents); i++)
1711 bstr = SysAllocString(context_idents[i]);
1712 id = 0;
1713 hr = IDispatchEx_GetDispID(dispex, bstr, 0, &id);
1714 ok(hr == DISP_E_UNKNOWNNAME, "GetDispID(%s) returned %08x\n", wine_dbgstr_w(context_idents[i]), hr);
1715 ok(id == -1, "[%s] id = %d, expected -1\n", wine_dbgstr_w(context_idents[i]), id);
1716 SysFreeString(bstr);
1718 IDispatchEx_Release(dispex);
1720 for (i = 0; i < ARRAY_SIZE(global_code_test); i++)
1722 SET_EXPECT(OnEnterScript);
1723 SET_EXPECT(OnLeaveScript);
1724 hr = IActiveScriptParse_ParseScriptText(parse, global_code_test[i], NULL, NULL, NULL, 0, 0, 0, NULL, NULL);
1725 ok(hr == S_OK, "ParseScriptText(%s) failed: %08x\n", wine_dbgstr_w(global_code_test[i]), hr);
1726 CHECK_CALLED(OnEnterScript);
1727 CHECK_CALLED(OnLeaveScript);
1728 SET_EXPECT(OnEnterScript);
1729 SET_EXPECT(OnLeaveScript);
1730 hr = IActiveScriptParse_ParseScriptText(parse, global_code_test[i], L"codeOnlyItem", NULL, NULL, 0, 0, 0, NULL, NULL);
1731 ok(hr == S_OK, "ParseScriptText(%s) failed: %08x\n", wine_dbgstr_w(global_code_test[i]), hr);
1732 CHECK_CALLED(OnEnterScript);
1733 CHECK_CALLED(OnLeaveScript);
1736 for (i = 0; i < ARRAY_SIZE(context_code_test); i++)
1738 SET_EXPECT(OnEnterScript);
1739 SET_EXPECT(OnScriptError);
1740 SET_EXPECT(OnLeaveScript);
1741 hr = IActiveScriptParse_ParseScriptText(parse, context_code_test[i], NULL, NULL, NULL, 0, 0, 0, NULL, NULL);
1742 ok(FAILED(hr), "ParseScriptText(%s) returned: %08x\n", wine_dbgstr_w(context_code_test[i]), hr);
1743 CHECK_CALLED(OnEnterScript);
1744 CHECK_CALLED(OnScriptError);
1745 CHECK_CALLED(OnLeaveScript);
1747 SET_EXPECT(OnEnterScript);
1748 SET_EXPECT(OnScriptError);
1749 SET_EXPECT(OnLeaveScript);
1750 hr = IActiveScriptParse_ParseScriptText(parse, context_code_test[i], L"codeOnlyItem", NULL, NULL, 0, 0, 0, NULL, NULL);
1751 ok(FAILED(hr), "ParseScriptText(%s) returned: %08x\n", wine_dbgstr_w(context_code_test[i]), hr);
1752 CHECK_CALLED(OnEnterScript);
1753 CHECK_CALLED(OnScriptError);
1754 CHECK_CALLED(OnLeaveScript);
1757 SET_EXPECT(OnStateChange_DISCONNECTED);
1758 SET_EXPECT(OnStateChange_INITIALIZED);
1759 SET_EXPECT(OnStateChange_CLOSED);
1760 hr = IActiveScript_Close(script);
1761 ok(hr == S_OK, "Close failed: %08x\n", hr);
1762 CHECK_CALLED(OnStateChange_DISCONNECTED);
1763 CHECK_CALLED(OnStateChange_INITIALIZED);
1764 CHECK_CALLED(OnStateChange_CLOSED);
1766 ok(global_named_item_ref == 0, "global_named_item_ref = %u\n", global_named_item_ref);
1767 ok(visible_named_item_ref == 0, "visible_named_item_ref = %u\n", visible_named_item_ref);
1768 ok(visible_code_named_item_ref == 0, "visible_code_named_item_ref = %u\n", visible_code_named_item_ref);
1769 ok(persistent_named_item_ref == 0, "persistent_named_item_ref = %u\n", persistent_named_item_ref);
1771 test_state(script, SCRIPTSTATE_CLOSED);
1772 IActiveScriptParse_Release(parse);
1774 ref = IActiveScript_Release(script);
1775 ok(!ref, "ref = %d\n", ref);
1778 static void test_typeinfo(const WCHAR *parse_func_name)
1780 static struct
1782 const WCHAR *name;
1783 UINT num_args;
1784 } func[] =
1786 { L"emptyfn", 0 },
1787 { L"voidfn", 0 },
1788 { L"math", 2 },
1789 { L"foobar", 1 },
1790 { L"C", 0 },
1791 { L"funcvar", 2 },
1792 { L"f1", 1 },
1793 { L"f2", 1 }
1795 static struct
1797 const WCHAR *name;
1798 } var[] =
1800 { L"global_var" },
1801 { L"uninit" },
1802 { L"obj" }
1804 const WCHAR *source = L""
1805 "var global_var = 42;\n"
1807 "function emptyfn() { }\n"
1808 "function voidfn() { return void(0); }\n"
1809 "function math(x, y) { return x - y; }\n"
1810 "function foobar(x) { return \"foobar\"; }\n"
1812 "function C() {\n"
1813 " this.x;\n"
1814 " this.strret = function() { return \"ret\"; }\n"
1815 "}\n"
1817 "var uninit;\n"
1818 "var obj = new C();\n"
1820 "var funcvar = function(x, y) { return x * y; };\n"
1821 "var native_func = decodeURI;\n"
1823 "(function() {\n"
1824 " f1 = function infuncexpr(x) { return 1; }\n"
1825 " f2 = function infuncexpr(x) { return 2; }\n"
1826 "})();\n";
1827 UINT expected_funcs_cnt = parse_func_name ? 0 : ARRAY_SIZE(func);
1828 UINT expected_vars_cnt = parse_func_name ? 0 : ARRAY_SIZE(var);
1830 ITypeInfo *typeinfo, *typeinfo2;
1831 ITypeComp *typecomp, *typecomp2;
1832 IActiveScriptParse *parser;
1833 IActiveScript *script;
1834 FUNCDESC *funcdesc;
1835 VARDESC *vardesc;
1836 IDispatchEx *disp;
1837 DESCKIND desckind;
1838 INT implTypeFlags;
1839 UINT count, index;
1840 HREFTYPE reftype;
1841 BINDPTR bindptr;
1842 MEMBERID memid;
1843 TYPEATTR *attr;
1844 HRESULT hr;
1845 WCHAR str[64], *names = str;
1846 BSTR bstr, bstrs[5];
1847 void *obj;
1848 int i;
1850 if (parse_func_name)
1851 trace("Testing TypeInfo for function %s...\n", wine_dbgstr_w(parse_func_name));
1852 else
1853 trace("Testing TypeInfo for script dispatch...\n");
1855 script = create_jscript();
1857 hr = IActiveScript_QueryInterface(script, &IID_IActiveScriptParse, (void**)&parser);
1858 ok(hr == S_OK, "Could not get IActiveScriptParse iface: %08x\n", hr);
1860 SET_EXPECT(GetLCID);
1861 hr = IActiveScript_SetScriptSite(script, &ActiveScriptSite);
1862 ok(hr == S_OK, "SetScriptSite failed: %08x\n", hr);
1863 CHECK_CALLED(GetLCID);
1865 SET_EXPECT(OnStateChange_INITIALIZED);
1866 hr = IActiveScriptParse_InitNew(parser);
1867 ok(hr == S_OK, "InitNew failed: %08x\n", hr);
1868 CHECK_CALLED(OnStateChange_INITIALIZED);
1870 SET_EXPECT(OnStateChange_CONNECTED);
1871 hr = IActiveScript_SetScriptState(script, SCRIPTSTATE_CONNECTED);
1872 ok(hr == S_OK, "SetScriptState(SCRIPTSTATE_CONNECTED) failed: %08x\n", hr);
1873 CHECK_CALLED(OnStateChange_CONNECTED);
1875 if (parse_func_name)
1877 IActiveScriptParseProcedure2 *parse_proc;
1878 IDispatch *proc_disp;
1880 hr = IActiveScript_QueryInterface(script, &IID_IActiveScriptParseProcedure2, (void**)&parse_proc);
1881 ok(hr == S_OK, "Could not get IActiveScriptParse: %08x\n", hr);
1883 hr = IActiveScriptParseProcedure2_ParseProcedureText(parse_proc, source, NULL, parse_func_name,
1884 NULL, NULL, NULL, 0, 0, SCRIPTPROC_IMPLICIT_THIS | SCRIPTPROC_IMPLICIT_PARENTS, &proc_disp);
1885 ok(hr == S_OK, "ParseProcedureText failed: %08x\n", hr);
1886 IActiveScriptParseProcedure2_Release(parse_proc);
1888 hr = IDispatch_QueryInterface(proc_disp, &IID_IDispatchEx, (void**)&disp);
1889 ok(hr == S_OK, "Could not get IDispatchEx: %08x\n", hr);
1890 IDispatch_Release(proc_disp);
1892 else
1894 parse_script(parser, source);
1895 disp = get_script_dispatch(script, NULL);
1898 hr = IDispatchEx_QueryInterface(disp, &IID_ITypeInfo, (void**)&typeinfo);
1899 ok(hr == E_NOINTERFACE, "QueryInterface(IID_ITypeInfo) returned: %08x\n", hr);
1900 hr = IDispatchEx_GetTypeInfo(disp, 1, LOCALE_USER_DEFAULT, &typeinfo);
1901 ok(hr == DISP_E_BADINDEX, "GetTypeInfo returned: %08x\n", hr);
1902 hr = IDispatchEx_GetTypeInfo(disp, 0, LOCALE_USER_DEFAULT, &typeinfo);
1903 ok(hr == S_OK, "GetTypeInfo failed: %08x\n", hr);
1904 hr = IDispatchEx_GetTypeInfo(disp, 0, LOCALE_USER_DEFAULT, &typeinfo2);
1905 ok(hr == S_OK, "GetTypeInfo failed: %08x\n", hr);
1906 ok(typeinfo != typeinfo2, "TypeInfo was not supposed to be shared.\n");
1907 ITypeInfo_Release(typeinfo2);
1909 obj = (void*)0xdeadbeef;
1910 hr = ITypeInfo_CreateInstance(typeinfo, NULL, NULL, NULL);
1911 ok(hr == E_INVALIDARG, "CreateInstance returned: %08x\n", hr);
1912 hr = ITypeInfo_CreateInstance(typeinfo, NULL, NULL, &obj);
1913 ok(hr == TYPE_E_BADMODULEKIND, "CreateInstance returned: %08x\n", hr);
1914 hr = ITypeInfo_CreateInstance(typeinfo, NULL, &IID_IDispatch, &obj);
1915 ok(hr == TYPE_E_BADMODULEKIND, "CreateInstance returned: %08x\n", hr);
1916 ok(!obj, "Unexpected non-null obj %p.\n", obj);
1918 hr = ITypeInfo_GetDocumentation(typeinfo, MEMBERID_NIL, &bstr, NULL, NULL, NULL);
1919 ok(hr == S_OK, "GetDocumentation(MEMBERID_NIL) failed: %08x\n", hr);
1920 ok(!lstrcmpW(bstr, L"JScriptTypeInfo"), "Unexpected TypeInfo name %s\n", wine_dbgstr_w(bstr));
1921 SysFreeString(bstr);
1923 hr = ITypeInfo_GetTypeAttr(typeinfo, &attr);
1924 ok(hr == S_OK, "GetTypeAttr failed: %08x\n", hr);
1925 ok(IsEqualGUID(&attr->guid, &IID_IScriptTypeInfo), "Unexpected GUID %s\n", wine_dbgstr_guid(&attr->guid));
1926 ok(attr->lcid == LOCALE_USER_DEFAULT, "Unexpected LCID %u\n", attr->lcid);
1927 ok(attr->memidConstructor == MEMBERID_NIL, "Unexpected constructor memid %u\n", attr->memidConstructor);
1928 ok(attr->memidDestructor == MEMBERID_NIL, "Unexpected destructor memid %u\n", attr->memidDestructor);
1929 ok(attr->cbSizeInstance == 4, "Unexpected cbSizeInstance %u\n", attr->cbSizeInstance);
1930 ok(attr->typekind == TKIND_DISPATCH, "Unexpected typekind %u\n", attr->typekind);
1931 ok(attr->cFuncs == expected_funcs_cnt, "Unexpected cFuncs %u\n", attr->cFuncs);
1932 ok(attr->cVars == expected_vars_cnt, "Unexpected cVars %u\n", attr->cVars);
1933 ok(attr->cImplTypes == 1, "Unexpected cImplTypes %u\n", attr->cImplTypes);
1934 ok(attr->cbSizeVft == sizeof(IDispatchVtbl), "Unexpected cbSizeVft %u\n", attr->cbSizeVft);
1935 ok(attr->cbAlignment == 4, "Unexpected cbAlignment %u\n", attr->cbAlignment);
1936 ok(attr->wTypeFlags == TYPEFLAG_FDISPATCHABLE, "Unexpected wTypeFlags 0x%x\n", attr->wTypeFlags);
1937 ok(attr->tdescAlias.vt == VT_EMPTY, "Unexpected tdescAlias.vt %d\n", attr->tdescAlias.vt);
1938 ok(attr->idldescType.wIDLFlags == IDLFLAG_NONE, "Unexpected idldescType.wIDLFlags 0x%x\n", attr->idldescType.wIDLFlags);
1939 ITypeInfo_ReleaseTypeAttr(typeinfo, attr);
1941 /* The type inherits from IDispatch */
1942 hr = ITypeInfo_GetImplTypeFlags(typeinfo, 0, NULL);
1943 ok(hr == E_INVALIDARG, "GetImplTypeFlags returned: %08x\n", hr);
1944 hr = ITypeInfo_GetImplTypeFlags(typeinfo, 1, &implTypeFlags);
1945 ok(hr == TYPE_E_ELEMENTNOTFOUND, "GetImplTypeFlags returned: %08x\n", hr);
1946 hr = ITypeInfo_GetImplTypeFlags(typeinfo, -1, &implTypeFlags);
1947 ok(hr == TYPE_E_ELEMENTNOTFOUND, "GetImplTypeFlags returned: %08x\n", hr);
1948 hr = ITypeInfo_GetImplTypeFlags(typeinfo, 0, &implTypeFlags);
1949 ok(hr == S_OK, "GetImplTypeFlags failed: %08x\n", hr);
1950 ok(implTypeFlags == 0, "Unexpected implTypeFlags 0x%x\n", implTypeFlags);
1952 hr = ITypeInfo_GetRefTypeOfImplType(typeinfo, 0, NULL);
1953 ok(hr == E_INVALIDARG, "GetRefTypeOfImplType returned: %08x\n", hr);
1954 hr = ITypeInfo_GetRefTypeOfImplType(typeinfo, 1, &reftype);
1955 ok(hr == TYPE_E_ELEMENTNOTFOUND, "GetRefTypeOfImplType returned: %08x\n", hr);
1956 hr = ITypeInfo_GetRefTypeOfImplType(typeinfo, -1, &reftype);
1957 ok(hr == TYPE_E_ELEMENTNOTFOUND, "GetRefTypeOfImplType failed: %08x\n", hr);
1958 hr = ITypeInfo_GetRefTypeOfImplType(typeinfo, 0, &reftype);
1959 ok(hr == S_OK, "GetRefTypeOfImplType failed: %08x\n", hr);
1960 ok(reftype == 1, "Unexpected reftype %d\n", reftype);
1962 hr = ITypeInfo_GetRefTypeInfo(typeinfo, reftype, NULL);
1963 ok(hr == E_INVALIDARG, "GetRefTypeInfo returned: %08x\n", hr);
1964 hr = ITypeInfo_GetRefTypeInfo(typeinfo, -1, &typeinfo2);
1965 ok(hr == E_INVALIDARG, "GetRefTypeInfo returned: %08x\n", hr);
1966 hr = ITypeInfo_GetRefTypeInfo(typeinfo, 4, &typeinfo2);
1967 ok(hr == E_FAIL, "GetRefTypeInfo returned: %08x\n", hr);
1968 hr = ITypeInfo_GetRefTypeInfo(typeinfo, 0, &typeinfo2);
1969 ok(hr == S_OK, "GetRefTypeInfo failed: %08x\n", hr);
1970 ok(typeinfo == typeinfo2, "Unexpected TypeInfo %p (expected %p)\n", typeinfo2, typeinfo);
1971 ITypeInfo_Release(typeinfo2);
1972 hr = ITypeInfo_GetRefTypeInfo(typeinfo, reftype, &typeinfo2);
1973 ok(hr == S_OK, "GetRefTypeInfo failed: %08x\n", hr);
1974 hr = ITypeInfo_GetDocumentation(typeinfo2, MEMBERID_NIL, &bstr, NULL, NULL, NULL);
1975 ok(hr == S_OK, "GetDocumentation(MEMBERID_NIL) failed: %08x\n", hr);
1976 ok(!lstrcmpW(bstr, L"IDispatch"), "Unexpected TypeInfo name %s\n", wine_dbgstr_w(bstr));
1977 ITypeInfo_Release(typeinfo2);
1978 SysFreeString(bstr);
1980 /* GetIDsOfNames looks into the inherited types as well */
1981 wcscpy(str, L"queryinterface");
1982 hr = ITypeInfo_GetIDsOfNames(typeinfo, NULL, 1, &memid);
1983 ok(hr == E_INVALIDARG, "GetIDsOfNames returned: %08x\n", hr);
1984 hr = ITypeInfo_GetIDsOfNames(typeinfo, &names, 1, NULL);
1985 ok(hr == E_INVALIDARG, "GetIDsOfNames returned: %08x\n", hr);
1986 hr = ITypeInfo_GetIDsOfNames(typeinfo, &names, 0, &memid);
1987 ok(hr == E_INVALIDARG, "GetIDsOfNames returned: %08x\n", hr);
1988 hr = ITypeInfo_GetIDsOfNames(typeinfo, &names, 1, &memid);
1989 ok(hr == S_OK, "GetIDsOfNames failed: %08x\n", hr);
1990 ok(!lstrcmpW(str, L"queryinterface"), "Unexpected string %s\n", wine_dbgstr_w(str));
1991 if (expected_funcs_cnt)
1993 wcscpy(str, L"Math");
1994 hr = ITypeInfo_GetIDsOfNames(typeinfo, &names, 1, &memid);
1995 ok(hr == S_OK, "GetIDsOfNames failed: %08x\n", hr);
1996 ok(!lstrcmpW(str, L"Math"), "Unexpected string %s\n", wine_dbgstr_w(str));
1997 hr = ITypeInfo_GetNames(typeinfo, memid, NULL, 1, &count);
1998 ok(hr == E_INVALIDARG, "GetNames returned: %08x\n", hr);
1999 hr = ITypeInfo_GetNames(typeinfo, memid, bstrs, 1, NULL);
2000 ok(hr == E_INVALIDARG, "GetNames returned: %08x\n", hr);
2001 hr = ITypeInfo_GetNames(typeinfo, memid, bstrs, 0, &count);
2002 ok(hr == S_OK, "GetNames failed: %08x\n", hr);
2003 ok(count == 0, "Unexpected count %u\n", count);
2004 hr = ITypeInfo_GetNames(typeinfo, memid, bstrs, ARRAY_SIZE(bstrs), &count);
2005 ok(hr == S_OK, "GetNames failed: %08x\n", hr);
2006 ok(count == 3, "Unexpected count %u\n", count);
2007 ok(!lstrcmpW(bstrs[0], L"math"), "Unexpected function name %s\n", wine_dbgstr_w(bstrs[0]));
2008 ok(!lstrcmpW(bstrs[1], L"x"), "Unexpected function first param name %s\n", wine_dbgstr_w(bstrs[1]));
2009 ok(!lstrcmpW(bstrs[2], L"y"), "Unexpected function second param name %s\n", wine_dbgstr_w(bstrs[2]));
2010 for (i = 0; i < count; i++) SysFreeString(bstrs[i]);
2012 hr = ITypeInfo_GetMops(typeinfo, memid, NULL);
2013 ok(hr == E_INVALIDARG, "GetMops returned: %08x\n", hr);
2014 hr = ITypeInfo_GetMops(typeinfo, memid, &bstr);
2015 ok(hr == S_OK, "GetMops failed: %08x\n", hr);
2016 ok(!bstr, "Unexpected non-null string %s\n", wine_dbgstr_w(bstr));
2017 hr = ITypeInfo_GetMops(typeinfo, MEMBERID_NIL, &bstr);
2018 ok(hr == S_OK, "GetMops failed: %08x\n", hr);
2019 ok(!bstr, "Unexpected non-null string %s\n", wine_dbgstr_w(bstr));
2021 /* These always fail */
2022 obj = (void*)0xdeadbeef;
2023 hr = ITypeInfo_AddressOfMember(typeinfo, memid, INVOKE_FUNC, NULL);
2024 ok(hr == E_INVALIDARG, "AddressOfMember returned: %08x\n", hr);
2025 hr = ITypeInfo_AddressOfMember(typeinfo, memid, INVOKE_FUNC, &obj);
2026 ok(hr == TYPE_E_BADMODULEKIND, "AddressOfMember returned: %08x\n", hr);
2027 ok(!obj, "Unexpected non-null obj %p.\n", obj);
2028 bstr = (BSTR)0xdeadbeef;
2029 hr = ITypeInfo_GetDllEntry(typeinfo, memid, INVOKE_FUNC, &bstr, NULL, NULL);
2030 ok(hr == TYPE_E_BADMODULEKIND, "GetDllEntry returned: %08x\n", hr);
2031 ok(!bstr, "Unexpected non-null str %p.\n", bstr);
2032 wcscpy(str, L"Invoke");
2033 hr = ITypeInfo_GetIDsOfNames(typeinfo, &names, 1, &memid);
2034 ok(hr == S_OK, "GetIDsOfNames failed: %08x\n", hr);
2035 obj = (void*)0xdeadbeef;
2036 hr = ITypeInfo_AddressOfMember(typeinfo, memid, INVOKE_FUNC, &obj);
2037 ok(hr == TYPE_E_BADMODULEKIND, "AddressOfMember returned: %08x\n", hr);
2038 ok(!obj, "Unexpected non-null obj %p.\n", obj);
2039 bstr = (BSTR)0xdeadbeef;
2040 hr = ITypeInfo_GetDllEntry(typeinfo, memid, INVOKE_FUNC, &bstr, NULL, NULL);
2041 ok(hr == TYPE_E_BADMODULEKIND, "GetDllEntry returned: %08x\n", hr);
2042 ok(!bstr, "Unexpected non-null str %p.\n", bstr);
2045 /* Check variable descriptions */
2046 hr = ITypeInfo_GetVarDesc(typeinfo, 0, NULL);
2047 ok(hr == E_INVALIDARG, "GetVarDesc returned: %08x\n", hr);
2048 hr = ITypeInfo_GetVarDesc(typeinfo, 1337, &vardesc);
2049 ok(hr == TYPE_E_ELEMENTNOTFOUND, "GetVarDesc returned: %08x\n", hr);
2050 for (i = 0; i < expected_vars_cnt; i++)
2052 hr = ITypeInfo_GetVarDesc(typeinfo, i, &vardesc);
2053 ok(hr == S_OK, "GetVarDesc(%u) failed: %08x\n", i, hr);
2054 hr = ITypeInfo_GetDocumentation(typeinfo, vardesc->memid, &bstr, &bstrs[0], NULL, NULL);
2055 ok(hr == S_OK, "[%u] GetDocumentation failed: %08x\n", i, hr);
2056 ok(!lstrcmpW(bstr, var[i].name), "[%u] Unexpected variable name %s (expected %s)\n",
2057 i, wine_dbgstr_w(bstr), wine_dbgstr_w(var[i].name));
2058 ok(!bstrs[0], "[%u] Unexpected doc string %s\n", i, wine_dbgstr_w(bstrs[0]));
2059 SysFreeString(bstr);
2060 ok(vardesc->memid <= 0xFFFF, "[%u] Unexpected memid 0x%x\n", i, vardesc->memid);
2061 ok(vardesc->lpstrSchema == NULL, "[%u] Unexpected lpstrSchema %p\n", i, vardesc->lpstrSchema);
2062 ok(vardesc->oInst == 0, "[%u] Unexpected oInst %u\n", i, vardesc->oInst);
2063 ok(vardesc->varkind == VAR_DISPATCH, "[%u] Unexpected varkind %d\n", i, vardesc->varkind);
2064 ok(vardesc->wVarFlags == 0, "[%u] Unexpected wVarFlags 0x%x\n", i, vardesc->wVarFlags);
2065 ok(vardesc->elemdescVar.tdesc.vt == VT_VARIANT,
2066 "[%u] Unexpected variable type vt %d (expected %d)\n", i, vardesc->elemdescVar.tdesc.vt, 0);
2067 ok(vardesc->elemdescVar.paramdesc.pparamdescex == NULL,
2068 "[%u] Unexpected variable type pparamdescex %p\n", i, vardesc->elemdescVar.paramdesc.pparamdescex);
2069 ok(vardesc->elemdescVar.paramdesc.wParamFlags == PARAMFLAG_NONE,
2070 "[%u] Unexpected variable type wParamFlags 0x%x\n", i, vardesc->elemdescVar.paramdesc.wParamFlags);
2071 ITypeInfo_ReleaseVarDesc(typeinfo, vardesc);
2074 /* Check function descriptions */
2075 hr = ITypeInfo_GetFuncDesc(typeinfo, 0, NULL);
2076 ok(hr == E_INVALIDARG, "GetFuncDesc returned: %08x\n", hr);
2077 hr = ITypeInfo_GetFuncDesc(typeinfo, 1337, &funcdesc);
2078 ok(hr == TYPE_E_ELEMENTNOTFOUND, "GetFuncDesc returned: %08x\n", hr);
2079 for (i = 0; i < expected_funcs_cnt; i++)
2081 hr = ITypeInfo_GetFuncDesc(typeinfo, i, &funcdesc);
2082 ok(hr == S_OK, "GetFuncDesc(%u) failed: %08x\n", i, hr);
2083 hr = ITypeInfo_GetDocumentation(typeinfo, funcdesc->memid, &bstr, &bstrs[0], NULL, NULL);
2084 ok(hr == S_OK, "[%u] GetDocumentation failed: %08x\n", i, hr);
2085 ok(!lstrcmpW(bstr, func[i].name), "[%u] Unexpected function name %s (expected %s)\n",
2086 i, wine_dbgstr_w(bstr), wine_dbgstr_w(func[i].name));
2087 ok(!bstrs[0], "[%u] Unexpected doc string %s\n", i, wine_dbgstr_w(bstrs[0]));
2088 SysFreeString(bstr);
2089 ok(funcdesc->memid <= 0xFFFF, "[%u] Unexpected memid 0x%x\n", i, funcdesc->memid);
2090 ok(funcdesc->lprgscode == NULL, "[%u] Unexpected lprgscode %p\n", i, funcdesc->lprgscode);
2091 ok(func[i].num_args ? (funcdesc->lprgelemdescParam != NULL) : (funcdesc->lprgelemdescParam == NULL),
2092 "[%u] Unexpected lprgelemdescParam %p\n", i, funcdesc->lprgelemdescParam);
2093 ok(funcdesc->funckind == FUNC_DISPATCH, "[%u] Unexpected funckind %u\n", i, funcdesc->funckind);
2094 ok(funcdesc->invkind == INVOKE_FUNC, "[%u] Unexpected invkind %u\n", i, funcdesc->invkind);
2095 ok(funcdesc->callconv == CC_STDCALL, "[%u] Unexpected callconv %u\n", i, funcdesc->callconv);
2096 ok(funcdesc->cParams == func[i].num_args, "[%u] Unexpected cParams %d (expected %d)\n",
2097 i, funcdesc->cParams, func[i].num_args);
2098 ok(funcdesc->cParamsOpt == 0, "[%u] Unexpected cParamsOpt %d\n", i, funcdesc->cParamsOpt);
2099 ok(funcdesc->cScodes == 0, "[%u] Unexpected cScodes %d\n", i, funcdesc->cScodes);
2100 ok(funcdesc->wFuncFlags == 0, "[%u] Unexpected wFuncFlags 0x%x\n", i, funcdesc->wFuncFlags);
2101 ok(funcdesc->elemdescFunc.tdesc.vt == VT_VARIANT,
2102 "[%u] Unexpected return type vt %d\n", i, funcdesc->elemdescFunc.tdesc.vt);
2103 ok(funcdesc->elemdescFunc.paramdesc.pparamdescex == NULL,
2104 "[%u] Unexpected return type pparamdescex %p\n", i, funcdesc->elemdescFunc.paramdesc.pparamdescex);
2105 ok(funcdesc->elemdescFunc.paramdesc.wParamFlags == PARAMFLAG_NONE,
2106 "[%u] Unexpected return type wParamFlags 0x%x\n", i, funcdesc->elemdescFunc.paramdesc.wParamFlags);
2107 if (funcdesc->lprgelemdescParam)
2108 for (index = 0; index < funcdesc->cParams; index++)
2110 ok(funcdesc->lprgelemdescParam[index].tdesc.vt == VT_VARIANT,
2111 "[%u] Unexpected parameter %u vt %d\n", i, index, funcdesc->lprgelemdescParam[index].tdesc.vt);
2112 ok(funcdesc->lprgelemdescParam[index].paramdesc.pparamdescex == NULL,
2113 "[%u] Unexpected parameter %u pparamdescex %p\n", i, index, funcdesc->lprgelemdescParam[index].paramdesc.pparamdescex);
2114 ok(funcdesc->lprgelemdescParam[index].paramdesc.wParamFlags == PARAMFLAG_NONE,
2115 "[%u] Unexpected parameter %u wParamFlags 0x%x\n", i, index, funcdesc->lprgelemdescParam[index].paramdesc.wParamFlags);
2117 ITypeInfo_ReleaseFuncDesc(typeinfo, funcdesc);
2120 /* Test TypeComp Binds */
2121 hr = ITypeInfo_QueryInterface(typeinfo, &IID_ITypeComp, (void**)&typecomp);
2122 ok(hr == S_OK, "QueryInterface(IID_ITypeComp) failed: %08x\n", hr);
2123 hr = ITypeInfo_GetTypeComp(typeinfo, NULL);
2124 ok(hr == E_INVALIDARG, "GetTypeComp returned: %08x\n", hr);
2125 hr = ITypeInfo_GetTypeComp(typeinfo, &typecomp2);
2126 ok(hr == S_OK, "GetTypeComp failed: %08x\n", hr);
2127 ok(typecomp == typecomp2, "QueryInterface(IID_ITypeComp) and GetTypeComp returned different TypeComps\n");
2128 ITypeComp_Release(typecomp2);
2129 wcscpy(str, L"not_found");
2130 hr = ITypeComp_Bind(typecomp, NULL, 0, 0, &typeinfo2, &desckind, &bindptr);
2131 ok(hr == E_INVALIDARG, "Bind returned: %08x\n", hr);
2132 hr = ITypeComp_Bind(typecomp, str, 0, 0, NULL, &desckind, &bindptr);
2133 ok(hr == E_INVALIDARG, "Bind returned: %08x\n", hr);
2134 hr = ITypeComp_Bind(typecomp, str, 0, 0, &typeinfo2, NULL, &bindptr);
2135 ok(hr == E_INVALIDARG, "Bind returned: %08x\n", hr);
2136 hr = ITypeComp_Bind(typecomp, str, 0, 0, &typeinfo2, &desckind, NULL);
2137 ok(hr == E_INVALIDARG, "Bind returned: %08x\n", hr);
2138 hr = ITypeComp_Bind(typecomp, str, 0, 0, &typeinfo2, &desckind, &bindptr);
2139 ok(hr == S_OK, "Bind failed: %08x\n", hr);
2140 ok(desckind == DESCKIND_NONE, "Unexpected desckind %u\n", desckind);
2141 wcscpy(str, L"addRef");
2142 hr = ITypeComp_Bind(typecomp, str, 0, 0, &typeinfo2, &desckind, &bindptr);
2143 ok(hr == S_OK, "Bind failed: %08x\n", hr);
2144 ok(desckind == DESCKIND_FUNCDESC, "Unexpected desckind %u\n", desckind);
2145 ok(!lstrcmpW(str, L"addRef"), "Unexpected string %s\n", wine_dbgstr_w(str));
2146 ITypeInfo_ReleaseFuncDesc(typeinfo2, bindptr.lpfuncdesc);
2147 ITypeInfo_Release(typeinfo2);
2148 for (i = 0; i < expected_vars_cnt; i++)
2150 wcscpy(str, var[i].name);
2151 hr = ITypeComp_Bind(typecomp, str, 0, INVOKE_PROPERTYGET, &typeinfo2, &desckind, &bindptr);
2152 ok(hr == S_OK, "Bind failed: %08x\n", hr);
2153 ok(desckind == DESCKIND_VARDESC, "Unexpected desckind %u\n", desckind);
2154 ITypeInfo_ReleaseVarDesc(typeinfo2, bindptr.lpvardesc);
2155 ITypeInfo_Release(typeinfo2);
2157 for (i = 0; i < expected_funcs_cnt; i++)
2159 wcscpy(str, func[i].name);
2160 hr = ITypeComp_Bind(typecomp, str, 0, INVOKE_FUNC, &typeinfo2, &desckind, &bindptr);
2161 ok(hr == S_OK, "Bind failed: %08x\n", hr);
2162 ok(desckind == DESCKIND_FUNCDESC, "Unexpected desckind %u\n", desckind);
2163 ITypeInfo_ReleaseFuncDesc(typeinfo2, bindptr.lpfuncdesc);
2164 ITypeInfo_Release(typeinfo2);
2166 wcscpy(str, L"JScriptTypeInfo");
2167 hr = ITypeComp_BindType(typecomp, NULL, 0, &typeinfo2, &typecomp2);
2168 ok(hr == E_INVALIDARG, "BindType returned: %08x\n", hr);
2169 hr = ITypeComp_BindType(typecomp, str, 0, NULL, &typecomp2);
2170 ok(hr == E_INVALIDARG, "BindType returned: %08x\n", hr);
2171 hr = ITypeComp_BindType(typecomp, str, 0, &typeinfo2, NULL);
2172 ok(hr == E_INVALIDARG, "BindType returned: %08x\n", hr);
2173 hr = ITypeComp_BindType(typecomp, str, 0, &typeinfo2, &typecomp2);
2174 ok(hr == S_OK, "BindType failed: %08x\n", hr);
2175 ok(!typeinfo2, "Unexpected TypeInfo %p (expected null)\n", typeinfo2);
2176 ok(!typecomp2, "Unexpected TypeComp %p (expected null)\n", typecomp2);
2177 wcscpy(str, L"C");
2178 hr = ITypeComp_BindType(typecomp, str, 0, &typeinfo2, &typecomp2);
2179 ok(hr == S_OK, "BindType failed: %08x\n", hr);
2180 ok(!typeinfo2, "Unexpected TypeInfo %p (expected null)\n", typeinfo2);
2181 ok(!typecomp2, "Unexpected TypeComp %p (expected null)\n", typecomp2);
2182 wcscpy(str, L"IDispatch");
2183 hr = ITypeComp_BindType(typecomp, str, 0, &typeinfo2, &typecomp2);
2184 ok(hr == S_OK, "BindType failed: %08x\n", hr);
2185 ok(!typeinfo2, "Unexpected TypeInfo %p (expected null)\n", typeinfo2);
2186 ok(!typecomp2, "Unexpected TypeComp %p (expected null)\n", typecomp2);
2187 ITypeComp_Release(typecomp);
2189 /* Updating the script won't update the typeinfo obtained before,
2190 but it will be reflected in any typeinfo obtained afterwards. */
2191 if (!parse_func_name)
2193 parse_script(parser, L""
2194 "var new_var;\n"
2195 "function new_func() { }\n");
2197 hr = IDispatchEx_GetTypeInfo(disp, 0, LOCALE_USER_DEFAULT, &typeinfo2);
2198 ok(hr == S_OK, "GetTypeInfo failed: %08x\n", hr);
2199 hr = ITypeInfo_GetTypeAttr(typeinfo, &attr);
2200 ok(hr == S_OK, "GetTypeAttr failed: %08x\n", hr);
2201 ok(attr->cFuncs == expected_funcs_cnt, "Unexpected cFuncs %u\n", attr->cFuncs);
2202 ok(attr->cVars == expected_vars_cnt, "Unexpected cVars %u\n", attr->cVars);
2203 ITypeInfo_ReleaseTypeAttr(typeinfo, attr);
2204 hr = ITypeInfo_GetTypeAttr(typeinfo2, &attr);
2205 ok(hr == S_OK, "GetTypeAttr failed: %08x\n", hr);
2206 ok(attr->cFuncs == expected_funcs_cnt + 1, "Unexpected cFuncs %u\n", attr->cFuncs);
2207 ok(attr->cVars == expected_vars_cnt + 1, "Unexpected cVars %u\n", attr->cVars);
2208 ITypeInfo_ReleaseTypeAttr(typeinfo2, attr);
2209 ITypeInfo_Release(typeinfo2);
2211 /* Adding an identifier that differs only in case gives an error
2212 when retrieving the TypeInfo, even though it is valid jscript. */
2213 parse_script(parser, L"var NEW_FUNC;\n");
2214 hr = IDispatchEx_GetTypeInfo(disp, 0, LOCALE_USER_DEFAULT, &typeinfo2);
2215 ok(hr == TYPE_E_AMBIGUOUSNAME, "GetTypeInfo returned: %08x\n", hr);
2218 ITypeInfo_Release(typeinfo);
2219 IDispatchEx_Release(disp);
2220 IActiveScriptParse_Release(parser);
2222 SET_EXPECT(OnStateChange_DISCONNECTED);
2223 SET_EXPECT(OnStateChange_INITIALIZED);
2224 SET_EXPECT(OnStateChange_CLOSED);
2225 hr = IActiveScript_Close(script);
2226 ok(hr == S_OK, "Close failed: %08x\n", hr);
2227 CHECK_CALLED(OnStateChange_DISCONNECTED);
2228 CHECK_CALLED(OnStateChange_INITIALIZED);
2229 CHECK_CALLED(OnStateChange_CLOSED);
2231 IActiveScript_Release(script);
2234 static BOOL check_jscript(void)
2236 IActiveScriptProperty *script_prop;
2237 HRESULT hres;
2239 hres = CoCreateInstance(&CLSID_JScript, NULL, CLSCTX_INPROC_SERVER|CLSCTX_INPROC_HANDLER,
2240 &IID_IActiveScriptProperty, (void**)&script_prop);
2241 if(SUCCEEDED(hres))
2242 IActiveScriptProperty_Release(script_prop);
2244 return hres == S_OK;
2247 START_TEST(jscript)
2249 CoInitialize(NULL);
2251 if(check_jscript()) {
2252 trace("Testing JScript object...\n");
2253 test_jscript();
2254 test_jscript2();
2255 test_jscript_uninitializing();
2256 test_aggregation();
2257 test_code_persistence();
2258 test_named_items();
2259 test_typeinfo(NULL);
2260 test_typeinfo(L"some_func_name");
2262 trace("Testing JScriptEncode object...\n");
2263 engine_clsid = &CLSID_JScriptEncode;
2264 test_jscript();
2265 }else {
2266 win_skip("Broken engine, probably too old\n");
2269 CoUninitialize();