[JSCRIPT_WINETEST] Sync with Wine Staging 1.7.47. CORE-9924
[reactos.git] / rostests / winetests / jscript / run.c
1 /*
2 * Copyright 2008 Jacek Caban for CodeWeavers
3 *
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.
8 *
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.
13 *
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
17 */
18
19 #define WIN32_NO_STATUS
20 #define _INC_WINDOWS
21 #define COM_NO_WINDOWS_H
22
23 #include <stdio.h>
24
25 #define COBJMACROS
26 #define CONST_VTABLE
27
28 #include <windef.h>
29 #include <winbase.h>
30 #include <winnls.h>
31 #include <ole2.h>
32 #include <dispex.h>
33 #include <activscp.h>
34
35 #include <wine/test.h>
36
37 #ifdef _WIN64
38
39 #define IActiveScriptParse_QueryInterface IActiveScriptParse64_QueryInterface
40 #define IActiveScriptParse_Release IActiveScriptParse64_Release
41 #define IActiveScriptParse_InitNew IActiveScriptParse64_InitNew
42 #define IActiveScriptParse_ParseScriptText IActiveScriptParse64_ParseScriptText
43 #define IActiveScriptParseProcedure2_Release IActiveScriptParseProcedure2_64_Release
44 #define IActiveScriptParseProcedure2_ParseProcedureText IActiveScriptParseProcedure2_64_ParseProcedureText
45
46 #else
47
48 #define IActiveScriptParse_QueryInterface IActiveScriptParse32_QueryInterface
49 #define IActiveScriptParse_Release IActiveScriptParse32_Release
50 #define IActiveScriptParse_InitNew IActiveScriptParse32_InitNew
51 #define IActiveScriptParse_ParseScriptText IActiveScriptParse32_ParseScriptText
52 #define IActiveScriptParseProcedure2_Release IActiveScriptParseProcedure2_32_Release
53 #define IActiveScriptParseProcedure2_ParseProcedureText IActiveScriptParseProcedure2_32_ParseProcedureText
54
55 #endif
56
57 static const CLSID CLSID_JScript =
58 {0xf414c260,0x6ac0,0x11cf,{0xb6,0xd1,0x00,0xaa,0x00,0xbb,0xbb,0x58}};
59 static const CLSID CLSID_JScriptEncode =
60 {0xf414c262,0x6ac0,0x11cf,{0xb6,0xd1,0x00,0xaa,0x00,0xbb,0xbb,0x58}};
61
62 #define DEFINE_EXPECT(func) \
63 static BOOL expect_ ## func = FALSE, called_ ## func = FALSE
64
65 #define SET_EXPECT(func) \
66 expect_ ## func = TRUE
67
68 #define CHECK_EXPECT2(func) \
69 do { \
70 ok(expect_ ##func, "unexpected call " #func "\n"); \
71 called_ ## func = TRUE; \
72 }while(0)
73
74 #define CHECK_EXPECT(func) \
75 do { \
76 CHECK_EXPECT2(func); \
77 expect_ ## func = FALSE; \
78 }while(0)
79
80 #define CHECK_CALLED(func) \
81 do { \
82 ok(called_ ## func, "expected " #func "\n"); \
83 expect_ ## func = called_ ## func = FALSE; \
84 }while(0)
85
86 DEFINE_EXPECT(global_propget_d);
87 DEFINE_EXPECT(global_propget_i);
88 DEFINE_EXPECT(global_propput_d);
89 DEFINE_EXPECT(global_propput_i);
90 DEFINE_EXPECT(global_propputref_d);
91 DEFINE_EXPECT(global_propputref_i);
92 DEFINE_EXPECT(global_propdelete_d);
93 DEFINE_EXPECT(global_nopropdelete_d);
94 DEFINE_EXPECT(global_success_d);
95 DEFINE_EXPECT(global_success_i);
96 DEFINE_EXPECT(global_notexists_d);
97 DEFINE_EXPECT(global_propargput_d);
98 DEFINE_EXPECT(global_propargput_i);
99 DEFINE_EXPECT(global_testargtypes_i);
100 DEFINE_EXPECT(puredisp_prop_d);
101 DEFINE_EXPECT(puredisp_noprop_d);
102 DEFINE_EXPECT(puredisp_value);
103 DEFINE_EXPECT(dispexfunc_value);
104 DEFINE_EXPECT(testobj_delete_test);
105 DEFINE_EXPECT(testobj_delete_nodelete);
106 DEFINE_EXPECT(testobj_value);
107 DEFINE_EXPECT(testobj_construct);
108 DEFINE_EXPECT(testobj_prop_d);
109 DEFINE_EXPECT(testobj_withprop_d);
110 DEFINE_EXPECT(testobj_withprop_i);
111 DEFINE_EXPECT(testobj_noprop_d);
112 DEFINE_EXPECT(testobj_onlydispid_d);
113 DEFINE_EXPECT(testobj_onlydispid_i);
114 DEFINE_EXPECT(testobj_notexists_d);
115 DEFINE_EXPECT(GetItemInfo_testVal);
116 DEFINE_EXPECT(ActiveScriptSite_OnScriptError);
117 DEFINE_EXPECT(invoke_func);
118 DEFINE_EXPECT(DeleteMemberByDispID);
119 DEFINE_EXPECT(DeleteMemberByDispID_false);
120 DEFINE_EXPECT(BindHandler);
121
122 #define DISPID_GLOBAL_TESTPROPGET 0x1000
123 #define DISPID_GLOBAL_TESTPROPPUT 0x1001
124 #define DISPID_GLOBAL_REPORTSUCCESS 0x1002
125 #define DISPID_GLOBAL_TRACE 0x1003
126 #define DISPID_GLOBAL_OK 0x1004
127 #define DISPID_GLOBAL_GETVT 0x1005
128 #define DISPID_GLOBAL_TESTOBJ 0x1006
129 #define DISPID_GLOBAL_GETNULLBSTR 0x1007
130 #define DISPID_GLOBAL_NULL_DISP 0x1008
131 #define DISPID_GLOBAL_TESTTHIS 0x1009
132 #define DISPID_GLOBAL_TESTTHIS2 0x100a
133 #define DISPID_GLOBAL_INVOKEVERSION 0x100b
134 #define DISPID_GLOBAL_CREATEARRAY 0x100c
135 #define DISPID_GLOBAL_PROPGETFUNC 0x100d
136 #define DISPID_GLOBAL_OBJECT_FLAG 0x100e
137 #define DISPID_GLOBAL_ISWIN64 0x100f
138 #define DISPID_GLOBAL_PUREDISP 0x1010
139 #define DISPID_GLOBAL_ISNULLBSTR 0x1011
140 #define DISPID_GLOBAL_PROPARGPUT 0x1012
141 #define DISPID_GLOBAL_SHORTPROP 0x1013
142 #define DISPID_GLOBAL_GETSHORT 0x1014
143 #define DISPID_GLOBAL_TESTARGTYPES 0x1015
144 #define DISPID_GLOBAL_INTPROP 0x1016
145 #define DISPID_GLOBAL_DISPUNK 0x1017
146 #define DISPID_GLOBAL_TESTRES 0x1018
147 #define DISPID_GLOBAL_TESTNORES 0x1019
148 #define DISPID_GLOBAL_DISPEXFUNC 0x101a
149 #define DISPID_GLOBAL_TESTPROPPUTREF 0x101b
150 #define DISPID_GLOBAL_GETSCRIPTSTATE 0x101c
151 #define DISPID_GLOBAL_BINDEVENTHANDLER 0x101d
152
153 #define DISPID_GLOBAL_TESTPROPDELETE 0x2000
154 #define DISPID_GLOBAL_TESTNOPROPDELETE 0x2001
155
156 #define DISPID_TESTOBJ_PROP 0x2000
157 #define DISPID_TESTOBJ_ONLYDISPID 0x2001
158 #define DISPID_TESTOBJ_WITHPROP 0x2002
159
160 #define JS_E_OUT_OF_MEMORY 0x800a03ec
161 #define JS_E_INVALID_CHAR 0x800a03f6
162
163 static const WCHAR testW[] = {'t','e','s','t',0};
164 static const CHAR testA[] = "test";
165 static const WCHAR test_valW[] = {'t','e','s','t','V','a','l',0};
166 static const CHAR test_valA[] = "testVal";
167 static const WCHAR emptyW[] = {0};
168
169 static BOOL strict_dispid_check, testing_expr;
170 static const char *test_name = "(null)";
171 static IDispatch *script_disp;
172 static int invoke_version;
173 static IActiveScriptError *script_error;
174 static IActiveScript *script_engine;
175 static const CLSID *engine_clsid = &CLSID_JScript;
176
177 /* Returns true if the user interface is in English. Note that this does not
178 * presume of the formatting of dates, numbers, etc.
179 */
180 static BOOL is_lang_english(void)
181 {
182 static HMODULE hkernel32 = NULL;
183 static LANGID (WINAPI *pGetThreadUILanguage)(void) = NULL;
184 static LANGID (WINAPI *pGetUserDefaultUILanguage)(void) = NULL;
185
186 if (!hkernel32)
187 {
188 hkernel32 = GetModuleHandleA("kernel32.dll");
189 pGetThreadUILanguage = (void*)GetProcAddress(hkernel32, "GetThreadUILanguage");
190 pGetUserDefaultUILanguage = (void*)GetProcAddress(hkernel32, "GetUserDefaultUILanguage");
191 }
192 if (pGetThreadUILanguage)
193 return PRIMARYLANGID(pGetThreadUILanguage()) == LANG_ENGLISH;
194 if (pGetUserDefaultUILanguage)
195 return PRIMARYLANGID(pGetUserDefaultUILanguage()) == LANG_ENGLISH;
196
197 return PRIMARYLANGID(GetUserDefaultLangID()) == LANG_ENGLISH;
198 }
199
200 static BSTR a2bstr(const char *str)
201 {
202 BSTR ret;
203 int len;
204
205 len = MultiByteToWideChar(CP_ACP, 0, str, -1, NULL, 0);
206 ret = SysAllocStringLen(NULL, len-1);
207 MultiByteToWideChar(CP_ACP, 0, str, -1, ret, len);
208
209 return ret;
210 }
211
212 static int strcmp_wa(LPCWSTR strw, const char *stra)
213 {
214 CHAR buf[512];
215 WideCharToMultiByte(CP_ACP, 0, strw, -1, buf, sizeof(buf), 0, 0);
216 return lstrcmpA(buf, stra);
217 }
218
219 #define test_grfdex(a,b) _test_grfdex(__LINE__,a,b)
220 static void _test_grfdex(unsigned line, DWORD grfdex, DWORD expect)
221 {
222 expect |= invoke_version << 28;
223 ok_(__FILE__,line)(grfdex == expect, "grfdex = %x, expected %x\n", grfdex, expect);
224 }
225
226 static HRESULT WINAPI DispatchEx_QueryInterface(IDispatchEx *iface, REFIID riid, void **ppv)
227 {
228 *ppv = NULL;
229
230 if(IsEqualGUID(riid, &IID_IUnknown)
231 || IsEqualGUID(riid, &IID_IDispatch)
232 || IsEqualGUID(riid, &IID_IDispatchEx))
233 *ppv = iface;
234 else
235 return E_NOINTERFACE;
236
237 return S_OK;
238 }
239
240 static ULONG WINAPI DispatchEx_AddRef(IDispatchEx *iface)
241 {
242 return 2;
243 }
244
245 static ULONG WINAPI DispatchEx_Release(IDispatchEx *iface)
246 {
247 return 1;
248 }
249
250 static HRESULT WINAPI DispatchEx_GetTypeInfoCount(IDispatchEx *iface, UINT *pctinfo)
251 {
252 ok(0, "unexpected call\n");
253 return E_NOTIMPL;
254 }
255
256 static HRESULT WINAPI DispatchEx_GetTypeInfo(IDispatchEx *iface, UINT iTInfo,
257 LCID lcid, ITypeInfo **ppTInfo)
258 {
259 ok(0, "unexpected call\n");
260 return E_NOTIMPL;
261 }
262
263 static HRESULT WINAPI DispatchEx_GetIDsOfNames(IDispatchEx *iface, REFIID riid,
264 LPOLESTR *rgszNames, UINT cNames,
265 LCID lcid, DISPID *rgDispId)
266 {
267 ok(0, "unexpected call\n");
268 return E_NOTIMPL;
269 }
270
271 static HRESULT WINAPI DispatchEx_Invoke(IDispatchEx *iface, DISPID dispIdMember,
272 REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS *pDispParams,
273 VARIANT *pVarResult, EXCEPINFO *pExcepInfo, UINT *puArgErr)
274 {
275 ok(0, "unexpected call\n");
276 return E_NOTIMPL;
277 }
278
279 static HRESULT WINAPI DispatchEx_GetDispID(IDispatchEx *iface, BSTR bstrName, DWORD grfdex, DISPID *pid)
280 {
281 ok(0, "unexpected call\n");
282 return E_NOTIMPL;
283 }
284
285 static HRESULT WINAPI DispatchEx_InvokeEx(IDispatchEx *iface, DISPID id, LCID lcid, WORD wFlags, DISPPARAMS *pdp,
286 VARIANT *res, EXCEPINFO *pei, IServiceProvider *pspCaller)
287 {
288 ok(0, "unexpected call\n");
289 return E_NOTIMPL;
290 }
291
292 static HRESULT WINAPI DispatchEx_DeleteMemberByName(IDispatchEx *iface, BSTR bstrName, DWORD grfdex)
293 {
294 ok(0, "unexpected call %s %x\n", wine_dbgstr_w(bstrName), grfdex);
295 return E_NOTIMPL;
296 }
297
298 static HRESULT WINAPI DispatchEx_DeleteMemberByDispID(IDispatchEx *iface, DISPID id)
299 {
300 ok(0, "unexpected call\n");
301 return E_NOTIMPL;
302 }
303
304 static HRESULT WINAPI DispatchEx_GetMemberProperties(IDispatchEx *iface, DISPID id, DWORD grfdexFetch, DWORD *pgrfdex)
305 {
306 ok(0, "unexpected call\n");
307 return E_NOTIMPL;
308 }
309
310 static HRESULT WINAPI DispatchEx_GetMemberName(IDispatchEx *iface, DISPID id, BSTR *pbstrName)
311 {
312 ok(0, "unexpected call\n");
313 return E_NOTIMPL;
314 }
315
316 static HRESULT WINAPI DispatchEx_GetNextDispID(IDispatchEx *iface, DWORD grfdex, DISPID id, DISPID *pid)
317 {
318 ok(0, "unexpected call\n");
319 return E_NOTIMPL;
320 }
321
322 static HRESULT WINAPI DispatchEx_GetNameSpaceParent(IDispatchEx *iface, IUnknown **ppunk)
323 {
324 ok(0, "unexpected call\n");
325 return E_NOTIMPL;
326 }
327
328 static HRESULT WINAPI testObj_GetDispID(IDispatchEx *iface, BSTR bstrName, DWORD grfdex, DISPID *pid)
329 {
330 if(!strcmp_wa(bstrName, "prop")) {
331 CHECK_EXPECT(testobj_prop_d);
332 test_grfdex(grfdex, fdexNameCaseSensitive);
333 *pid = DISPID_TESTOBJ_PROP;
334 return S_OK;
335 }
336 if(!strcmp_wa(bstrName, "withProp")) {
337 CHECK_EXPECT(testobj_withprop_d);
338 test_grfdex(grfdex, fdexNameCaseSensitive|fdexNameImplicit);
339 *pid = DISPID_TESTOBJ_WITHPROP;
340 return S_OK;
341 }
342 if(!strcmp_wa(bstrName, "noprop")) {
343 CHECK_EXPECT(testobj_noprop_d);
344 test_grfdex(grfdex, fdexNameCaseSensitive);
345 return DISP_E_UNKNOWNNAME;
346 }
347 if(!strcmp_wa(bstrName, "onlyDispID")) {
348 if(strict_dispid_check)
349 CHECK_EXPECT(testobj_onlydispid_d);
350 test_grfdex(grfdex, fdexNameCaseSensitive);
351 *pid = DISPID_TESTOBJ_ONLYDISPID;
352 return S_OK;
353 }
354 if(!strcmp_wa(bstrName, "notExists")) {
355 CHECK_EXPECT(testobj_notexists_d);
356 test_grfdex(grfdex, fdexNameCaseSensitive);
357 return DISP_E_UNKNOWNNAME;
358 }
359
360 ok(0, "unexpected name %s\n", wine_dbgstr_w(bstrName));
361 return E_NOTIMPL;
362 }
363
364 static HRESULT WINAPI testObj_InvokeEx(IDispatchEx *iface, DISPID id, LCID lcid, WORD wFlags, DISPPARAMS *pdp,
365 VARIANT *pvarRes, EXCEPINFO *pei, IServiceProvider *pspCaller)
366 {
367 ok(pspCaller != NULL, "pspCaller = NULL\n");
368
369 switch(id) {
370 case DISPID_VALUE:
371 ok(pdp != NULL, "pdp == NULL\n");
372 ok(!pdp->rgdispidNamedArgs, "rgdispidNamedArgs != NULL\n");
373 ok(!pdp->cNamedArgs, "cNamedArgs = %d\n", pdp->cNamedArgs);
374 ok(pvarRes != NULL, "pvarRes == NULL\n");
375 ok(V_VT(pvarRes) == VT_EMPTY, "V_VT(pvarRes) = %d\n", V_VT(pvarRes));
376 ok(pei != NULL, "pei == NULL\n");
377
378 switch(wFlags) {
379 case INVOKE_PROPERTYGET:
380 CHECK_EXPECT(testobj_value);
381 ok(!pdp->rgvarg, "rgvarg != NULL\n");
382 ok(!pdp->cArgs, "cArgs = %d\n", pdp->cArgs);
383 break;
384 case INVOKE_FUNC:
385 ok(!pdp->cArgs, "cArgs = %d\n", pdp->cArgs);
386 break;
387 case INVOKE_FUNC|INVOKE_PROPERTYGET:
388 ok(pdp->cArgs == 1, "cArgs = %d\n", pdp->cArgs);
389 break;
390 case DISPATCH_CONSTRUCT:
391 CHECK_EXPECT(testobj_construct);
392 ok(pdp->cArgs == 1, "cArgs = %d\n", pdp->cArgs);
393 break;
394 default:
395 ok(0, "invalid flag (%x)\n", wFlags);
396 }
397
398 V_VT(pvarRes) = VT_I4;
399 V_I4(pvarRes) = 1;
400 return S_OK;
401 case DISPID_TESTOBJ_ONLYDISPID:
402 if(strict_dispid_check)
403 CHECK_EXPECT(testobj_onlydispid_i);
404 ok(wFlags == INVOKE_PROPERTYGET, "wFlags = %x\n", wFlags);
405 ok(pdp != NULL, "pdp == NULL\n");
406 ok(!pdp->rgvarg, "rgvarg != NULL\n");
407 ok(!pdp->rgdispidNamedArgs, "rgdispidNamedArgs != NULL\n");
408 ok(!pdp->cArgs, "cArgs = %d\n", pdp->cArgs);
409 ok(!pdp->cNamedArgs, "cNamedArgs = %d\n", pdp->cNamedArgs);
410 ok(pvarRes != NULL, "pvarRes == NULL\n");
411 ok(V_VT(pvarRes) == VT_EMPTY, "V_VT(pvarRes) = %d\n", V_VT(pvarRes));
412 ok(pei != NULL, "pei == NULL\n");
413 return DISP_E_MEMBERNOTFOUND;
414 case DISPID_TESTOBJ_WITHPROP:
415 CHECK_EXPECT(testobj_withprop_i);
416
417 ok(wFlags == INVOKE_PROPERTYGET, "wFlags = %x\n", wFlags);
418 ok(pdp != NULL, "pdp == NULL\n");
419 ok(!pdp->rgvarg, "rgvarg != NULL\n");
420 ok(!pdp->rgdispidNamedArgs, "rgdispidNamedArgs != NULL\n");
421 ok(!pdp->cArgs, "cArgs = %d\n", pdp->cArgs);
422 ok(!pdp->cNamedArgs, "cNamedArgs = %d\n", pdp->cNamedArgs);
423 ok(pvarRes != NULL, "pvarRes == NULL\n");
424 ok(V_VT(pvarRes) == VT_EMPTY, "V_VT(pvarRes) = %d\n", V_VT(pvarRes));
425 ok(pei != NULL, "pei == NULL\n");
426
427 V_VT(pvarRes) = VT_I4;
428 V_I4(pvarRes) = 1;
429
430 return S_OK;
431 }
432
433 ok(0, "unexpected call %x\n", id);
434 return DISP_E_MEMBERNOTFOUND;
435 }
436
437 static HRESULT WINAPI testObj_DeleteMemberByName(IDispatchEx *iface, BSTR bstrName, DWORD grfdex)
438 {
439 if(!strcmp_wa(bstrName, "deleteTest")) {
440 CHECK_EXPECT(testobj_delete_test);
441 test_grfdex(grfdex, fdexNameCaseSensitive);
442 return S_OK;
443 }
444 if(!strcmp_wa(bstrName, "noDeleteTest")) {
445 CHECK_EXPECT(testobj_delete_nodelete);
446 test_grfdex(grfdex, fdexNameCaseSensitive);
447 return S_FALSE;
448 }
449
450 ok(0, "unexpected name %s\n", wine_dbgstr_w(bstrName));
451 return E_FAIL;
452 }
453
454 static IDispatchExVtbl testObjVtbl = {
455 DispatchEx_QueryInterface,
456 DispatchEx_AddRef,
457 DispatchEx_Release,
458 DispatchEx_GetTypeInfoCount,
459 DispatchEx_GetTypeInfo,
460 DispatchEx_GetIDsOfNames,
461 DispatchEx_Invoke,
462 testObj_GetDispID,
463 testObj_InvokeEx,
464 testObj_DeleteMemberByName,
465 DispatchEx_DeleteMemberByDispID,
466 DispatchEx_GetMemberProperties,
467 DispatchEx_GetMemberName,
468 DispatchEx_GetNextDispID,
469 DispatchEx_GetNameSpaceParent
470 };
471
472 static IDispatchEx testObj = { &testObjVtbl };
473
474 static HRESULT WINAPI dispexFunc_InvokeEx(IDispatchEx *iface, DISPID id, LCID lcid, WORD wFlags, DISPPARAMS *pdp,
475 VARIANT *res, EXCEPINFO *pei, IServiceProvider *pspCaller)
476 {
477 ok(pspCaller != NULL, "pspCaller = NULL\n");
478
479 switch(id) {
480 case DISPID_VALUE:
481 CHECK_EXPECT(dispexfunc_value);
482
483 ok(pdp != NULL, "pdp == NULL\n");
484 ok(pdp->rgvarg != NULL, "rgvarg == NULL\n");
485 ok(pdp->rgdispidNamedArgs != NULL, "rgdispidNamedArgs != NULL\n");
486 ok(*pdp->rgdispidNamedArgs == DISPID_THIS, "*rgdispidNamedArgs = %d\n", *pdp->rgdispidNamedArgs);
487 ok(pdp->cArgs == 2, "cArgs = %d\n", pdp->cArgs);
488 ok(pdp->cNamedArgs == 1, "cNamedArgs = %d\n", pdp->cNamedArgs);
489 ok(res != NULL, "res == NULL\n");
490 ok(wFlags == (DISPATCH_PROPERTYGET|DISPATCH_METHOD), "wFlags = %x\n", wFlags);
491 ok(pei != NULL, "pei == NULL\n");
492
493 ok(V_VT(pdp->rgvarg+1) == VT_BOOL, "V_VT(pdp->rgvarg+1) = %d\n", V_VT(pdp->rgvarg+1));
494 ok(!V_BOOL(pdp->rgvarg+1), "V_BOOL(pdp->rgvarg+1) = %x\n", V_BOOL(pdp->rgvarg+1));
495
496 ok(V_VT(pdp->rgvarg) == VT_DISPATCH, "V_VT(pdp->rgvarg) = %d\n", V_VT(pdp->rgvarg));
497 ok(V_DISPATCH(pdp->rgvarg) != NULL, "V_DISPATCH(pdp->rgvarg) == NULL\n");
498
499 if(res)
500 V_VT(res) = VT_NULL;
501 return S_OK;
502 default:
503 ok(0, "unexpected call %x\n", id);
504 return DISP_E_MEMBERNOTFOUND;
505 }
506 }
507
508 static IDispatchExVtbl dispexFuncVtbl = {
509 DispatchEx_QueryInterface,
510 DispatchEx_AddRef,
511 DispatchEx_Release,
512 DispatchEx_GetTypeInfoCount,
513 DispatchEx_GetTypeInfo,
514 DispatchEx_GetIDsOfNames,
515 DispatchEx_Invoke,
516 DispatchEx_GetDispID,
517 dispexFunc_InvokeEx,
518 DispatchEx_DeleteMemberByName,
519 DispatchEx_DeleteMemberByDispID,
520 DispatchEx_GetMemberProperties,
521 DispatchEx_GetMemberName,
522 DispatchEx_GetNextDispID,
523 DispatchEx_GetNameSpaceParent
524 };
525
526 static IDispatchEx dispexFunc = { &dispexFuncVtbl };
527
528 static HRESULT WINAPI pureDisp_QueryInterface(IDispatchEx *iface, REFIID riid, void **ppv)
529 {
530 if(IsEqualGUID(riid, &IID_IUnknown) || IsEqualGUID(riid, &IID_IDispatch)) {
531 *ppv = iface;
532 return S_OK;
533 }
534
535 *ppv = NULL;
536 return E_NOINTERFACE;
537 }
538
539 static HRESULT WINAPI pureDisp_GetIDsOfNames(IDispatchEx *iface, REFIID riid,
540 LPOLESTR *rgszNames, UINT cNames,
541 LCID lcid, DISPID *rgDispId)
542 {
543 ok(IsEqualGUID(riid, &IID_NULL), "Expected IID_NULL\n");
544 ok(cNames==1, "cNames = %d\n", cNames);
545
546 if(!strcmp_wa(*rgszNames, "prop")) {
547 CHECK_EXPECT(puredisp_prop_d);
548 *rgDispId = DISPID_TESTOBJ_PROP;
549 return S_OK;
550 } else if(!strcmp_wa(*rgszNames, "noprop")) {
551 CHECK_EXPECT(puredisp_noprop_d);
552 return DISP_E_UNKNOWNNAME;
553 }
554
555 ok(0, "unexpected call\n");
556 return E_NOTIMPL;
557 }
558
559 static HRESULT WINAPI pureDisp_Invoke(IDispatchEx *iface, DISPID dispIdMember, REFIID riid, LCID lcid,
560 WORD wFlags, DISPPARAMS *pdp, VARIANT *res, EXCEPINFO *ei, UINT *puArgErr)
561 {
562 ok(IsEqualGUID(&IID_NULL, riid), "unexpected riid\n");
563
564 switch(dispIdMember) {
565 case DISPID_VALUE:
566 CHECK_EXPECT(puredisp_value);
567
568 ok(pdp != NULL, "pdp == NULL\n");
569 ok(pdp->rgvarg != NULL, "rgvarg == NULL\n");
570 ok(!pdp->rgdispidNamedArgs, "rgdispidNamedArgs != NULL\n");
571 ok(pdp->cArgs == 1, "cArgs = %d\n", pdp->cArgs);
572 ok(!pdp->cNamedArgs, "cNamedArgs = %d\n", pdp->cNamedArgs);
573 ok(res != NULL, "res == NULL\n");
574 ok(wFlags == (DISPATCH_PROPERTYGET|DISPATCH_METHOD), "wFlags = %x\n", wFlags);
575 ok(ei != NULL, "ei == NULL\n");
576 ok(puArgErr != NULL, "puArgErr == NULL\n");
577
578 ok(V_VT(pdp->rgvarg) == VT_BOOL, "V_VT(pdp->rgvarg) = %d\n", V_VT(pdp->rgvarg));
579 ok(!V_BOOL(pdp->rgvarg), "V_BOOL(pdp->rgvarg) = %x\n", V_BOOL(pdp->rgvarg));
580
581 if(res)
582 V_VT(res) = VT_NULL;
583 return S_OK;
584 default:
585 ok(0, "unexpected call\n");
586 return E_NOTIMPL;
587 }
588 }
589
590 static IDispatchExVtbl pureDispVtbl = {
591 pureDisp_QueryInterface,
592 DispatchEx_AddRef,
593 DispatchEx_Release,
594 DispatchEx_GetTypeInfoCount,
595 DispatchEx_GetTypeInfo,
596 pureDisp_GetIDsOfNames,
597 pureDisp_Invoke
598 };
599
600 static IDispatchEx pureDisp = { &pureDispVtbl };
601
602 static HRESULT WINAPI BindEventHandler_QueryInterface(IBindEventHandler *iface, REFIID riid, void **ppv)
603 {
604 ok(0, "unexpected call\n");
605 return E_NOINTERFACE;
606 }
607
608 static ULONG WINAPI BindEventHandler_AddRef(IBindEventHandler *iface)
609 {
610 return 2;
611 }
612
613 static ULONG WINAPI BindEventHandler_Release(IBindEventHandler *iface)
614 {
615 return 1;
616 }
617
618 static HRESULT WINAPI BindEventHandler_BindHandler(IBindEventHandler *iface, const WCHAR *event, IDispatch *disp)
619 {
620 CHECK_EXPECT(BindHandler);
621 ok(!strcmp_wa(event, "eventName"), "event = %s\n", wine_dbgstr_w(event));
622 ok(disp != NULL, "disp = NULL\n");
623 return S_OK;
624 }
625
626 static const IBindEventHandlerVtbl BindEventHandlerVtbl = {
627 BindEventHandler_QueryInterface,
628 BindEventHandler_AddRef,
629 BindEventHandler_Release,
630 BindEventHandler_BindHandler
631 };
632
633 static IBindEventHandler BindEventHandler = { &BindEventHandlerVtbl };
634
635 static HRESULT WINAPI bindEventHandlerDisp_QueryInterface(IDispatchEx *iface, REFIID riid, void **ppv)
636 {
637 if(IsEqualGUID(riid, &IID_IUnknown) || IsEqualGUID(riid, &IID_IDispatch) || IsEqualGUID(riid, &IID_IDispatchEx)) {
638 *ppv = iface;
639 return S_OK;
640 }
641
642 if(IsEqualGUID(riid, &IID_IBindEventHandler)) {
643 *ppv = &BindEventHandler;
644 return S_OK;
645 }
646
647 *ppv = NULL;
648 return E_NOINTERFACE;
649 }
650
651 static IDispatchExVtbl bindEventHandlerDispVtbl = {
652 bindEventHandlerDisp_QueryInterface,
653 DispatchEx_AddRef,
654 DispatchEx_Release,
655 DispatchEx_GetTypeInfoCount,
656 DispatchEx_GetTypeInfo,
657 DispatchEx_GetIDsOfNames,
658 DispatchEx_Invoke,
659 DispatchEx_GetDispID,
660 DispatchEx_InvokeEx,
661 DispatchEx_DeleteMemberByName,
662 DispatchEx_DeleteMemberByDispID,
663 DispatchEx_GetMemberProperties,
664 DispatchEx_GetMemberName,
665 DispatchEx_GetNextDispID,
666 DispatchEx_GetNameSpaceParent
667 };
668
669 static IDispatchEx bindEventHandlerDisp = { &bindEventHandlerDispVtbl };
670
671 static HRESULT WINAPI Global_GetDispID(IDispatchEx *iface, BSTR bstrName, DWORD grfdex, DISPID *pid)
672 {
673 if(!strcmp_wa(bstrName, "ok")) {
674 test_grfdex(grfdex, fdexNameCaseSensitive);
675 *pid = DISPID_GLOBAL_OK;
676 return S_OK;
677 }
678 if(!strcmp_wa(bstrName, "trace")) {
679 test_grfdex(grfdex, fdexNameCaseSensitive);
680 *pid = DISPID_GLOBAL_TRACE;
681 return S_OK;
682 }
683 if(!strcmp_wa(bstrName, "reportSuccess")) {
684 CHECK_EXPECT(global_success_d);
685 test_grfdex(grfdex, fdexNameCaseSensitive);
686 *pid = DISPID_GLOBAL_REPORTSUCCESS;
687 return S_OK;
688 }
689 if(!strcmp_wa(bstrName, "testPropGet")) {
690 CHECK_EXPECT(global_propget_d);
691 test_grfdex(grfdex, fdexNameCaseSensitive);
692 *pid = DISPID_GLOBAL_TESTPROPGET;
693 return S_OK;
694 }
695 if(!strcmp_wa(bstrName, "testPropPut")) {
696 CHECK_EXPECT(global_propput_d);
697 test_grfdex(grfdex, fdexNameCaseSensitive);
698 *pid = DISPID_GLOBAL_TESTPROPPUT;
699 return S_OK;
700 }
701 if(!strcmp_wa(bstrName, "testPropPutRef")) {
702 CHECK_EXPECT(global_propputref_d);
703 test_grfdex(grfdex, fdexNameCaseSensitive);
704 *pid = DISPID_GLOBAL_TESTPROPPUTREF;
705 return S_OK;
706 }
707 if(!strcmp_wa(bstrName, "testPropDelete")) {
708 CHECK_EXPECT(global_propdelete_d);
709 test_grfdex(grfdex, fdexNameCaseSensitive);
710 *pid = DISPID_GLOBAL_TESTPROPDELETE;
711 return S_OK;
712 }
713 if(!strcmp_wa(bstrName, "testNoPropDelete")) {
714 CHECK_EXPECT(global_nopropdelete_d);
715 test_grfdex(grfdex, fdexNameCaseSensitive);
716 *pid = DISPID_GLOBAL_TESTNOPROPDELETE;
717 return S_OK;
718 }
719 if(!strcmp_wa(bstrName, "getVT")) {
720 test_grfdex(grfdex, fdexNameCaseSensitive);
721 *pid = DISPID_GLOBAL_GETVT;
722 return S_OK;
723 }
724 if(!strcmp_wa(bstrName, "testObj")) {
725 test_grfdex(grfdex, fdexNameCaseSensitive);
726 *pid = DISPID_GLOBAL_TESTOBJ;
727 return S_OK;
728 }
729 if(!strcmp_wa(bstrName, "getNullBSTR")) {
730 *pid = DISPID_GLOBAL_GETNULLBSTR;
731 return S_OK;
732 }
733 if(!strcmp_wa(bstrName, "isNullBSTR")) {
734 *pid = DISPID_GLOBAL_ISNULLBSTR;
735 return S_OK;
736 }
737 if(!strcmp_wa(bstrName, "nullDisp")) {
738 *pid = DISPID_GLOBAL_NULL_DISP;
739 return S_OK;
740 }
741 if(!strcmp_wa(bstrName, "notExists")) {
742 CHECK_EXPECT(global_notexists_d);
743 test_grfdex(grfdex, fdexNameCaseSensitive);
744 return DISP_E_UNKNOWNNAME;
745 }
746
747 if(!strcmp_wa(bstrName, "testThis")) {
748 test_grfdex(grfdex, fdexNameCaseSensitive);
749 *pid = DISPID_GLOBAL_TESTTHIS;
750 return S_OK;
751 }
752
753 if(!strcmp_wa(bstrName, "testThis2")) {
754 test_grfdex(grfdex, fdexNameCaseSensitive);
755 *pid = DISPID_GLOBAL_TESTTHIS2;
756 return S_OK;
757 }
758
759 if(!strcmp_wa(bstrName, "invokeVersion")) {
760 test_grfdex(grfdex, fdexNameCaseSensitive);
761 *pid = DISPID_GLOBAL_INVOKEVERSION;
762 return S_OK;
763 }
764 if(!strcmp_wa(bstrName, "createArray")) {
765 test_grfdex(grfdex, fdexNameCaseSensitive);
766 *pid = DISPID_GLOBAL_CREATEARRAY;
767 return S_OK;
768 }
769 if(!strcmp_wa(bstrName, "propGetFunc")) {
770 test_grfdex(grfdex, fdexNameCaseSensitive);
771 *pid = DISPID_GLOBAL_PROPGETFUNC;
772 return S_OK;
773 }
774 if(!strcmp_wa(bstrName, "objectFlag")) {
775 test_grfdex(grfdex, fdexNameCaseSensitive);
776 *pid = DISPID_GLOBAL_OBJECT_FLAG;
777 return S_OK;
778 }
779
780 if(!strcmp_wa(bstrName, "isWin64")) {
781 test_grfdex(grfdex, fdexNameCaseSensitive);
782 *pid = DISPID_GLOBAL_ISWIN64;
783 return S_OK;
784 }
785
786 if(!strcmp_wa(bstrName, "pureDisp")) {
787 test_grfdex(grfdex, fdexNameCaseSensitive);
788 *pid = DISPID_GLOBAL_PUREDISP;
789 return S_OK;
790 }
791
792 if(!strcmp_wa(bstrName, "propArgPutG")) {
793 CHECK_EXPECT(global_propargput_d);
794 test_grfdex(grfdex, fdexNameCaseSensitive);
795 *pid = DISPID_GLOBAL_PROPARGPUT;
796 return S_OK;
797 }
798
799 if(!strcmp_wa(bstrName, "propArgPutO")) {
800 CHECK_EXPECT(global_propargput_d);
801 test_grfdex(grfdex, fdexNameEnsure|fdexNameCaseSensitive);
802 *pid = DISPID_GLOBAL_PROPARGPUT;
803 return S_OK;
804 }
805
806 if(!strcmp_wa(bstrName, "shortProp")) {
807 *pid = DISPID_GLOBAL_SHORTPROP;
808 return S_OK;
809 }
810
811 if(!strcmp_wa(bstrName, "getShort")) {
812 *pid = DISPID_GLOBAL_GETSHORT;
813 return S_OK;
814 }
815
816 if(!strcmp_wa(bstrName, "testArgTypes")) {
817 *pid = DISPID_GLOBAL_TESTARGTYPES;
818 return S_OK;
819 }
820
821 if(!strcmp_wa(bstrName, "intProp")) {
822 *pid = DISPID_GLOBAL_INTPROP;
823 return S_OK;
824 }
825
826 if(!strcmp_wa(bstrName, "dispUnk")) {
827 *pid = DISPID_GLOBAL_DISPUNK;
828 return S_OK;
829 }
830
831 if(!strcmp_wa(bstrName, "testRes")) {
832 *pid = DISPID_GLOBAL_TESTRES;
833 return S_OK;
834 }
835
836 if(!strcmp_wa(bstrName, "testNoRes")) {
837 *pid = DISPID_GLOBAL_TESTNORES;
838 return S_OK;
839 }
840
841 if(!strcmp_wa(bstrName, "dispexFunc")) {
842 *pid = DISPID_GLOBAL_DISPEXFUNC;
843 return S_OK;
844 }
845
846 if(!strcmp_wa(bstrName, "getScriptState")) {
847 *pid = DISPID_GLOBAL_GETSCRIPTSTATE;
848 return S_OK;
849 }
850
851 if(!strcmp_wa(bstrName, "bindEventHandler")) {
852 *pid = DISPID_GLOBAL_BINDEVENTHANDLER;
853 return S_OK;
854 }
855
856 if(strict_dispid_check && strcmp_wa(bstrName, "t"))
857 ok(0, "unexpected call %s\n", wine_dbgstr_w(bstrName));
858 return DISP_E_UNKNOWNNAME;
859 }
860
861 static HRESULT WINAPI Global_InvokeEx(IDispatchEx *iface, DISPID id, LCID lcid, WORD wFlags, DISPPARAMS *pdp,
862 VARIANT *pvarRes, EXCEPINFO *pei, IServiceProvider *pspCaller)
863 {
864 ok(pspCaller != NULL, "pspCaller = NULL\n");
865
866 switch(id) {
867 case DISPID_GLOBAL_OK:
868 ok(wFlags == INVOKE_FUNC || wFlags == (INVOKE_FUNC|INVOKE_PROPERTYGET), "wFlags = %x\n", wFlags);
869 ok(pdp != NULL, "pdp == NULL\n");
870 ok(pdp->rgvarg != NULL, "rgvarg == NULL\n");
871 ok(!pdp->rgdispidNamedArgs, "rgdispidNamedArgs != NULL\n");
872 ok(pdp->cArgs == 2, "cArgs = %d\n", pdp->cArgs);
873 ok(!pdp->cNamedArgs, "cNamedArgs = %d\n", pdp->cNamedArgs);
874 if(wFlags & INVOKE_PROPERTYGET)
875 ok(pvarRes != NULL, "pvarRes == NULL\n");
876 else
877 ok(!pvarRes, "pvarRes != NULL\n");
878 ok(pei != NULL, "pei == NULL\n");
879
880 ok(V_VT(pdp->rgvarg) == VT_BSTR, "V_VT(pdp->rgvarg) = %d\n", V_VT(pdp->rgvarg));
881 ok(V_VT(pdp->rgvarg+1) == VT_BOOL, "V_VT(pdp->rgvarg+1) = %d\n", V_VT(pdp->rgvarg+1));
882 ok(V_BOOL(pdp->rgvarg+1), "%s: %s\n", test_name, wine_dbgstr_w(V_BSTR(pdp->rgvarg)));
883
884 return S_OK;
885
886 case DISPID_GLOBAL_TRACE:
887 ok(wFlags == INVOKE_FUNC, "wFlags = %x\n", wFlags);
888 ok(pdp != NULL, "pdp == NULL\n");
889 ok(pdp->rgvarg != NULL, "rgvarg == NULL\n");
890 ok(!pdp->rgdispidNamedArgs, "rgdispidNamedArgs != NULL\n");
891 ok(pdp->cArgs == 1, "cArgs = %d\n", pdp->cArgs);
892 ok(!pdp->cNamedArgs, "cNamedArgs = %d\n", pdp->cNamedArgs);
893 ok(!pvarRes, "pvarRes != NULL\n");
894 ok(pei != NULL, "pei == NULL\n");
895
896 ok(V_VT(pdp->rgvarg) == VT_BSTR, "V_VT(pdp->rgvarg) = %d\n", V_VT(pdp->rgvarg));
897 if(V_VT(pdp->rgvarg) == VT_BSTR)
898 trace("%s: %s\n", test_name, wine_dbgstr_w(V_BSTR(pdp->rgvarg)));
899
900 return S_OK;
901
902 case DISPID_GLOBAL_REPORTSUCCESS:
903 CHECK_EXPECT(global_success_i);
904
905 ok(wFlags == INVOKE_FUNC, "wFlags = %x\n", wFlags);
906 ok(pdp != NULL, "pdp == NULL\n");
907 ok(!pdp->rgdispidNamedArgs, "rgdispidNamedArgs != NULL\n");
908 ok(pdp->cArgs == 0, "cArgs = %d\n", pdp->cArgs);
909 ok(!pdp->cNamedArgs, "cNamedArgs = %d\n", pdp->cNamedArgs);
910 if(!testing_expr)
911 ok(!pvarRes, "pvarRes != NULL\n");
912 ok(pei != NULL, "pei == NULL\n");
913
914 return S_OK;
915
916 case DISPID_GLOBAL_TESTPROPGET:
917 CHECK_EXPECT(global_propget_i);
918
919 ok(wFlags == INVOKE_PROPERTYGET, "wFlags = %x\n", wFlags);
920 ok(pdp != NULL, "pdp == NULL\n");
921 ok(!pdp->rgvarg, "rgvarg != NULL\n");
922 ok(!pdp->rgdispidNamedArgs, "rgdispidNamedArgs != NULL\n");
923 ok(!pdp->cArgs, "cArgs = %d\n", pdp->cArgs);
924 ok(!pdp->cNamedArgs, "cNamedArgs = %d\n", pdp->cNamedArgs);
925 ok(pvarRes != NULL, "pvarRes == NULL\n");
926 ok(V_VT(pvarRes) == VT_EMPTY, "V_VT(pvarRes) = %d\n", V_VT(pvarRes));
927 ok(pei != NULL, "pei == NULL\n");
928
929 V_VT(pvarRes) = VT_I4;
930 V_I4(pvarRes) = 1;
931
932 return S_OK;
933
934 case DISPID_GLOBAL_TESTPROPPUT:
935 CHECK_EXPECT(global_propput_i);
936
937 ok(wFlags == INVOKE_PROPERTYPUT, "wFlags = %x\n", wFlags);
938 ok(pdp != NULL, "pdp == NULL\n");
939 ok(pdp->rgvarg != NULL, "rgvarg == NULL\n");
940 ok(pdp->rgdispidNamedArgs != NULL, "rgdispidNamedArgs == NULL\n");
941 ok(pdp->cArgs == 1, "cArgs = %d\n", pdp->cArgs);
942 ok(pdp->cNamedArgs == 1, "cNamedArgs = %d\n", pdp->cNamedArgs);
943 ok(pdp->rgdispidNamedArgs[0] == DISPID_PROPERTYPUT, "pdp->rgdispidNamedArgs[0] = %d\n", pdp->rgdispidNamedArgs[0]);
944 ok(!pvarRes, "pvarRes != NULL\n");
945
946 ok(V_VT(pdp->rgvarg) == VT_I4, "V_VT(pdp->rgvarg)=%d\n", V_VT(pdp->rgvarg));
947 ok(V_I4(pdp->rgvarg) == 1, "V_I4(pdp->rgvarg)=%d\n", V_I4(pdp->rgvarg));
948 return S_OK;
949
950 case DISPID_GLOBAL_TESTPROPPUTREF:
951 CHECK_EXPECT(global_propputref_i);
952
953 ok(wFlags == (INVOKE_PROPERTYPUT|INVOKE_PROPERTYPUTREF), "wFlags = %x\n", wFlags);
954 ok(pdp != NULL, "pdp == NULL\n");
955 ok(pdp->rgvarg != NULL, "rgvarg == NULL\n");
956 ok(pdp->rgdispidNamedArgs != NULL, "rgdispidNamedArgs == NULL\n");
957 ok(pdp->cArgs == 1, "cArgs = %d\n", pdp->cArgs);
958 ok(pdp->cNamedArgs == 1, "cNamedArgs = %d\n", pdp->cNamedArgs);
959 ok(pdp->rgdispidNamedArgs[0] == DISPID_PROPERTYPUT, "pdp->rgdispidNamedArgs[0] = %d\n", pdp->rgdispidNamedArgs[0]);
960 ok(!pvarRes, "pvarRes != NULL\n");
961
962 ok(V_VT(pdp->rgvarg) == VT_DISPATCH, "V_VT(pdp->rgvarg)=%d\n", V_VT(pdp->rgvarg));
963 return S_OK;
964
965 case DISPID_GLOBAL_GETVT:
966 ok(pdp != NULL, "pdp == NULL\n");
967 ok(pdp->rgvarg != NULL, "rgvarg == NULL\n");
968 ok(!pdp->rgdispidNamedArgs, "rgdispidNamedArgs != NULL\n");
969 ok(pdp->cArgs == 1, "cArgs = %d\n", pdp->cArgs);
970 ok(!pdp->cNamedArgs, "cNamedArgs = %d\n", pdp->cNamedArgs);
971 ok(pvarRes != NULL, "pvarRes == NULL\n");
972 ok(V_VT(pvarRes) == VT_EMPTY, "V_VT(pvarRes) = %d\n", V_VT(pvarRes));
973 ok(pei != NULL, "pei == NULL\n");
974
975 V_VT(pvarRes) = VT_BSTR;
976 switch(V_VT(pdp->rgvarg)) {
977 case VT_EMPTY:
978 V_BSTR(pvarRes) = a2bstr("VT_EMPTY");
979 break;
980 case VT_NULL:
981 V_BSTR(pvarRes) = a2bstr("VT_NULL");
982 break;
983 case VT_I4:
984 V_BSTR(pvarRes) = a2bstr("VT_I4");
985 break;
986 case VT_R8:
987 V_BSTR(pvarRes) = a2bstr("VT_R8");
988 break;
989 case VT_BSTR:
990 V_BSTR(pvarRes) = a2bstr("VT_BSTR");
991 break;
992 case VT_DISPATCH:
993 V_BSTR(pvarRes) = a2bstr("VT_DISPATCH");
994 break;
995 case VT_BOOL:
996 V_BSTR(pvarRes) = a2bstr("VT_BOOL");
997 break;
998 case VT_ARRAY|VT_VARIANT:
999 V_BSTR(pvarRes) = a2bstr("VT_ARRAY|VT_VARIANT");
1000 break;
1001 default:
1002 ok(0, "unknown vt %d\n", V_VT(pdp->rgvarg));
1003 return E_FAIL;
1004 }
1005
1006 return S_OK;
1007
1008 case DISPID_GLOBAL_TESTRES:
1009 ok(pvarRes != NULL, "pvarRes = NULL\n");
1010 if(pvarRes) {
1011 V_VT(pvarRes) = VT_BOOL;
1012 V_BOOL(pvarRes) = VARIANT_TRUE;
1013 }
1014 return S_OK;
1015
1016 case DISPID_GLOBAL_TESTNORES:
1017 ok(!pvarRes, "pvarRes != NULL\n");
1018 if(pvarRes)
1019 V_VT(pvarRes) = VT_NULL;
1020 return S_OK;
1021
1022 case DISPID_GLOBAL_TESTOBJ:
1023 ok(wFlags == INVOKE_PROPERTYGET, "wFlags = %x\n", wFlags);
1024 ok(pdp != NULL, "pdp == NULL\n");
1025 ok(!pdp->rgvarg, "rgvarg != NULL\n");
1026 ok(!pdp->rgdispidNamedArgs, "rgdispidNamedArgs != NULL\n");
1027 ok(!pdp->cArgs, "cArgs = %d\n", pdp->cArgs);
1028 ok(!pdp->cNamedArgs, "cNamedArgs = %d\n", pdp->cNamedArgs);
1029 ok(pvarRes != NULL, "pvarRes == NULL\n");
1030 ok(V_VT(pvarRes) == VT_EMPTY, "V_VT(pvarRes) = %d\n", V_VT(pvarRes));
1031 ok(pei != NULL, "pei == NULL\n");
1032
1033 V_VT(pvarRes) = VT_DISPATCH;
1034 V_DISPATCH(pvarRes) = (IDispatch*)&testObj;
1035 return S_OK;
1036
1037 case DISPID_GLOBAL_PUREDISP:
1038 ok(wFlags == INVOKE_PROPERTYGET, "wFlags = %x\n", wFlags);
1039 ok(pdp != NULL, "pdp == NULL\n");
1040 ok(!pdp->rgvarg, "rgvarg != NULL\n");
1041 ok(!pdp->rgdispidNamedArgs, "rgdispidNamedArgs != NULL\n");
1042 ok(!pdp->cArgs, "cArgs = %d\n", pdp->cArgs);
1043 ok(!pdp->cNamedArgs, "cNamedArgs = %d\n", pdp->cNamedArgs);
1044 ok(pvarRes != NULL, "pvarRes == NULL\n");
1045 ok(V_VT(pvarRes) == VT_EMPTY, "V_VT(pvarRes) = %d\n", V_VT(pvarRes));
1046 ok(pei != NULL, "pei == NULL\n");
1047
1048 V_VT(pvarRes) = VT_DISPATCH;
1049 V_DISPATCH(pvarRes) = (IDispatch*)&pureDisp;
1050 return S_OK;
1051
1052 case DISPID_GLOBAL_DISPEXFUNC:
1053 V_VT(pvarRes) = VT_DISPATCH;
1054 V_DISPATCH(pvarRes) = (IDispatch*)&dispexFunc;
1055 return S_OK;
1056
1057 case DISPID_GLOBAL_GETNULLBSTR:
1058 if(pvarRes) {
1059 V_VT(pvarRes) = VT_BSTR;
1060 V_BSTR(pvarRes) = NULL;
1061 }
1062 return S_OK;
1063
1064 case DISPID_GLOBAL_ISNULLBSTR:
1065 ok(pdp != NULL, "pdp == NULL\n");
1066 ok(pdp->rgvarg != NULL, "rgvarg == NULL\n");
1067 ok(!pdp->rgdispidNamedArgs, "rgdispidNamedArgs != NULL\n");
1068 ok(pdp->cArgs == 1, "cArgs = %d\n", pdp->cArgs);
1069 ok(!pdp->cNamedArgs, "cNamedArgs = %d\n", pdp->cNamedArgs);
1070 ok(pvarRes != NULL, "pvarRes == NULL\n");
1071 ok(V_VT(pvarRes) == VT_EMPTY, "V_VT(pvarRes) = %d\n", V_VT(pvarRes));
1072 ok(pei != NULL, "pei == NULL\n");
1073 ok(V_VT(pdp->rgvarg) == VT_BSTR, "V_VT(pdp->rgvarg) = %d\n", V_VT(pdp->rgvarg));
1074
1075 V_VT(pvarRes) = VT_BOOL;
1076 V_BOOL(pvarRes) = V_BSTR(pdp->rgvarg) ? VARIANT_FALSE : VARIANT_TRUE;
1077 return S_OK;
1078
1079 case DISPID_GLOBAL_ISWIN64:
1080 if(pvarRes) {
1081 V_VT(pvarRes) = VT_BOOL;
1082 V_BOOL(pvarRes) = sizeof(void*) == 8 ? VARIANT_TRUE : VARIANT_FALSE;
1083 }
1084 return S_OK;
1085
1086 case DISPID_GLOBAL_NULL_DISP:
1087 ok(wFlags == INVOKE_PROPERTYGET, "wFlags = %x\n", wFlags);
1088 ok(pdp != NULL, "pdp == NULL\n");
1089 ok(!pdp->rgvarg, "rgvarg != NULL\n");
1090 ok(!pdp->rgdispidNamedArgs, "rgdispidNamedArgs != NULL\n");
1091 ok(!pdp->cArgs, "cArgs = %d\n", pdp->cArgs);
1092 ok(!pdp->cNamedArgs, "cNamedArgs = %d\n", pdp->cNamedArgs);
1093 ok(pvarRes != NULL, "pvarRes == NULL\n");
1094 ok(V_VT(pvarRes) == VT_EMPTY, "V_VT(pvarRes) = %d\n", V_VT(pvarRes));
1095 ok(pei != NULL, "pei == NULL\n");
1096
1097 V_VT(pvarRes) = VT_DISPATCH;
1098 V_DISPATCH(pvarRes) = NULL;
1099 return S_OK;
1100
1101 case DISPID_GLOBAL_TESTTHIS:
1102 ok(pdp != NULL, "pdp == NULL\n");
1103 ok(pdp->rgvarg != NULL, "rgvarg == NULL\n");
1104 ok(!pdp->rgdispidNamedArgs, "rgdispidNamedArgs != NULL\n");
1105 ok(pdp->cArgs == 1, "cArgs = %d\n", pdp->cArgs);
1106 ok(!pdp->cNamedArgs, "cNamedArgs = %d\n", pdp->cNamedArgs);
1107 ok(pvarRes == NULL, "pvarRes != NULL\n");
1108 ok(pei != NULL, "pei == NULL\n");
1109
1110 ok(V_VT(pdp->rgvarg) == VT_DISPATCH, "V_VT(pdp->rgvarg) = %d\n", V_VT(pdp->rgvarg));
1111 ok(V_DISPATCH(pdp->rgvarg) == (IDispatch*)iface, "disp != iface\n");
1112
1113 return S_OK;
1114
1115 case DISPID_GLOBAL_TESTTHIS2:
1116 ok(pdp != NULL, "pdp == NULL\n");
1117 ok(pdp->rgvarg != NULL, "rgvarg == NULL\n");
1118 ok(!pdp->rgdispidNamedArgs, "rgdispidNamedArgs != NULL\n");
1119 ok(pdp->cArgs == 1, "cArgs = %d\n", pdp->cArgs);
1120 ok(!pdp->cNamedArgs, "cNamedArgs = %d\n", pdp->cNamedArgs);
1121 ok(pvarRes == NULL, "pvarRes != NULL\n");
1122 ok(pei != NULL, "pei == NULL\n");
1123
1124 ok(V_VT(pdp->rgvarg) == VT_DISPATCH, "V_VT(arg) = %d\n", V_VT(pdp->rgvarg));
1125 ok(V_DISPATCH(pdp->rgvarg) != (IDispatch*)iface, "disp == iface\n");
1126 ok(V_DISPATCH(pdp->rgvarg) == script_disp, "disp != script_disp\n");
1127
1128 return S_OK;
1129
1130 case DISPID_GLOBAL_INVOKEVERSION:
1131 ok(wFlags == INVOKE_PROPERTYGET, "wFlags = %x\n", wFlags);
1132 ok(pdp != NULL, "pdp == NULL\n");
1133 ok(!pdp->rgvarg, "rgvarg != NULL\n");
1134 ok(!pdp->rgdispidNamedArgs, "rgdispidNamedArgs != NULL\n");
1135 ok(!pdp->cArgs, "cArgs = %d\n", pdp->cArgs);
1136 ok(!pdp->cNamedArgs, "cNamedArgs = %d\n", pdp->cNamedArgs);
1137 ok(pvarRes != NULL, "pvarRes == NULL\n");
1138 ok(V_VT(pvarRes) == VT_EMPTY, "V_VT(pvarRes) = %d\n", V_VT(pvarRes));
1139 ok(pei != NULL, "pei == NULL\n");
1140
1141 V_VT(pvarRes) = VT_I4;
1142 V_I4(pvarRes) = invoke_version;
1143
1144 return S_OK;
1145
1146 case DISPID_GLOBAL_CREATEARRAY: {
1147 SAFEARRAYBOUND bound[2];
1148 VARIANT *data;
1149 int i,j;
1150
1151 ok(wFlags == INVOKE_FUNC, "wFlags = %x\n", wFlags);
1152 ok(pdp != NULL, "pdp == NULL\n");
1153 ok(pdp->rgvarg != NULL, "rgvarg == NULL\n");
1154 ok(!pdp->rgdispidNamedArgs, "rgdispidNamedArgs != NULL\n");
1155 ok(!pdp->cArgs, "cArgs = %d\n", pdp->cArgs);
1156 ok(!pdp->cNamedArgs, "cNamedArgs = %d\n", pdp->cNamedArgs);
1157 ok(pvarRes != NULL, "pvarRes == NULL\n");
1158 ok(V_VT(pvarRes) == VT_EMPTY, "V_VT(pvarRes) = %d\n", V_VT(pvarRes));
1159 ok(pei != NULL, "pei == NULL\n");
1160
1161 bound[0].lLbound = 0;
1162 bound[0].cElements = 5;
1163 bound[1].lLbound = 2;
1164 bound[1].cElements = 2;
1165
1166 V_VT(pvarRes) = VT_ARRAY|VT_VARIANT;
1167 V_ARRAY(pvarRes) = SafeArrayCreate(VT_VARIANT, 2, bound);
1168
1169 SafeArrayAccessData(V_ARRAY(pvarRes), (void**)&data);
1170 for(i=0; i<5; i++) {
1171 for(j=2; j<4; j++) {
1172 V_VT(data) = VT_I4;
1173 V_I4(data) = i*10+j;
1174 data++;
1175 }
1176 }
1177 SafeArrayUnaccessData(V_ARRAY(pvarRes));
1178
1179 return S_OK;
1180 }
1181
1182 case DISPID_GLOBAL_PROPGETFUNC:
1183 switch(wFlags) {
1184 case INVOKE_FUNC:
1185 CHECK_EXPECT(invoke_func);
1186 break;
1187 case INVOKE_FUNC|INVOKE_PROPERTYGET:
1188 ok(pdp->cArgs != 0, "pdp->cArgs = %d\n", pdp->cArgs);
1189 ok(pvarRes != NULL, "pdp->pvarRes == NULL\n");
1190 break;
1191 default:
1192 ok(0, "invalid flag (%x)\n", wFlags);
1193 }
1194
1195 ok(pdp != NULL, "pdp == NULL\n");
1196 ok(!pdp->rgdispidNamedArgs, "rgdispidNamedArgs != NULL\n");
1197 ok(!pdp->cNamedArgs, "cNamedArgs = %d\n", pdp->cNamedArgs);
1198 ok(pei != NULL, "pei == NULL\n");
1199
1200 if(pvarRes) {
1201 ok(V_VT(pvarRes) == VT_EMPTY, "V_VT(pvarRes) = %d\n", V_VT(pvarRes));
1202 V_VT(pvarRes) = VT_I4;
1203 V_I4(pvarRes) = pdp->cArgs;
1204 }
1205
1206 return S_OK;
1207
1208 case DISPID_GLOBAL_GETSCRIPTSTATE: {
1209 SCRIPTSTATE state;
1210 HRESULT hres;
1211
1212 hres = IActiveScript_GetScriptState(script_engine, &state);
1213 ok(hres == S_OK, "GetScriptState failed: %08x\n", hres);
1214
1215 V_VT(pvarRes) = VT_I4;
1216 V_I4(pvarRes) = state;
1217 return S_OK;
1218 }
1219
1220 case DISPID_GLOBAL_BINDEVENTHANDLER:
1221 V_VT(pvarRes) = VT_DISPATCH;
1222 V_DISPATCH(pvarRes) = (IDispatch*)&bindEventHandlerDisp;
1223 return S_OK;
1224
1225 case DISPID_GLOBAL_PROPARGPUT:
1226 CHECK_EXPECT(global_propargput_i);
1227 ok(wFlags == INVOKE_PROPERTYPUT, "wFlags = %x\n", wFlags);
1228 ok(pdp != NULL, "pdp == NULL\n");
1229 ok(pdp->rgvarg != NULL, "rgvarg != NULL\n");
1230 ok(pdp->rgdispidNamedArgs != NULL, "rgdispidNamedArgs == NULL\n");
1231 ok(pdp->cArgs == 3, "cArgs = %d\n", pdp->cArgs);
1232 ok(pdp->cNamedArgs == 1, "cNamedArgs = %d\n", pdp->cNamedArgs);
1233 ok(pdp->rgdispidNamedArgs[0] == DISPID_PROPERTYPUT, "pdp->rgdispidNamedArgs[0] = %d\n", pdp->rgdispidNamedArgs[0]);
1234 ok(!pvarRes, "pvarRes != NULL\n");
1235 ok(pei != NULL, "pei == NULL\n");
1236
1237 ok(V_VT(pdp->rgvarg) == VT_I4, "V_VT(pdp->rgvarg) = %d\n", V_VT(pdp->rgvarg));
1238 ok(V_I4(pdp->rgvarg) == 2, "V_I4(pdp->rgvarg) = %d\n", V_I4(pdp->rgvarg));
1239
1240 ok(V_VT(pdp->rgvarg+1) == VT_I4, "V_VT(pdp->rgvarg+1) = %d\n", V_VT(pdp->rgvarg+1));
1241 ok(V_I4(pdp->rgvarg+1) == 1, "V_I4(pdp->rgvarg+1) = %d\n", V_I4(pdp->rgvarg+1));
1242
1243 ok(V_VT(pdp->rgvarg+2) == VT_I4, "V_VT(pdp->rgvarg+2) = %d\n", V_VT(pdp->rgvarg+2));
1244 ok(V_I4(pdp->rgvarg+2) == 0, "V_I4(pdp->rgvarg+2) = %d\n", V_I4(pdp->rgvarg+2));
1245 return S_OK;
1246
1247 case DISPID_GLOBAL_OBJECT_FLAG: {
1248 IDispatchEx *dispex;
1249 BSTR str;
1250 HRESULT hres;
1251
1252 hres = IDispatch_QueryInterface(script_disp, &IID_IDispatchEx, (void**)&dispex);
1253 ok(hres == S_OK, "hres = %x\n", hres);
1254
1255 str = a2bstr("Object");
1256 hres = IDispatchEx_GetDispID(dispex, str, fdexNameCaseSensitive, &id);
1257 SysFreeString(str);
1258 ok(hres == S_OK, "hres = %x\n", hres);
1259
1260 hres = IDispatchEx_InvokeEx(dispex, id, lcid, DISPATCH_METHOD, pdp, NULL, pei, pspCaller);
1261 ok(hres == S_OK, "hres = %x\n", hres);
1262
1263 V_VT(pvarRes) = VT_EMPTY;
1264 hres = IDispatchEx_InvokeEx(dispex, id, lcid, DISPATCH_METHOD, pdp, pvarRes, pei, pspCaller);
1265 ok(hres == S_OK, "hres = %x\n", hres);
1266 ok(V_VT(pvarRes) == VT_DISPATCH, "V_VT(pvarRes) = %d\n", V_VT(pvarRes));
1267 VariantClear(pvarRes);
1268
1269 hres = IDispatchEx_InvokeEx(dispex, id, lcid, DISPATCH_METHOD|DISPATCH_PROPERTYGET, pdp, NULL, pei, pspCaller);
1270 ok(hres == S_OK, "hres = %x\n", hres);
1271
1272 V_VT(pvarRes) = VT_EMPTY;
1273 hres = IDispatchEx_InvokeEx(dispex, id, lcid, DISPATCH_CONSTRUCT, pdp, pvarRes, pei, pspCaller);
1274 ok(hres == S_OK, "hres = %x\n", hres);
1275 ok(V_VT(pvarRes) == VT_DISPATCH, "V_VT(pvarRes) = %d\n", V_VT(pvarRes));
1276 VariantClear(pvarRes);
1277
1278 hres = IDispatchEx_InvokeEx(dispex, id, lcid, DISPATCH_CONSTRUCT, pdp, NULL, pei, pspCaller);
1279 ok(hres == S_OK, "hres = %x\n", hres);
1280
1281 V_VT(pvarRes) = VT_EMPTY;
1282 hres = IDispatchEx_InvokeEx(dispex, id, lcid, DISPATCH_CONSTRUCT|DISPATCH_PROPERTYGET, pdp, pvarRes, pei, pspCaller);
1283 ok(hres == E_INVALIDARG, "hres = %x\n", hres);
1284
1285 V_VT(pvarRes) = VT_EMPTY;
1286 hres = IDispatchEx_InvokeEx(dispex, id, lcid, wFlags, pdp, pvarRes, pei, pspCaller);
1287 ok(hres == S_OK, "hres = %x\n", hres);
1288 ok(V_VT(pvarRes) == VT_DISPATCH, "V_VT(pvarRes) = %d\n", V_VT(pvarRes));
1289 IDispatchEx_Release(dispex);
1290 return S_OK;
1291 }
1292 case DISPID_GLOBAL_SHORTPROP:
1293 case DISPID_GLOBAL_GETSHORT:
1294 V_VT(pvarRes) = VT_I2;
1295 V_I2(pvarRes) = 10;
1296 return S_OK;
1297
1298 case DISPID_GLOBAL_INTPROP:
1299 V_VT(pvarRes) = VT_INT;
1300 V_INT(pvarRes) = 22;
1301 return S_OK;
1302
1303 case DISPID_GLOBAL_DISPUNK:
1304 V_VT(pvarRes) = VT_UNKNOWN;
1305 V_UNKNOWN(pvarRes) = (IUnknown*)&testObj;
1306 return S_OK;
1307
1308 case DISPID_GLOBAL_TESTARGTYPES: {
1309 VARIANT args[6], v;
1310 DISPPARAMS dp = {args, NULL, sizeof(args)/sizeof(*args), 0};
1311 HRESULT hres;
1312
1313 CHECK_EXPECT(global_testargtypes_i);
1314 ok(wFlags == DISPATCH_METHOD, "wFlags = %x\n", wFlags);
1315 ok(pdp != NULL, "pdp == NULL\n");
1316 ok(pdp->rgvarg != NULL, "rgvarg != NULL\n");
1317 ok(pdp->cArgs == 6, "cArgs = %d\n", pdp->cArgs);
1318 ok(!pvarRes, "pvarRes != NULL\n");
1319
1320 ok(V_VT(pdp->rgvarg+1) == VT_I4, "V_VT(pdp->rgvarg+1) = %d\n", V_VT(pdp->rgvarg+1));
1321 ok(V_I4(pdp->rgvarg+1) == 10, "V_I4(pdp->rgvarg+1) = %d\n", V_I4(pdp->rgvarg+1));
1322
1323 ok(V_VT(pdp->rgvarg+2) == VT_I4, "V_VT(pdp->rgvarg+2) = %d\n", V_VT(pdp->rgvarg+2));
1324 ok(V_I4(pdp->rgvarg+2) == 10, "V_I4(pdp->rgvarg+2) = %d\n", V_I4(pdp->rgvarg+2));
1325
1326 ok(V_VT(pdp->rgvarg+3) == VT_I4, "V_VT(pdp->rgvarg+3) = %d\n", V_VT(pdp->rgvarg+3));
1327 ok(V_I4(pdp->rgvarg+3) == 22, "V_I4(pdp->rgvarg+3) = %d\n", V_I4(pdp->rgvarg+3));
1328
1329 ok(V_VT(pdp->rgvarg+4) == VT_I4, "V_VT(pdp->rgvarg+4) = %d\n", V_VT(pdp->rgvarg+4));
1330 ok(V_I4(pdp->rgvarg+4) == 22, "V_I4(pdp->rgvarg+4) = %d\n", V_I4(pdp->rgvarg+4));
1331
1332 ok(V_VT(pdp->rgvarg+5) == VT_DISPATCH, "V_VT(pdp->rgvarg+5) = %d\n", V_VT(pdp->rgvarg+5));
1333 ok(V_DISPATCH(pdp->rgvarg+5) == (IDispatch*)&testObj, "V_DISPATCH(pdp->rgvarg+5) != testObj\n");
1334
1335 ok(V_VT(pdp->rgvarg) == VT_DISPATCH, "V_VT(pdp->rgvarg) = %d\n", V_VT(pdp->rgvarg));
1336
1337 V_VT(args) = VT_I2;
1338 V_I2(args) = 2;
1339 V_VT(args+1) = VT_INT;
1340 V_INT(args+1) = 22;
1341 V_VT(args+2) = VT_UNKNOWN;
1342 V_UNKNOWN(args+2) = (IUnknown*)&testObj;
1343 V_VT(args+3) = VT_UNKNOWN;
1344 V_UNKNOWN(args+3) = NULL;
1345 V_VT(args+4) = VT_UI4;
1346 V_UI4(args+4) = 0xffffffff;
1347 V_VT(args+5) = VT_BYREF|VT_VARIANT;
1348 V_VARIANTREF(args+5) = &v;
1349 V_VT(&v) = VT_I4;
1350 V_I4(&v) = 2;
1351 hres = IDispatch_Invoke(V_DISPATCH(pdp->rgvarg), DISPID_VALUE, &IID_NULL, 0, DISPATCH_METHOD, &dp, NULL, NULL, NULL);
1352 ok(hres == S_OK, "Invoke failed: %08x\n", hres);
1353
1354 return S_OK;
1355 }
1356 }
1357
1358 ok(0, "unexpected call %x\n", id);
1359 return DISP_E_MEMBERNOTFOUND;
1360 }
1361
1362 static HRESULT WINAPI Global_DeleteMemberByDispID(IDispatchEx *iface, DISPID id)
1363 {
1364 switch(id) {
1365 case DISPID_GLOBAL_TESTPROPDELETE:
1366 CHECK_EXPECT(DeleteMemberByDispID);
1367 return S_OK;
1368 case DISPID_GLOBAL_TESTNOPROPDELETE:
1369 CHECK_EXPECT(DeleteMemberByDispID_false);
1370 return S_FALSE;
1371 default:
1372 ok(0, "id = %d\n", id);
1373 }
1374
1375 return E_FAIL;
1376 }
1377
1378 static IDispatchExVtbl GlobalVtbl = {
1379 DispatchEx_QueryInterface,
1380 DispatchEx_AddRef,
1381 DispatchEx_Release,
1382 DispatchEx_GetTypeInfoCount,
1383 DispatchEx_GetTypeInfo,
1384 DispatchEx_GetIDsOfNames,
1385 DispatchEx_Invoke,
1386 Global_GetDispID,
1387 Global_InvokeEx,
1388 DispatchEx_DeleteMemberByName,
1389 Global_DeleteMemberByDispID,
1390 DispatchEx_GetMemberProperties,
1391 DispatchEx_GetMemberName,
1392 DispatchEx_GetNextDispID,
1393 DispatchEx_GetNameSpaceParent
1394 };
1395
1396 static IDispatchEx Global = { &GlobalVtbl };
1397
1398 static HRESULT WINAPI ActiveScriptSite_QueryInterface(IActiveScriptSite *iface, REFIID riid, void **ppv)
1399 {
1400 *ppv = NULL;
1401
1402 if(IsEqualGUID(&IID_IUnknown, riid))
1403 *ppv = iface;
1404 else if(IsEqualGUID(&IID_IActiveScriptSite, riid))
1405 *ppv = iface;
1406 else
1407 return E_NOINTERFACE;
1408
1409 IUnknown_AddRef((IUnknown*)*ppv);
1410 return S_OK;
1411 }
1412
1413 static ULONG WINAPI ActiveScriptSite_AddRef(IActiveScriptSite *iface)
1414 {
1415 return 2;
1416 }
1417
1418 static ULONG WINAPI ActiveScriptSite_Release(IActiveScriptSite *iface)
1419 {
1420 return 1;
1421 }
1422
1423 static HRESULT WINAPI ActiveScriptSite_GetLCID(IActiveScriptSite *iface, LCID *plcid)
1424 {
1425 *plcid = GetUserDefaultLCID();
1426 return S_OK;
1427 }
1428
1429 static HRESULT WINAPI ActiveScriptSite_GetItemInfo(IActiveScriptSite *iface, LPCOLESTR pstrName,
1430 DWORD dwReturnMask, IUnknown **ppiunkItem, ITypeInfo **ppti)
1431 {
1432 ok(dwReturnMask == SCRIPTINFO_IUNKNOWN, "unexpected dwReturnMask %x\n", dwReturnMask);
1433 ok(!ppti, "ppti != NULL\n");
1434
1435 if(!strcmp_wa(pstrName, test_valA))
1436 CHECK_EXPECT(GetItemInfo_testVal);
1437 else if(strcmp_wa(pstrName, testA))
1438 ok(0, "unexpected pstrName %s\n", wine_dbgstr_w(pstrName));
1439
1440 *ppiunkItem = (IUnknown*)&Global;
1441 return S_OK;
1442 }
1443
1444 static HRESULT WINAPI ActiveScriptSite_GetDocVersionString(IActiveScriptSite *iface, BSTR *pbstrVersion)
1445 {
1446 return E_NOTIMPL;
1447 }
1448
1449 static HRESULT WINAPI ActiveScriptSite_OnScriptTerminate(IActiveScriptSite *iface,
1450 const VARIANT *pvarResult, const EXCEPINFO *pexcepinfo)
1451 {
1452 return E_NOTIMPL;
1453 }
1454
1455 static HRESULT WINAPI ActiveScriptSite_OnStateChange(IActiveScriptSite *iface, SCRIPTSTATE ssScriptState)
1456 {
1457 return E_NOTIMPL;
1458 }
1459
1460 static HRESULT WINAPI ActiveScriptSite_OnScriptError(IActiveScriptSite *iface, IActiveScriptError *pscripterror)
1461 {
1462 return E_NOTIMPL;
1463 }
1464
1465 static HRESULT WINAPI ActiveScriptSite_OnEnterScript(IActiveScriptSite *iface)
1466 {
1467 return E_NOTIMPL;
1468 }
1469
1470 static HRESULT WINAPI ActiveScriptSite_OnLeaveScript(IActiveScriptSite *iface)
1471 {
1472 return E_NOTIMPL;
1473 }
1474
1475 #undef ACTSCPSITE_THIS
1476
1477 static const IActiveScriptSiteVtbl ActiveScriptSiteVtbl = {
1478 ActiveScriptSite_QueryInterface,
1479 ActiveScriptSite_AddRef,
1480 ActiveScriptSite_Release,
1481 ActiveScriptSite_GetLCID,
1482 ActiveScriptSite_GetItemInfo,
1483 ActiveScriptSite_GetDocVersionString,
1484 ActiveScriptSite_OnScriptTerminate,
1485 ActiveScriptSite_OnStateChange,
1486 ActiveScriptSite_OnScriptError,
1487 ActiveScriptSite_OnEnterScript,
1488 ActiveScriptSite_OnLeaveScript
1489 };
1490
1491 static IActiveScriptSite ActiveScriptSite = { &ActiveScriptSiteVtbl };
1492
1493 static HRESULT WINAPI ActiveScriptSite_OnScriptError_CheckError(IActiveScriptSite *iface, IActiveScriptError *pscripterror)
1494 {
1495 ok(pscripterror != NULL, "ActiveScriptSite_OnScriptError -- expected pscripterror to be set, got NULL\n");
1496
1497 script_error = pscripterror;
1498 IActiveScriptError_AddRef(script_error);
1499
1500 CHECK_EXPECT(ActiveScriptSite_OnScriptError);
1501
1502 return S_OK;
1503 }
1504
1505 static const IActiveScriptSiteVtbl ActiveScriptSite_CheckErrorVtbl = {
1506 ActiveScriptSite_QueryInterface,
1507 ActiveScriptSite_AddRef,
1508 ActiveScriptSite_Release,
1509 ActiveScriptSite_GetLCID,
1510 ActiveScriptSite_GetItemInfo,
1511 ActiveScriptSite_GetDocVersionString,
1512 ActiveScriptSite_OnScriptTerminate,
1513 ActiveScriptSite_OnStateChange,
1514 ActiveScriptSite_OnScriptError_CheckError,
1515 ActiveScriptSite_OnEnterScript,
1516 ActiveScriptSite_OnLeaveScript
1517 };
1518
1519 static IActiveScriptSite ActiveScriptSite_CheckError = { &ActiveScriptSite_CheckErrorVtbl };
1520
1521 static HRESULT set_script_prop(IActiveScript *engine, DWORD property, VARIANT *val)
1522 {
1523 IActiveScriptProperty *script_prop;
1524 HRESULT hres;
1525
1526 hres = IActiveScript_QueryInterface(engine, &IID_IActiveScriptProperty,
1527 (void**)&script_prop);
1528 ok(hres == S_OK, "Could not get IActiveScriptProperty iface: %08x\n", hres);
1529
1530 hres = IActiveScriptProperty_SetProperty(script_prop, property, NULL, val);
1531 IActiveScriptProperty_Release(script_prop);
1532
1533 return hres;
1534 }
1535
1536 static IActiveScript *create_script(void)
1537 {
1538 IActiveScript *script;
1539 VARIANT v;
1540 HRESULT hres;
1541
1542 hres = CoCreateInstance(engine_clsid, NULL, CLSCTX_INPROC_SERVER|CLSCTX_INPROC_HANDLER,
1543 &IID_IActiveScript, (void**)&script);
1544 ok(hres == S_OK, "CoCreateInstance failed: %08x\n", hres);
1545
1546 V_VT(&v) = VT_I4;
1547 V_I4(&v) = invoke_version;
1548 hres = set_script_prop(script, SCRIPTPROP_INVOKEVERSIONING, &v);
1549 ok(hres == S_OK || broken(hres == E_NOTIMPL), "SetProperty(SCRIPTPROP_INVOKEVERSIONING) failed: %08x\n", hres);
1550 if(invoke_version && FAILED(hres)) {
1551 IActiveScript_Release(script);
1552 return NULL;
1553 }
1554
1555 return script;
1556 }
1557
1558 static HRESULT parse_script(DWORD flags, BSTR script_str)
1559 {
1560 IActiveScriptParse *parser;
1561 IActiveScript *engine;
1562 HRESULT hres;
1563
1564 engine = create_script();
1565 if(!engine)
1566 return S_OK;
1567
1568 hres = IActiveScript_QueryInterface(engine, &IID_IActiveScriptParse, (void**)&parser);
1569 ok(hres == S_OK, "Could not get IActiveScriptParse: %08x\n", hres);
1570 if (FAILED(hres))
1571 {
1572 IActiveScript_Release(engine);
1573 return hres;
1574 }
1575
1576 hres = IActiveScriptParse_InitNew(parser);
1577 ok(hres == S_OK, "InitNew failed: %08x\n", hres);
1578
1579 hres = IActiveScript_SetScriptSite(engine, &ActiveScriptSite);
1580 ok(hres == S_OK, "SetScriptSite failed: %08x\n", hres);
1581
1582 hres = IActiveScript_AddNamedItem(engine, testW,
1583 SCRIPTITEM_ISVISIBLE|SCRIPTITEM_ISSOURCE|flags);
1584 ok(hres == S_OK, "AddNamedItem failed: %08x\n", hres);
1585
1586 hres = IActiveScript_SetScriptState(engine, SCRIPTSTATE_STARTED);
1587 ok(hres == S_OK, "SetScriptState(SCRIPTSTATE_STARTED) failed: %08x\n", hres);
1588
1589 hres = IActiveScript_GetScriptDispatch(engine, NULL, &script_disp);
1590 ok(hres == S_OK, "GetScriptDispatch failed: %08x\n", hres);
1591 ok(script_disp != NULL, "script_disp == NULL\n");
1592 ok(script_disp != (IDispatch*)&Global, "script_disp == Global\n");
1593
1594 hres = IActiveScriptParse_ParseScriptText(parser, script_str, NULL, NULL, NULL, 0, 0, 0, NULL, NULL);
1595
1596 IDispatch_Release(script_disp);
1597 IActiveScript_Release(engine);
1598 IActiveScriptParse_Release(parser);
1599
1600 return hres;
1601 }
1602
1603 static HRESULT invoke_procedure(const char *argsa, const char *sourcea, DISPPARAMS *dp)
1604 {
1605 IActiveScriptParseProcedure2 *parse_proc;
1606 IActiveScriptParse *parser;
1607 IActiveScript *engine;
1608 IDispatchEx *dispex;
1609 EXCEPINFO ei = {0};
1610 BSTR source, args;
1611 IDispatch *disp;
1612 VARIANT res;
1613 HRESULT hres;
1614
1615 engine = create_script();
1616 if(!engine)
1617 return S_OK;
1618
1619 hres = IActiveScript_QueryInterface(engine, &IID_IActiveScriptParse, (void**)&parser);
1620 ok(hres == S_OK, "Could not get IActiveScriptParse: %08x\n", hres);
1621
1622 hres = IActiveScriptParse_InitNew(parser);
1623 ok(hres == S_OK, "InitNew failed: %08x\n", hres);
1624
1625 hres = IActiveScript_SetScriptSite(engine, &ActiveScriptSite);
1626 ok(hres == S_OK, "SetScriptSite failed: %08x\n", hres);
1627
1628 hres = IActiveScript_SetScriptState(engine, SCRIPTSTATE_STARTED);
1629 ok(hres == S_OK, "SetScriptState(SCRIPTSTATE_STARTED) failed: %08x\n", hres);
1630
1631 hres = IActiveScript_QueryInterface(engine, &IID_IActiveScriptParseProcedure2, (void**)&parse_proc);
1632 ok(hres == S_OK, "Could not get IActiveScriptParse: %08x\n", hres);
1633
1634 source = a2bstr(sourcea);
1635 args = argsa ? a2bstr(argsa) : NULL;
1636 hres = IActiveScriptParseProcedure2_ParseProcedureText(parse_proc, source, args, emptyW, NULL, NULL, NULL, 0, 0,
1637 SCRIPTPROC_HOSTMANAGESSOURCE|SCRIPTPROC_IMPLICIT_THIS|SCRIPTPROC_IMPLICIT_PARENTS, &disp);
1638 ok(hres == S_OK, "ParseProcedureText failed: %08x\n", hres);
1639 SysFreeString(source);
1640 SysFreeString(args);
1641
1642 hres = IDispatch_QueryInterface(disp, &IID_IDispatchEx, (void**)&dispex);
1643 ok(hres == S_OK, "Could not get IDispatchEx iface: %08x\n", hres);
1644 IDispatch_Release(disp);
1645
1646 V_VT(&res) = VT_EMPTY;
1647 hres = IDispatchEx_InvokeEx(dispex, DISPID_VALUE, 0, DISPATCH_METHOD, dp, &res, &ei, NULL);
1648 ok(hres == S_OK, "InvokeEx failed: %08x\n", hres);
1649 ok(V_VT(&res) == VT_BOOL && V_BOOL(&res), "InvokeEx returned vt %d (%x)\n", V_VT(&res), V_I4(&res));
1650 IDispatchEx_Release(dispex);
1651
1652 IActiveScriptParseProcedure2_Release(parse_proc);
1653 IActiveScript_Release(engine);
1654 IActiveScriptParse_Release(parser);
1655
1656 return hres;
1657 }
1658
1659 static HRESULT parse_htmlscript(BSTR script_str)
1660 {
1661 IActiveScriptParse *parser;
1662 IActiveScript *engine;
1663 HRESULT hres;
1664 BSTR tmp = a2bstr("</SCRIPT>");
1665
1666 engine = create_script();
1667 if(!engine)
1668 return E_FAIL;
1669
1670 hres = IActiveScript_QueryInterface(engine, &IID_IActiveScriptParse, (void**)&parser);
1671 ok(hres == S_OK, "Could not get IActiveScriptParse: %08x\n", hres);
1672 if (FAILED(hres))
1673 {
1674 IActiveScript_Release(engine);
1675 return E_FAIL;
1676 }
1677
1678 hres = IActiveScriptParse_InitNew(parser);
1679 ok(hres == S_OK, "InitNew failed: %08x\n", hres);
1680
1681 hres = IActiveScript_SetScriptSite(engine, &ActiveScriptSite);
1682 ok(hres == S_OK, "SetScriptSite failed: %08x\n", hres);
1683
1684 hres = IActiveScript_AddNamedItem(engine, testW,
1685 SCRIPTITEM_ISVISIBLE|SCRIPTITEM_ISSOURCE|SCRIPTITEM_GLOBALMEMBERS);
1686 ok(hres == S_OK, "AddNamedItem failed: %08x\n", hres);
1687
1688 hres = IActiveScript_SetScriptState(engine, SCRIPTSTATE_STARTED);
1689 ok(hres == S_OK, "SetScriptState(SCRIPTSTATE_STARTED) failed: %08x\n", hres);
1690
1691 hres = IActiveScriptParse_ParseScriptText(parser, script_str, NULL, NULL, tmp, 0, 0, 0, NULL, NULL);
1692
1693 IActiveScript_Release(engine);
1694 IActiveScriptParse_Release(parser);
1695 SysFreeString(tmp);
1696
1697 return hres;
1698 }
1699
1700 static void test_IActiveScriptError(IActiveScriptError *error, SCODE errorcode, ULONG line, LONG pos, BSTR script_source, BSTR description, BSTR line_text)
1701 {
1702 HRESULT hres;
1703 DWORD source_context;
1704 ULONG line_number;
1705 LONG char_position;
1706 BSTR linetext;
1707 EXCEPINFO excep;
1708
1709 /* IActiveScriptError_GetSourcePosition */
1710
1711 hres = IActiveScriptError_GetSourcePosition(error, NULL, NULL, NULL);
1712 ok(hres == S_OK, "IActiveScriptError_GetSourcePosition -- hres: expected S_OK, got 0x%08x\n", hres);
1713
1714 source_context = 0xdeadbeef;
1715 hres = IActiveScriptError_GetSourcePosition(error, &source_context, NULL, NULL);
1716 ok(hres == S_OK, "IActiveScriptError_GetSourcePosition -- hres: expected S_OK, got 0x%08x\n", hres);
1717 ok(source_context == 0, "IActiveScriptError_GetSourcePosition -- source_context: expected 0, got 0x%08x\n", source_context);
1718
1719 line_number = 0xdeadbeef;
1720 hres = IActiveScriptError_GetSourcePosition(error, NULL, &line_number, NULL);
1721 ok(hres == S_OK, "IActiveScriptError_GetSourcePosition -- hres: expected S_OK, got 0x%08x\n", hres);
1722 ok(line_number == line, "IActiveScriptError_GetSourcePosition -- line_number: expected %d, got %d\n", line, line_number);
1723
1724 char_position = 0xdeadbeef;
1725 hres = IActiveScriptError_GetSourcePosition(error, NULL, NULL, &char_position);
1726 ok(hres == S_OK, "IActiveScriptError_GetSourcePosition -- hres: expected S_OK, got 0x%08x\n", hres);
1727 ok(char_position == pos, "IActiveScriptError_GetSourcePosition -- char_position: expected %d, got %d\n", pos, char_position);
1728
1729 /* IActiveScriptError_GetSourceLineText */
1730
1731 hres = IActiveScriptError_GetSourceLineText(error, NULL);
1732 ok(hres == E_POINTER, "IActiveScriptError_GetSourceLineText -- hres: expected E_POINTER, got 0x%08x\n", hres);
1733
1734 linetext = NULL;
1735 hres = IActiveScriptError_GetSourceLineText(error, &linetext);
1736 if (line_text) {
1737 ok(hres == S_OK, "IActiveScriptError_GetSourceLineText -- hres: expected S_OK, got 0x%08x\n", hres);
1738 ok(linetext != NULL && !lstrcmpW(linetext, line_text),
1739 "IActiveScriptError_GetSourceLineText -- expected %s, got %s\n", wine_dbgstr_w(line_text), wine_dbgstr_w(linetext));
1740 } else {
1741 ok(hres == E_FAIL, "IActiveScriptError_GetSourceLineText -- hres: expected S_OK, got 0x%08x\n", hres);
1742 ok(linetext == NULL,
1743 "IActiveScriptError_GetSourceLineText -- expected NULL, got %s\n", wine_dbgstr_w(linetext));
1744 }
1745 SysFreeString(linetext);
1746
1747 /* IActiveScriptError_GetExceptionInfo */
1748
1749 hres = IActiveScriptError_GetExceptionInfo(error, NULL);
1750 ok(hres == E_POINTER, "IActiveScriptError_GetExceptionInfo -- hres: expected E_POINTER, got 0x%08x\n", hres);
1751
1752 excep.wCode = 0xdead;
1753 excep.wReserved = 0xdead;
1754 excep.bstrSource = (BSTR)0xdeadbeef;
1755 excep.bstrDescription = (BSTR)0xdeadbeef;
1756 excep.bstrHelpFile = (BSTR)0xdeadbeef;
1757 excep.dwHelpContext = 0xdeadbeef;
1758 excep.pvReserved = (void *)0xdeadbeef;
1759 excep.pfnDeferredFillIn = (void *)0xdeadbeef;
1760 excep.scode = 0xdeadbeef;
1761
1762 hres = IActiveScriptError_GetExceptionInfo(error, &excep);
1763 ok(hres == S_OK, "IActiveScriptError_GetExceptionInfo -- hres: expected S_OK, got 0x%08x\n", hres);
1764
1765 ok(excep.wCode == 0, "IActiveScriptError_GetExceptionInfo -- excep.wCode: expected 0, got 0x%08x\n", excep.wCode);
1766 ok(excep.wReserved == 0, "IActiveScriptError_GetExceptionInfo -- excep.wReserved: expected 0, got %d\n", excep.wReserved);
1767 if (!is_lang_english())
1768 skip("Non-english UI (test with hardcoded strings)\n");
1769 else {
1770 ok(excep.bstrSource != NULL && !lstrcmpW(excep.bstrSource, script_source),
1771 "IActiveScriptError_GetExceptionInfo -- excep.bstrSource is not valid: expected %s, got %s\n",
1772 wine_dbgstr_w(script_source), wine_dbgstr_w(excep.bstrSource));
1773 ok(excep.bstrDescription != NULL && !lstrcmpW(excep.bstrDescription, description),
1774 "IActiveScriptError_GetExceptionInfo -- excep.bstrDescription is not valid: got %s\n", wine_dbgstr_w(excep.bstrDescription));
1775 }
1776 ok(excep.bstrHelpFile == NULL,
1777 "IActiveScriptError_GetExceptionInfo -- excep.bstrHelpFile: expected NULL, got %s\n", wine_dbgstr_w(excep.bstrHelpFile));
1778 ok(excep.dwHelpContext == 0, "IActiveScriptError_GetExceptionInfo -- excep.dwHelpContext: expected 0, got %d\n", excep.dwHelpContext);
1779 ok(excep.pvReserved == NULL, "IActiveScriptError_GetExceptionInfo -- excep.pvReserved: expected NULL, got %p\n", excep.pvReserved);
1780 ok(excep.pfnDeferredFillIn == NULL, "IActiveScriptError_GetExceptionInfo -- excep.pfnDeferredFillIn: expected NULL, got %p\n", excep.pfnDeferredFillIn);
1781 ok(excep.scode == errorcode, "IActiveScriptError_GetExceptionInfo -- excep.scode: expected 0x%08x, got 0x%08x\n", errorcode, excep.scode);
1782
1783 SysFreeString(excep.bstrSource);
1784 SysFreeString(excep.bstrDescription);
1785 SysFreeString(excep.bstrHelpFile);
1786 }
1787
1788 static void parse_script_with_error(DWORD flags, BSTR script_str, SCODE errorcode, ULONG line, LONG pos, BSTR script_source, BSTR description, BSTR line_text)
1789 {
1790 IActiveScriptParse *parser;
1791 IActiveScript *engine;
1792 HRESULT hres;
1793
1794 engine = create_script();
1795 if(!engine)
1796 return;
1797
1798 hres = IActiveScript_QueryInterface(engine, &IID_IActiveScriptParse, (void**)&parser);
1799 ok(hres == S_OK, "Could not get IActiveScriptParse: %08x\n", hres);
1800 if (FAILED(hres))
1801 {
1802 IActiveScript_Release(engine);
1803 return;
1804 }
1805
1806 hres = IActiveScriptParse_InitNew(parser);
1807 ok(hres == S_OK, "InitNew failed: %08x\n", hres);
1808
1809 hres = IActiveScript_SetScriptSite(engine, &ActiveScriptSite_CheckError);
1810 ok(hres == S_OK, "SetScriptSite failed: %08x\n", hres);
1811
1812 hres = IActiveScript_AddNamedItem(engine, testW,
1813 SCRIPTITEM_ISVISIBLE|SCRIPTITEM_ISSOURCE|flags);
1814 ok(hres == S_OK, "AddNamedItem failed: %08x\n", hres);
1815
1816 hres = IActiveScript_SetScriptState(engine, SCRIPTSTATE_STARTED);
1817 ok(hres == S_OK, "SetScriptState(SCRIPTSTATE_STARTED) failed: %08x\n", hres);
1818
1819 hres = IActiveScript_GetScriptDispatch(engine, NULL, &script_disp);
1820 ok(hres == S_OK, "GetScriptDispatch failed: %08x\n", hres);
1821 ok(script_disp != NULL, "script_disp == NULL\n");
1822 ok(script_disp != (IDispatch*)&Global, "script_disp == Global\n");
1823
1824 script_error = NULL;
1825 SET_EXPECT(ActiveScriptSite_OnScriptError);
1826 hres = IActiveScriptParse_ParseScriptText(parser, script_str, NULL, NULL, NULL, 0, 0, 0, NULL, NULL);
1827 todo_wine ok(hres == 0x80020101, "parse_script_with_error should have returned 0x80020101, got: 0x%08x\n", hres);
1828 todo_wine CHECK_CALLED(ActiveScriptSite_OnScriptError);
1829
1830 if (script_error)
1831 {
1832 test_IActiveScriptError(script_error, errorcode, line, pos, script_source, description, line_text);
1833
1834 IActiveScriptError_Release(script_error);
1835 }
1836
1837 IDispatch_Release(script_disp);
1838 IActiveScript_Release(engine);
1839 IActiveScriptParse_Release(parser);
1840 }
1841
1842 static void parse_script_af(DWORD flags, const char *src)
1843 {
1844 BSTR tmp;
1845 HRESULT hres;
1846
1847 tmp = a2bstr(src);
1848 hres = parse_script(flags, tmp);
1849 SysFreeString(tmp);
1850 ok(hres == S_OK, "parse_script failed: %08x\n", hres);
1851 }
1852
1853 static void parse_script_a(const char *src)
1854 {
1855 parse_script_af(SCRIPTITEM_GLOBALMEMBERS, src);
1856 }
1857
1858 static void parse_script_with_error_a(const char *src, SCODE errorcode, ULONG line, LONG pos, LPCSTR source, LPCSTR desc, LPCSTR linetext)
1859 {
1860 BSTR tmp, script_source, description, line_text;
1861
1862 tmp = a2bstr(src);
1863 script_source = a2bstr(source);
1864 description = a2bstr(desc);
1865 line_text = a2bstr(linetext);
1866
1867 parse_script_with_error(SCRIPTITEM_GLOBALMEMBERS, tmp, errorcode, line, pos, script_source, description, line_text);
1868
1869 SysFreeString(line_text);
1870 SysFreeString(description);
1871 SysFreeString(script_source);
1872 SysFreeString(tmp);
1873 }
1874
1875 static HRESULT parse_htmlscript_a(const char *src)
1876 {
1877 HRESULT hres;
1878 BSTR tmp = a2bstr(src);
1879 hres = parse_htmlscript(tmp);
1880 SysFreeString(tmp);
1881
1882 return hres;
1883 }
1884
1885 static BSTR get_script_from_file(const char *filename)
1886 {
1887 DWORD size, len;
1888 HANDLE file, map;
1889 const char *file_map;
1890 BSTR ret;
1891
1892 file = CreateFileA(filename, GENERIC_READ, 0, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_READONLY, NULL);
1893 if(file == INVALID_HANDLE_VALUE) {
1894 trace("Could not open file: %u\n", GetLastError());
1895 return NULL;
1896 }
1897
1898 size = GetFileSize(file, NULL);
1899
1900 map = CreateFileMappingW(file, NULL, PAGE_READONLY, 0, 0, NULL);
1901 CloseHandle(file);
1902 if(map == INVALID_HANDLE_VALUE) {
1903 trace("Could not create file mapping: %u\n", GetLastError());
1904 return NULL;
1905 }
1906
1907 file_map = MapViewOfFile(map, FILE_MAP_READ, 0, 0, 0);
1908 CloseHandle(map);
1909 if(!file_map) {
1910 trace("MapViewOfFile failed: %u\n", GetLastError());
1911 return NULL;
1912 }
1913
1914 len = MultiByteToWideChar(CP_ACP, 0, file_map, size, NULL, 0);
1915 ret = SysAllocStringLen(NULL, len);
1916 MultiByteToWideChar(CP_ACP, 0, file_map, size, ret, len);
1917
1918 UnmapViewOfFile(file_map);
1919
1920 return ret;
1921 }
1922
1923 static void run_from_file(const char *filename)
1924 {
1925 BSTR script_str;
1926 HRESULT hres;
1927
1928 script_str = get_script_from_file(filename);
1929 if(!script_str)
1930 return;
1931
1932 strict_dispid_check = FALSE;
1933 hres = parse_script(SCRIPTITEM_GLOBALMEMBERS, script_str);
1934 SysFreeString(script_str);
1935 ok(hres == S_OK, "parse_script failed: %08x\n", hres);
1936 }
1937
1938 static BSTR load_res(const char *name)
1939 {
1940 const char *data;
1941 DWORD size, len;
1942 BSTR str;
1943 HRSRC src;
1944
1945 strict_dispid_check = FALSE;
1946 test_name = name;
1947
1948 src = FindResourceA(NULL, name, (LPCSTR)40);
1949 ok(src != NULL, "Could not find resource %s\n", name);
1950
1951 size = SizeofResource(NULL, src);
1952 data = LoadResource(NULL, src);
1953
1954 len = MultiByteToWideChar(CP_ACP, 0, data, size, NULL, 0);
1955 str = SysAllocStringLen(NULL, len);
1956 MultiByteToWideChar(CP_ACP, 0, data, size, str, len);
1957
1958 return str;
1959 }
1960
1961 static void run_from_res(const char *name)
1962 {
1963 BSTR str;
1964 HRESULT hres;
1965
1966 str = load_res(name);
1967
1968 SET_EXPECT(global_success_d);
1969 SET_EXPECT(global_success_i);
1970 hres = parse_script(SCRIPTITEM_GLOBALMEMBERS, str);
1971 CHECK_CALLED(global_success_d);
1972 CHECK_CALLED(global_success_i);
1973
1974 ok(hres == S_OK, "parse_script failed: %08x\n", hres);
1975 SysFreeString(str);
1976 }
1977
1978 static void test_isvisible(BOOL global_members)
1979 {
1980 IActiveScriptParse *parser;
1981 IActiveScript *engine;
1982 HRESULT hres;
1983
1984 static const WCHAR script_textW[] =
1985 {'v','a','r',' ','v',' ','=',' ','t','e','s','t','V','a','l',';',0};
1986
1987 engine = create_script();
1988 if(!engine)
1989 return;
1990
1991 hres = IActiveScript_QueryInterface(engine, &IID_IActiveScriptParse, (void**)&parser);
1992 ok(hres == S_OK, "Could not get IActiveScriptParse: %08x\n", hres);
1993 if (FAILED(hres))
1994 {
1995 IActiveScript_Release(engine);
1996 return;
1997 }
1998
1999 hres = IActiveScriptParse_InitNew(parser);
2000 ok(hres == S_OK, "InitNew failed: %08x\n", hres);
2001
2002 hres = IActiveScript_SetScriptSite(engine, &ActiveScriptSite);
2003 ok(hres == S_OK, "SetScriptSite failed: %08x\n", hres);
2004
2005 if(global_members)
2006 SET_EXPECT(GetItemInfo_testVal);
2007 hres = IActiveScript_AddNamedItem(engine, test_valW,
2008 SCRIPTITEM_ISVISIBLE|SCRIPTITEM_ISSOURCE|
2009 (global_members ? SCRIPTITEM_GLOBALMEMBERS : 0));
2010 ok(hres == S_OK, "AddNamedItem failed: %08x\n", hres);
2011 if(global_members)
2012 CHECK_CALLED(GetItemInfo_testVal);
2013
2014 hres = IActiveScript_SetScriptState(engine, SCRIPTSTATE_STARTED);
2015 ok(hres == S_OK, "SetScriptState(SCRIPTSTATE_STARTED) failed: %08x\n", hres);
2016
2017 if(!global_members)
2018 SET_EXPECT(GetItemInfo_testVal);
2019 hres = IActiveScriptParse_ParseScriptText(parser, script_textW, NULL, NULL, NULL, 0, 0, 0, NULL, NULL);
2020 ok(hres == S_OK, "ParseScriptText failed: %08x\n", hres);
2021 if(!global_members)
2022 CHECK_CALLED(GetItemInfo_testVal);
2023
2024 hres = IActiveScriptParse_ParseScriptText(parser, script_textW, NULL, NULL, NULL, 0, 0, 0, NULL, NULL);
2025 ok(hres == S_OK, "ParseScriptText failed: %08x\n", hres);
2026
2027 IActiveScript_Release(engine);
2028 IActiveScriptParse_Release(parser);
2029 }
2030
2031 static void test_start(void)
2032 {
2033 IActiveScriptParse *parser;
2034 IActiveScript *engine;
2035 BSTR str;
2036 HRESULT hres;
2037
2038 script_engine = engine = create_script();
2039 if(!engine)
2040 return;
2041
2042 hres = IActiveScript_QueryInterface(engine, &IID_IActiveScriptParse, (void**)&parser);
2043 ok(hres == S_OK, "Could not get IActiveScriptParse: %08x\n", hres);
2044
2045 hres = IActiveScriptParse_InitNew(parser);
2046 ok(hres == S_OK, "InitNew failed: %08x\n", hres);
2047
2048 hres = IActiveScript_SetScriptSite(engine, &ActiveScriptSite);
2049 ok(hres == S_OK, "SetScriptSite failed: %08x\n", hres);
2050
2051 hres = IActiveScript_AddNamedItem(engine, testW, SCRIPTITEM_ISVISIBLE|SCRIPTITEM_ISSOURCE|SCRIPTITEM_GLOBALMEMBERS);
2052 ok(hres == S_OK, "AddNamedItem failed: %08x\n", hres);
2053
2054 str = a2bstr("ok(getScriptState() === 5, \"getScriptState = \" + getScriptState());\n"
2055 "reportSuccess();");
2056 hres = IActiveScriptParse_ParseScriptText(parser, str, NULL, NULL, NULL, 0, 0, 0, NULL, NULL);
2057 ok(hres == S_OK, "ParseScriptText failed: %08x\n", hres);
2058 SysFreeString(str);
2059
2060 SET_EXPECT(global_success_d);
2061 SET_EXPECT(global_success_i);
2062 hres = IActiveScript_SetScriptState(engine, SCRIPTSTATE_STARTED);
2063 ok(hres == S_OK, "SetScriptState(SCRIPTSTATE_STARTED) failed: %08x\n", hres);
2064 CHECK_CALLED(global_success_d);
2065 CHECK_CALLED(global_success_i);
2066
2067 IActiveScript_Release(engine);
2068 IActiveScriptParse_Release(parser);
2069 script_engine = NULL;
2070 }
2071
2072 static void test_automagic(void)
2073 {
2074 IActiveScriptParse *parser;
2075 IActiveScript *engine;
2076 BSTR str;
2077 HRESULT hres;
2078
2079 script_engine = engine = create_script();
2080 if(!engine)
2081 return;
2082
2083 hres = IActiveScript_QueryInterface(engine, &IID_IActiveScriptParse, (void**)&parser);
2084 ok(hres == S_OK, "Could not get IActiveScriptParse: %08x\n", hres);
2085
2086 hres = IActiveScriptParse_InitNew(parser);
2087 ok(hres == S_OK, "InitNew failed: %08x\n", hres);
2088
2089 hres = IActiveScript_SetScriptSite(engine, &ActiveScriptSite);
2090 ok(hres == S_OK, "SetScriptSite failed: %08x\n", hres);
2091
2092 hres = IActiveScript_AddNamedItem(engine, testW, SCRIPTITEM_ISVISIBLE|SCRIPTITEM_ISSOURCE|SCRIPTITEM_GLOBALMEMBERS);
2093 ok(hres == S_OK, "AddNamedItem failed: %08x\n", hres);
2094
2095 str = a2bstr("function bindEventHandler::eventName() {}\n"
2096 "reportSuccess();");
2097 hres = IActiveScriptParse_ParseScriptText(parser, str, NULL, NULL, NULL, 0, 0, 0, NULL, NULL);
2098 ok(hres == S_OK, "ParseScriptText failed: %08x\n", hres);
2099 SysFreeString(str);
2100
2101 SET_EXPECT(BindHandler);
2102 SET_EXPECT(global_success_d);
2103 SET_EXPECT(global_success_i);
2104 hres = IActiveScript_SetScriptState(engine, SCRIPTSTATE_STARTED);
2105 ok(hres == S_OK, "SetScriptState(SCRIPTSTATE_STARTED) failed: %08x\n", hres);
2106 CHECK_CALLED(BindHandler);
2107 CHECK_CALLED(global_success_d);
2108 CHECK_CALLED(global_success_i);
2109
2110 IActiveScript_Release(engine);
2111 IActiveScriptParse_Release(parser);
2112 script_engine = NULL;
2113 }
2114
2115 static HRESULT parse_script_expr(const char *expr, VARIANT *res, IActiveScript **engine_ret)
2116 {
2117 IActiveScriptParse *parser;
2118 IActiveScript *engine;
2119 BSTR str;
2120 HRESULT hres;
2121
2122 engine = create_script();
2123
2124 hres = IActiveScript_QueryInterface(engine, &IID_IActiveScriptParse, (void**)&parser);
2125 ok(hres == S_OK, "Could not get IActiveScriptParse: %08x\n", hres);
2126
2127 hres = IActiveScriptParse_InitNew(parser);
2128 ok(hres == S_OK, "InitNew failed: %08x\n", hres);
2129
2130 hres = IActiveScript_SetScriptSite(engine, &ActiveScriptSite);
2131 ok(hres == S_OK, "SetScriptSite failed: %08x\n", hres);
2132
2133 SET_EXPECT(GetItemInfo_testVal);
2134 hres = IActiveScript_AddNamedItem(engine, test_valW,
2135 SCRIPTITEM_ISVISIBLE|SCRIPTITEM_ISSOURCE|SCRIPTITEM_GLOBALMEMBERS);
2136 ok(hres == S_OK, "AddNamedItem failed: %08x\n", hres);
2137 CHECK_CALLED(GetItemInfo_testVal);
2138
2139 hres = IActiveScript_SetScriptState(engine, SCRIPTSTATE_STARTED);
2140 ok(hres == S_OK, "SetScriptState(SCRIPTSTATE_STARTED) failed: %08x\n", hres);
2141
2142 str = a2bstr(expr);
2143 hres = IActiveScriptParse_ParseScriptText(parser, str, NULL, NULL, NULL, 0, 0, SCRIPTTEXT_ISEXPRESSION, res, NULL);
2144 SysFreeString(str);
2145
2146 IActiveScriptParse_Release(parser);
2147
2148 if(engine_ret) {
2149 *engine_ret = engine;
2150 }else {
2151 IActiveScript_Close(engine);
2152 IActiveScript_Release(engine);
2153 }
2154 return hres;
2155 }
2156
2157 static void test_retval(void)
2158 {
2159 BSTR str = a2bstr("reportSuccess(), true");
2160 IActiveScriptParse *parser;
2161 IActiveScript *engine;
2162 SCRIPTSTATE state;
2163 VARIANT res;
2164 HRESULT hres;
2165
2166 engine = create_script();
2167
2168 hres = IActiveScript_QueryInterface(engine, &IID_IActiveScriptParse, (void**)&parser);
2169 ok(hres == S_OK, "Could not get IActiveScriptParse: %08x\n", hres);
2170
2171 hres = IActiveScriptParse_InitNew(parser);
2172 ok(hres == S_OK, "InitNew failed: %08x\n", hres);
2173
2174 hres = IActiveScript_SetScriptSite(engine, &ActiveScriptSite);
2175 ok(hres == S_OK, "SetScriptSite failed: %08x\n", hres);
2176
2177 SET_EXPECT(GetItemInfo_testVal);
2178 hres = IActiveScript_AddNamedItem(engine, test_valW,
2179 SCRIPTITEM_ISVISIBLE|SCRIPTITEM_ISSOURCE|SCRIPTITEM_GLOBALMEMBERS);
2180 ok(hres == S_OK, "AddNamedItem failed: %08x\n", hres);
2181 CHECK_CALLED(GetItemInfo_testVal);
2182
2183 V_VT(&res) = VT_NULL;
2184 SET_EXPECT(global_success_d);
2185 SET_EXPECT(global_success_i);
2186 hres = IActiveScriptParse_ParseScriptText(parser, str, NULL, NULL, NULL, 0, 0, 0, &res, NULL);
2187 CHECK_CALLED(global_success_d);
2188 CHECK_CALLED(global_success_i);
2189 ok(hres == S_OK, "ParseScriptText failed: %08x\n", hres);
2190 ok(V_VT(&res) == VT_EMPTY, "V_VT(&res) = %d\n", V_VT(&res));
2191
2192 hres = IActiveScript_GetScriptState(engine, &state);
2193 ok(hres == S_OK, "GetScriptState failed: %08x\n", hres);
2194 ok(state == SCRIPTSTATE_INITIALIZED, "state = %d\n", state);
2195
2196 hres = IActiveScript_SetScriptState(engine, SCRIPTSTATE_STARTED);
2197 ok(hres == S_OK, "SetScriptState(SCRIPTSTATE_STARTED) failed: %08x\n", hres);
2198
2199 hres = IActiveScript_Close(engine);
2200 ok(hres == S_OK, "Close failed: %08x\n", hres);
2201
2202 IActiveScriptParse_Release(parser);
2203 IActiveScript_Release(engine);
2204 SysFreeString(str);
2205 }
2206
2207 static void test_default_value(void)
2208 {
2209 DISPPARAMS dp = {0};
2210 IDispatch *disp;
2211 VARIANT v;
2212 HRESULT hres;
2213
2214 hres = parse_script_expr("new Date()", &v, NULL);
2215 ok(hres == S_OK, "parse_script_expr failed: %08x\n", hres);
2216 ok(V_VT(&v) == VT_DISPATCH, "V_VT(v) = %d\n", V_VT(&v));
2217 disp = V_DISPATCH(&v);
2218
2219 V_VT(&v) = VT_EMPTY;
2220 hres = IDispatch_Invoke(disp, DISPID_VALUE, &IID_NULL, 0, DISPATCH_PROPERTYGET, &dp, &v, NULL, NULL);
2221 ok(hres == S_OK || broken(hres == 0x8000ffff), "Invoke failed: %08x\n", hres);
2222 if(hres == S_OK)
2223 {
2224 ok(V_VT(&v) == VT_BSTR, "V_VT(v) = %d\n", V_VT(&v));
2225 }
2226
2227 VariantClear(&v);
2228 IDispatch_Release(disp);
2229 }
2230
2231 static void test_script_exprs(void)
2232 {
2233 VARIANT v;
2234 HRESULT hres;
2235
2236 testing_expr = TRUE;
2237
2238 hres = parse_script_expr("true", &v, NULL);
2239 ok(hres == S_OK, "parse_script_expr failed: %08x\n", hres);
2240 ok(V_VT(&v) == VT_BOOL, "V_VT(v) = %d\n", V_VT(&v));
2241 ok(V_BOOL(&v) == VARIANT_TRUE, "V_BOOL(v) = %x\n", V_BOOL(&v));
2242
2243 hres = parse_script_expr("false, true", &v, NULL);
2244 ok(hres == S_OK, "parse_script_expr failed: %08x\n", hres);
2245 ok(V_VT(&v) == VT_BOOL, "V_VT(v) = %d\n", V_VT(&v));
2246 ok(V_BOOL(&v) == VARIANT_TRUE, "V_BOOL(v) = %x\n", V_BOOL(&v));
2247
2248 SET_EXPECT(global_success_d);
2249 SET_EXPECT(global_success_i);
2250 hres = parse_script_expr("reportSuccess(); true", &v, NULL);
2251 ok(hres == S_OK, "parse_script_expr failed: %08x\n", hres);
2252 ok(V_VT(&v) == VT_BOOL, "V_VT(v) = %d\n", V_VT(&v));
2253 ok(V_BOOL(&v) == VARIANT_TRUE, "V_BOOL(v) = %x\n", V_BOOL(&v));
2254 CHECK_CALLED(global_success_d);
2255 CHECK_CALLED(global_success_i);
2256
2257 hres = parse_script_expr("if(false) true", &v, NULL);
2258 ok(hres == S_OK, "parse_script_expr failed: %08x\n", hres);
2259 ok(V_VT(&v) == VT_EMPTY, "V_VT(v) = %d\n", V_VT(&v));
2260
2261 hres = parse_script_expr("return testPropGet", &v, NULL);
2262 ok(hres == 0x800a03fa, "parse_script_expr failed: %08x\n", hres);
2263
2264 hres = parse_script_expr("reportSuccess(); return true", &v, NULL);
2265 ok(hres == 0x800a03fa, "parse_script_expr failed: %08x\n", hres);
2266
2267 SET_EXPECT(global_success_d);
2268 SET_EXPECT(global_success_i);
2269 hres = parse_script_expr("reportSuccess(); true", NULL, NULL);
2270 ok(hres == S_OK, "parse_script_expr failed: %08x\n", hres);
2271 CHECK_CALLED(global_success_d);
2272 CHECK_CALLED(global_success_i);
2273
2274 test_default_value();
2275 test_retval();
2276
2277 testing_expr = FALSE;
2278 }
2279
2280 static void test_invokeex(void)
2281 {
2282 DISPID func_id, prop_id;
2283 DISPPARAMS dp = {NULL};
2284 IActiveScript *script;
2285 IDispatchEx *dispex;
2286 VARIANT v;
2287 BSTR str;
2288 HRESULT hres;
2289
2290 hres = parse_script_expr("var o = {func: function() {return 3;}, prop: 6}; o", &v, &script);
2291 ok(hres == S_OK, "parse_script_expr failed: %08x\n", hres);
2292 ok(V_VT(&v) == VT_DISPATCH, "V_VT(v) = %d\n", V_VT(&v));
2293
2294 hres = IDispatch_QueryInterface(V_DISPATCH(&v), &IID_IDispatchEx, (void**)&dispex);
2295 ok(hres == S_OK, "Could not get IDispatchEx iface: %08x\n", hres);
2296 VariantClear(&v);
2297
2298 str = a2bstr("func");
2299 hres = IDispatchEx_GetDispID(dispex, str, 0, &func_id);
2300 SysFreeString(str);
2301 ok(hres == S_OK, "GetDispID failed: %08x\n", hres);
2302
2303 str = a2bstr("prop");
2304 hres = IDispatchEx_GetDispID(dispex, str, 0, &prop_id);
2305 SysFreeString(str);
2306 ok(hres == S_OK, "GetDispID failed: %08x\n", hres);
2307
2308 hres = IDispatchEx_InvokeEx(dispex, func_id, 0, DISPATCH_METHOD, &dp, &v, NULL, NULL);
2309 ok(hres == S_OK, "InvokeEx failed: %08x\n", hres);
2310 ok(V_VT(&v) == VT_I4, "V_VT(v) = %d\n", V_VT(&v));
2311 ok(V_I4(&v) == 3, "V_I4(v) = %d\n", V_I4(&v));
2312
2313 hres = IDispatchEx_InvokeEx(dispex, prop_id, 0, DISPATCH_PROPERTYGET, &dp, &v, NULL, NULL);
2314 ok(hres == S_OK, "InvokeEx failed: %08x\n", hres);
2315 ok(V_VT(&v) == VT_I4, "V_VT(v) = %d\n", V_VT(&v));
2316 ok(V_I4(&v) == 6, "V_I4(v) = %d\n", V_I4(&v));
2317
2318 hres = IActiveScript_SetScriptState(script, SCRIPTSTATE_UNINITIALIZED);
2319 ok(hres == S_OK, "SetScriptState(SCRIPTSTATE_STARTED) failed: %08x\n", hres);
2320
2321 str = a2bstr("func");
2322 hres = IDispatchEx_GetDispID(dispex, str, 0, &func_id);
2323 SysFreeString(str);
2324 ok(hres == S_OK, "GetDispID failed: %08x\n", hres);
2325
2326 hres = IDispatchEx_InvokeEx(dispex, func_id, 0, DISPATCH_METHOD, &dp, &v, NULL, NULL);
2327 ok(hres == E_UNEXPECTED || broken(hres == 0x800a1393), "InvokeEx failed: %08x\n", hres);
2328
2329 hres = IDispatchEx_InvokeEx(dispex, prop_id, 0, DISPATCH_PROPERTYGET, &dp, &v, NULL, NULL);
2330 ok(hres == S_OK, "InvokeEx failed: %08x\n", hres);
2331 ok(V_VT(&v) == VT_I4, "V_VT(v) = %d\n", V_VT(&v));
2332 ok(V_I4(&v) == 6, "V_I4(v) = %d\n", V_I4(&v));
2333
2334 IDispatchEx_Release(dispex);
2335 IActiveScript_Release(script);
2336 }
2337
2338 struct bom_test
2339 {
2340 WCHAR str[1024];
2341 HRESULT hres;
2342 };
2343
2344 static void run_bom_tests(void)
2345 {
2346 BSTR src;
2347 int i;
2348 HRESULT hres;
2349 struct bom_test bom_tests[] = {
2350 {{'v','a','r',' ','a',' ','=',' ','1',';',' ','r','e','p','o','r','t','S','u','c','c','e','s','s','(',')',';','\0'}, S_OK},
2351 {{0xFEFF,'v','a','r',' ','a',' ','=',' ','1',';',' ','r','e','p','o','r','t','S','u','c','c','e','s','s','(',')',';','\0'}, S_OK},
2352 {{'v',0xFEFF,'a','r',' ','a',' ','=',' ','1',';',' ','r','e','p','o','r','t','S','u','c','c','e','s','s','(',')',';','\0'}, JS_E_OUT_OF_MEMORY},
2353 {{'v','a','r',0xFEFF,' ','a',' ','=',' ','1',';',' ','r','e','p','o','r','t','S','u','c','c','e','s','s','(',')',';','\0'}, S_OK},
2354 {{'v','a','r',' ','a',' ','=',' ','1',';',' ',0xFEFF,'r','e','p','o','r','t','S','u','c','c','e','s','s','(',')',';','\0'}, S_OK},
2355 {{'v','a','r',' ','a',' ','=',' ','1',';',' ','r','e','p','o','r','t',0xFEFF,'S','u','c','c','e','s','s','(',')',';','\0'}, JS_E_OUT_OF_MEMORY},
2356 {{'v','a','r',' ','a',' ','=',' ','1',';',' ','r','e','p','o','r','t','S','u','c','c','e','s','s',0xFEFF,'(',')',';','\0'}, S_OK},
2357 {{'v','a','r',' ','a',' ','=',' ','1',';',' ','r','e','p','o','r','t','S','u','c','c','e','s','s','(',0xFEFF,')',';','\0'}, S_OK},
2358 {{'v','a','r',' ','a',' ','=',0xFEFF,' ','1',';',' ','r','e','p','o','r','t','S','u','c','c','e','s','s','(',0xFEFF,')',';','\0'}, S_OK},
2359 {{0xFEFF,'v','a','r',' ','a',' ','=',0xFEFF,0xFEFF,' ','1',';',' ','r','e','p','o','r','t','S','u','c','c','e','s','s','(',0xFEFF,')',';','\0'}, S_OK},
2360 {{0}}
2361 };
2362
2363 engine_clsid = &CLSID_JScript;
2364
2365 for (i = 0; bom_tests[i].str[0]; i++)
2366 {
2367 if(bom_tests[i].hres == S_OK)
2368 {
2369 SET_EXPECT(global_success_d);
2370 SET_EXPECT(global_success_i);
2371 src = SysAllocString(bom_tests[i].str);
2372 hres = parse_script(SCRIPTITEM_GLOBALMEMBERS, src);
2373 ok(hres == S_OK, "test %s failed with %08x\n", wine_dbgstr_w(src), hres);
2374 SysFreeString(src);
2375 CHECK_CALLED(global_success_d);
2376 CHECK_CALLED(global_success_i);
2377 }
2378 else
2379 {
2380 src = SysAllocString(bom_tests[i].str);
2381 hres = parse_script(SCRIPTITEM_GLOBALMEMBERS, src);
2382 todo_wine ok(hres == bom_tests[i].hres, "test %s returned with %08x\n", wine_dbgstr_w(src), hres);
2383 SysFreeString(src);
2384 }
2385 }
2386 }
2387
2388 static BOOL run_tests(void)
2389 {
2390 HRESULT hres;
2391
2392 if(invoke_version) {
2393 IActiveScript *script;
2394
2395 script = create_script();
2396 if(!script) {
2397 win_skip("Could not create script\n");
2398 return FALSE;
2399 }
2400 IActiveScript_Release(script);
2401 }
2402
2403 strict_dispid_check = TRUE;
2404
2405 parse_script_a("");
2406 parse_script_a("/* empty */ ;");
2407
2408 SET_EXPECT(global_propget_d);
2409 SET_EXPECT(global_propget_i);
2410 parse_script_a("testPropGet;");
2411 CHECK_CALLED(global_propget_d);
2412 CHECK_CALLED(global_propget_i);
2413
2414 SET_EXPECT(global_propput_d);
2415 SET_EXPECT(global_propput_i);
2416 parse_script_a("testPropPut = 1;");
2417 CHECK_CALLED(global_propput_d);
2418 CHECK_CALLED(global_propput_i);
2419
2420 SET_EXPECT(global_propputref_d);
2421 SET_EXPECT(global_propputref_i);
2422 parse_script_a("testPropPutRef = new Object();");
2423 CHECK_CALLED(global_propputref_d);
2424 CHECK_CALLED(global_propputref_i);
2425
2426 SET_EXPECT(global_propputref_d);
2427 SET_EXPECT(global_propputref_i);
2428 parse_script_a("testPropPutRef = testObj;");
2429 CHECK_CALLED(global_propputref_d);
2430 CHECK_CALLED(global_propputref_i);
2431
2432 SET_EXPECT(global_success_d);
2433 SET_EXPECT(global_success_i);
2434 parse_script_a("reportSuccess();");
2435 CHECK_CALLED(global_success_d);
2436 CHECK_CALLED(global_success_i);
2437
2438 SET_EXPECT(testobj_delete_test);
2439 parse_script_a("ok((delete testObj.deleteTest) === true, 'delete testObj.deleteTest did not return true');");
2440 CHECK_CALLED(testobj_delete_test);
2441
2442 SET_EXPECT(testobj_delete_nodelete);
2443 parse_script_a("ok((delete testObj.noDeleteTest) === false, 'delete testObj.noDeleteTest did not return false');");
2444 CHECK_CALLED(testobj_delete_nodelete);
2445
2446 SET_EXPECT(global_propdelete_d);
2447 SET_EXPECT(DeleteMemberByDispID);
2448 parse_script_a("ok((delete testPropDelete) === true, 'delete testPropDelete did not return true');");
2449 CHECK_CALLED(global_propdelete_d);
2450 CHECK_CALLED(DeleteMemberByDispID);
2451
2452 SET_EXPECT(global_nopropdelete_d);
2453 SET_EXPECT(DeleteMemberByDispID_false);
2454 parse_script_a("ok((delete testNoPropDelete) === false, 'delete testPropDelete did not return false');");
2455 CHECK_CALLED(global_nopropdelete_d);
2456 CHECK_CALLED(DeleteMemberByDispID_false);
2457
2458 SET_EXPECT(puredisp_prop_d);
2459 parse_script_a("ok((delete pureDisp.prop) === false, 'delete pureDisp.prop did not return true');");
2460 CHECK_CALLED(puredisp_prop_d);
2461
2462 SET_EXPECT(puredisp_noprop_d);
2463 parse_script_a("ok((delete pureDisp.noprop) === true, 'delete pureDisp.noprop did not return false');");
2464 CHECK_CALLED(puredisp_noprop_d);
2465
2466 SET_EXPECT(puredisp_value);
2467 parse_script_a("var t=pureDisp; t=t(false);");
2468 CHECK_CALLED(puredisp_value);
2469
2470 SET_EXPECT(puredisp_value);
2471 parse_script_a("var t = {func: pureDisp}; t = t.func(false);");
2472 CHECK_CALLED(puredisp_value);
2473
2474 SET_EXPECT(dispexfunc_value);
2475 parse_script_a("var t = dispexFunc; t = t(false);");
2476 CHECK_CALLED(dispexfunc_value);
2477
2478 SET_EXPECT(dispexfunc_value);
2479 parse_script_a("var t = {func: dispexFunc}; t = t.func(false);");
2480 CHECK_CALLED(dispexfunc_value);
2481
2482 parse_script_a("(function reportSuccess() {})()");
2483
2484 parse_script_a("ok(typeof(test) === 'object', \"typeof(test) != 'object'\");");
2485
2486 parse_script_a("function reportSuccess() {}; reportSuccess();");
2487
2488 SET_EXPECT(global_propget_d);
2489 parse_script_a("var testPropGet");
2490 CHECK_CALLED(global_propget_d);
2491
2492 SET_EXPECT(global_propget_d);
2493 parse_script_a("eval('var testPropGet;');");
2494 CHECK_CALLED(global_propget_d);
2495
2496 SET_EXPECT(global_notexists_d);
2497 parse_script_a("var notExists; notExists = 1;");
2498 CHECK_CALLED(global_notexists_d);
2499
2500 SET_EXPECT(testobj_notexists_d);
2501 parse_script_a("testObj.notExists;");
2502 CHECK_CALLED(testobj_notexists_d);
2503
2504 parse_script_a("function f() { var testPropGet; }");
2505 parse_script_a("(function () { var testPropGet; })();");
2506 parse_script_a("(function () { eval('var testPropGet;'); })();");
2507
2508 SET_EXPECT(invoke_func);
2509 parse_script_a("ok(propGetFunc() == 0, \"Incorrect propGetFunc value\");");
2510 CHECK_CALLED(invoke_func);
2511 parse_script_a("ok(propGetFunc(1) == 1, \"Incorrect propGetFunc value\");");
2512 parse_script_a("ok(propGetFunc(1, 2) == 2, \"Incorrect propGetFunc value\");");
2513 SET_EXPECT(invoke_func);
2514 parse_script_a("ok(propGetFunc().toString() == 0, \"Incorrect propGetFunc value\");");
2515 CHECK_CALLED(invoke_func);
2516 parse_script_a("ok(propGetFunc(1).toString() == 1, \"Incorrect propGetFunc value\");");
2517 SET_EXPECT(invoke_func);
2518 parse_script_a("propGetFunc(1);");
2519 CHECK_CALLED(invoke_func);
2520
2521 parse_script_a("objectFlag(1).toString();");
2522
2523 parse_script_a("(function() { var tmp = (function () { return testObj; })()(1);})();");
2524 parse_script_a("(function() { var tmp = (function () { return testObj; })()();})();");
2525
2526 parse_script_a("ok((testObj instanceof Object) === false, 'testObj is instance of Object');");
2527
2528 SET_EXPECT(testobj_prop_d);
2529 parse_script_a("ok(('prop' in testObj) === true, 'prop is not in testObj');");
2530 CHECK_CALLED(testobj_prop_d);
2531
2532 SET_EXPECT(testobj_noprop_d);
2533 parse_script_a("ok(('noprop' in testObj) === false, 'noprop is in testObj');");
2534 CHECK_CALLED(testobj_noprop_d);
2535
2536 SET_EXPECT(testobj_prop_d);
2537 parse_script_a("ok(Object.prototype.hasOwnProperty.call(testObj, 'prop') === true, 'hasOwnProperty(\\\"prop\\\") returned false');");
2538 CHECK_CALLED(testobj_prop_d);
2539
2540 SET_EXPECT(testobj_noprop_d);
2541 parse_script_a("ok(Object.prototype.hasOwnProperty.call(testObj, 'noprop') === false, 'hasOwnProperty(\\\"noprop\\\") returned true');");
2542 CHECK_CALLED(testobj_noprop_d);
2543
2544 SET_EXPECT(puredisp_prop_d);
2545 parse_script_a("ok(Object.prototype.hasOwnProperty.call(pureDisp, 'prop') === true, 'hasOwnProperty(\\\"noprop\\\") returned false');");
2546 CHECK_CALLED(puredisp_prop_d);
2547
2548 SET_EXPECT(puredisp_noprop_d);
2549 parse_script_a("ok(Object.prototype.hasOwnProperty.call(pureDisp, 'noprop') === false, 'hasOwnProperty(\\\"noprop\\\") returned true');");
2550 CHECK_CALLED(puredisp_noprop_d);
2551
2552 SET_EXPECT(testobj_value);
2553 parse_script_a("ok(String(testObj) === '1', 'wrong testObj value');");
2554 CHECK_CALLED(testobj_value);
2555
2556 SET_EXPECT(testobj_value);
2557 parse_script_a("ok(String.prototype.concat.call(testObj, ' OK') === '1 OK', 'wrong concat result');");
2558 CHECK_CALLED(testobj_value);
2559
2560 SET_EXPECT(testobj_construct);
2561 parse_script_a("var t = new testObj(1);");
2562 CHECK_CALLED(testobj_construct);
2563
2564 SET_EXPECT(global_propget_d);
2565 SET_EXPECT(global_propget_i);
2566 parse_script_a("this.testPropGet;");
2567 CHECK_CALLED(global_propget_d);
2568 CHECK_CALLED(global_propget_i);
2569
2570 SET_EXPECT(global_propputref_d);
2571 SET_EXPECT(global_propputref_i);
2572 parse_script_a("testPropPutRef = nullDisp;");
2573 CHECK_CALLED(global_propputref_d);
2574 CHECK_CALLED(global_propputref_i);
2575
2576 SET_EXPECT(global_propget_d);
2577 SET_EXPECT(global_propget_i);
2578 parse_script_a("(function () { this.testPropGet; })();");
2579 CHECK_CALLED(global_propget_d);
2580 CHECK_CALLED(global_propget_i);
2581
2582 parse_script_a("testThis(this);");
2583 parse_script_a("(function () { testThis(this); })();");
2584 parse_script_a("function x() { testThis(this); }; x();");
2585 parse_script_a("var t = {func: function () { ok(this === t, 'this !== t'); }}; with(t) { func(); }");
2586 parse_script_a("function x() { testThis(this); }; with({y: 1}) { x(); }");
2587 parse_script_a("(function () { function x() { testThis(this);} x(); })();");
2588
2589 SET_EXPECT(testobj_onlydispid_d);
2590 SET_EXPECT(testobj_onlydispid_i);
2591 parse_script_a("ok(typeof(testObj.onlyDispID) === 'unknown', 'unexpected typeof(testObj.onlyDispID)');");
2592 CHECK_CALLED(testobj_onlydispid_d);
2593 CHECK_CALLED(testobj_onlydispid_i);
2594
2595 SET_EXPECT(global_propargput_d);
2596 SET_EXPECT(global_propargput_i);
2597 parse_script_a("var t=0; propArgPutG(t++, t++) = t++;");
2598 CHECK_CALLED(global_propargput_d);
2599 CHECK_CALLED(global_propargput_i);
2600
2601 SET_EXPECT(global_propargput_d);
2602 SET_EXPECT(global_propargput_i);
2603 parse_script_a("var t=0; test.propArgPutO(t++, t++) = t++;");
2604 CHECK_CALLED(global_propargput_d);
2605 CHECK_CALLED(global_propargput_i);
2606
2607 SET_EXPECT(global_testargtypes_i);
2608 parse_script_a("testArgTypes(dispUnk, intProp(), intProp, getShort(), shortProp, function(i4ref,ui4,nullunk,d,i,s) {"
2609 " ok(getVT(i) === 'VT_I4', 'getVT(i) = ' + getVT(i));"
2610 " ok(getVT(s) === 'VT_I4', 'getVT(s) = ' + getVT(s));"
2611 " ok(getVT(d) === 'VT_DISPATCH', 'getVT(d) = ' + getVT(d));"
2612 " ok(getVT(nullunk) === 'VT_DISPATCH', 'getVT(nullunk) = ' + getVT(nullunk));"
2613 " ok(nullunk === null, 'nullunk !== null');"
2614 " ok(getVT(ui4) === 'VT_R8', 'getVT(ui4) = ' + getVT(ui4));"
2615 " ok(ui4 > 0, 'ui4 = ' + ui4);"
2616 " ok(getVT(i4ref) === 'VT_I4', 'getVT(i4ref) = ' + getVT(i4ref));"
2617 " ok(i4ref === 2, 'i4ref = ' + i4ref);"
2618 "});");
2619 CHECK_CALLED(global_testargtypes_i);
2620
2621 SET_EXPECT(testobj_withprop_d);
2622 SET_EXPECT(testobj_withprop_i);
2623 parse_script_a("var t = (function () { with(testObj) { return withProp; }})(); ok(t === 1, 't = ' + t);");
2624 CHECK_CALLED(testobj_withprop_d);
2625 CHECK_CALLED(testobj_withprop_i);
2626
2627 parse_script_a("@set @t=2\nok(@t === 2, '@t = ' + @t);");
2628
2629 SET_EXPECT(global_success_d);
2630 SET_EXPECT(global_success_i);
2631 parse_script_a("@if(true)\nif(@_jscript) reportSuccess();\n@end");
2632 CHECK_CALLED(global_success_d);
2633 CHECK_CALLED(global_success_i);
2634
2635 run_from_res("lang.js");
2636 run_from_res("api.js");
2637 run_from_res("regexp.js");
2638 run_from_res("cc.js");
2639
2640 test_isvisible(FALSE);
2641 test_isvisible(TRUE);
2642 test_start();
2643 test_automagic();
2644
2645 parse_script_af(0, "test.testThis2(this);");
2646 parse_script_af(0, "(function () { test.testThis2(this); })();");
2647
2648 hres = parse_htmlscript_a("<!--");
2649 ok(hres == S_OK, "ParseScriptText failed: %08x\n", hres);
2650 hres = parse_htmlscript_a("-->");
2651 ok(hres == S_OK, "ParseScriptText failed: %08x\n", hres);
2652 hres = parse_htmlscript_a("<!--\nvar a=1;\n-->\n");
2653 ok(hres == S_OK, "ParseScriptText failed: %08x\n", hres);
2654 hres = parse_htmlscript_a("<!--\n<!-- ignore this\n-->\n");
2655 ok(hres == S_OK, "ParseScriptText failed: %08x\n", hres);
2656 hres = parse_htmlscript_a("var a=1;\nif(a-->0) a=5;\n");
2657 ok(hres == S_OK, "ParseScriptText failed: %08x\n", hres);
2658 hres = parse_htmlscript_a("var a=1;\nif(a\n-->0) a=5;\n");
2659 ok(hres != S_OK, "ParseScriptText have not failed\n");
2660
2661 test_script_exprs();
2662 test_invokeex();
2663
2664 parse_script_with_error_a(
2665 "?",
2666 0x800a03ea, 0, 0,
2667 "Microsoft JScript compilation error",
2668 "Syntax error",
2669 "?");
2670
2671 parse_script_with_error_a(
2672 "var a=1;\nif(a\n-->0) a=5;\n",
2673 0x800a03ee, 2, 0,
2674 "Microsoft JScript compilation error",
2675 "Expected ')'",
2676 "-->0) a=5;");
2677
2678 parse_script_with_error_a(
2679 "new 3;",
2680 0x800a01bd, 0, 0,
2681 "Microsoft JScript runtime error",
2682 "Object doesn't support this action",
2683 NULL);
2684
2685 parse_script_with_error_a(
2686 "new null;",
2687 0x800a138f, 0, 0,
2688 "Microsoft JScript runtime error",
2689 "Object expected",
2690 NULL);
2691
2692 parse_script_with_error_a(
2693 "var a;\nnew null;",
2694 0x800a138f, 1, 0,
2695 "Microsoft JScript runtime error",
2696 "Object expected",
2697 NULL);
2698
2699 parse_script_with_error_a(
2700 "var a; new null;",
2701 0x800a138f, 0, 7,
2702 "Microsoft JScript runtime error",
2703 "Object expected",
2704 NULL);
2705
2706 run_bom_tests();
2707
2708 return TRUE;
2709 }
2710
2711 static void test_parse_proc(void)
2712 {
2713 VARIANT args[2];
2714 DISPPARAMS dp = {args};
2715
2716 dp.cArgs = 0;
2717 invoke_procedure(NULL, "return true;", &dp);
2718
2719 dp.cArgs = 1;
2720 V_VT(args) = VT_EMPTY;
2721 invoke_procedure(NULL, "return arguments.length == 1;", &dp);
2722
2723 V_VT(args) = VT_BOOL;
2724 V_BOOL(args) = VARIANT_TRUE;
2725 invoke_procedure(" x ", "return x;", &dp);
2726
2727 dp.cArgs = 2;
2728 V_VT(args) = VT_I4;
2729 V_I4(args) = 2;
2730 V_VT(args+1) = VT_I4;
2731 V_I4(args+1) = 1;
2732 invoke_procedure(" _x1 , y_2", "return _x1 === 1 && y_2 === 2;", &dp);
2733 }
2734
2735 static void run_encoded_tests(void)
2736 {
2737 BSTR src;
2738 HRESULT hres;
2739
2740 engine_clsid = &CLSID_JScriptEncode;
2741
2742 SET_EXPECT(global_success_d);
2743 SET_EXPECT(global_success_i);
2744 /* |reportSuccess(); | */
2745 parse_script_a("#@~^EAAAAA==.\x7fwGMYUEm1+kd`*iAQYAAA==^#~@");
2746 CHECK_CALLED(global_success_d);
2747 CHECK_CALLED(global_success_i);
2748
2749 SET_EXPECT(global_success_d);
2750 SET_EXPECT(global_success_i);
2751 parse_script_a("reportSuccess();");
2752 CHECK_CALLED(global_success_d);
2753 CHECK_CALLED(global_success_i);
2754
2755 SET_EXPECT(global_success_d);
2756 SET_EXPECT(global_success_i);
2757 /* |Success | */
2758 parse_script_a("report#@~^BwAAAA==j!m^\x7f/k2QIAAA==^#~@();");
2759 CHECK_CALLED(global_success_d);
2760 CHECK_CALLED(global_success_i);
2761
2762 SET_EXPECT(global_success_d);
2763 SET_EXPECT(global_success_i);
2764 /* |\r\n\treportSuccess();\r\n | */
2765 parse_script_a("#@~^GQAAAA==@#@&d.\x7fwKDYUE1^+k/c#p@#@&OAYAAA==^#~@");
2766 CHECK_CALLED(global_success_d);
2767 CHECK_CALLED(global_success_i);
2768
2769 /* v */
2770 src = a2bstr("#@~^EAA*AA==.\x7fwGMYUEm1+kd`*iAQYAAA==^#~@");
2771 hres = parse_script(SCRIPTITEM_GLOBALMEMBERS, src);
2772 SysFreeString(src);
2773 ok(hres == JS_E_INVALID_CHAR, "parse_script failed %08x\n", hres);
2774
2775 /* vv */
2776 src = a2bstr("#@~^EAAAAAAA==.\x7fwGMYUEm1+kd`*iAQYAAA==^#~@");
2777 hres = parse_script(SCRIPTITEM_GLOBALMEMBERS, src);
2778 SysFreeString(src);
2779 ok(hres == JS_E_INVALID_CHAR, "parse_script failed %08x\n", hres);
2780
2781 /* v */
2782 src = a2bstr("#@~^EAAAAA^=.\x7fwGMYUEm1+kd`*iAQYAAA==^#~@");
2783 hres = parse_script(SCRIPTITEM_GLOBALMEMBERS, src);
2784 SysFreeString(src);
2785 ok(hres == JS_E_INVALID_CHAR, "parse_script failed %08x\n", hres);
2786
2787 /* v */
2788 src = a2bstr("#@~^EAAAAA==.\x7fwGMYUEm1ekd`*iAQYAAA==^#~@");
2789 hres = parse_script(SCRIPTITEM_GLOBALMEMBERS, src);
2790 SysFreeString(src);
2791 ok(hres == JS_E_INVALID_CHAR, "parse_script failed %08x\n", hres);
2792
2793 /* vv */
2794 src = a2bstr("#@~^EAAAAA==.\x7fwGMYUEm1+kd`*iAQYAAA==^~#@");
2795 hres = parse_script(SCRIPTITEM_GLOBALMEMBERS, src);
2796 SysFreeString(src);
2797 ok(hres == JS_E_INVALID_CHAR, "parse_script failed %08x\n", hres);
2798 }
2799
2800 static void run_benchmark(const char *script_name)
2801 {
2802 IActiveScriptParse *parser;
2803 IActiveScript *engine;
2804 ULONG start, end;
2805 BSTR src;
2806 HRESULT hres;
2807
2808 engine = create_script();
2809 if(!engine)
2810 return;
2811
2812 hres = IActiveScript_QueryInterface(engine, &IID_IActiveScriptParse, (void**)&parser);
2813 ok(hres == S_OK, "Could not get IActiveScriptParse: %08x\n", hres);
2814 if (FAILED(hres)) {
2815 IActiveScript_Release(engine);
2816 return;
2817 }
2818
2819 hres = IActiveScriptParse_InitNew(parser);
2820 ok(hres == S_OK, "InitNew failed: %08x\n", hres);
2821
2822 hres = IActiveScript_SetScriptSite(engine, &ActiveScriptSite);
2823 ok(hres == S_OK, "SetScriptSite failed: %08x\n", hres);
2824
2825 hres = IActiveScript_AddNamedItem(engine, testW,
2826 SCRIPTITEM_ISVISIBLE|SCRIPTITEM_ISSOURCE);
2827 ok(hres == S_OK, "AddNamedItem failed: %08x\n", hres);
2828
2829 hres = IActiveScript_SetScriptState(engine, SCRIPTSTATE_STARTED);
2830 ok(hres == S_OK, "SetScriptState(SCRIPTSTATE_STARTED) failed: %08x\n", hres);
2831
2832 src = load_res(script_name);
2833
2834 start = GetTickCount();
2835 hres = IActiveScriptParse_ParseScriptText(parser, src, NULL, NULL, NULL, 0, 0, 0