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