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