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 */ 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 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 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) 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 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 245 static ULONG WINAPI EnumVARIANT_AddRef(IEnumVARIANT *iface) 246 { 247 return 2; 248 } 249 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; 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 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 } 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 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 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 342 static ULONG WINAPI DispatchEx_AddRef(IDispatchEx *iface) 343 { 344 return 2; 345 } 346 347 static ULONG WINAPI DispatchEx_Release(IDispatchEx *iface) 348 { 349 return 1; 350 } 351 352 static HRESULT WINAPI DispatchEx_GetTypeInfoCount(IDispatchEx *iface, UINT *pctinfo) 353 { 354 ok(0, "unexpected call\n"); 355 return E_NOTIMPL; 356 } 357 358 static HRESULT WINAPI DispatchEx_GetTypeInfo(IDispatchEx *iface, UINT iTInfo, 359 LCID lcid, ITypeInfo **ppTInfo) 360 { 361 return E_NOTIMPL; 362 } 363 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 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 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 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 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 399 static HRESULT WINAPI DispatchEx_DeleteMemberByDispID(IDispatchEx *iface, DISPID id) 400 { 401 ok(0, "unexpected call\n"); 402 return E_NOTIMPL; 403 } 404 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 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 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 423 static HRESULT WINAPI DispatchEx_GetNameSpaceParent(IDispatchEx *iface, IUnknown **ppunk) 424 { 425 ok(0, "unexpected call\n"); 426 return E_NOTIMPL; 427 } 428 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 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 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 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 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 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 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 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 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 738 static ULONG WINAPI BindEventHandler_AddRef(IBindEventHandler *iface) 739 { 740 return 2; 741 } 742 743 static ULONG WINAPI BindEventHandler_Release(IBindEventHandler *iface) 744 { 745 return 1; 746 } 747 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 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 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 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 ok(V_BOOL(pdp->rgvarg+1), "%s: %s\n", test_name, wine_dbgstr_w(V_BSTR(pdp->rgvarg))); 1036 1037 return S_OK; 1038 1039 case DISPID_GLOBAL_TRACE: 1040 ok(wFlags == INVOKE_FUNC, "wFlags = %x\n", wFlags); 1041 ok(pdp != NULL, "pdp == NULL\n"); 1042 ok(pdp->rgvarg != NULL, "rgvarg == NULL\n"); 1043 ok(!pdp->rgdispidNamedArgs, "rgdispidNamedArgs != NULL\n"); 1044 ok(pdp->cArgs == 1, "cArgs = %d\n", pdp->cArgs); 1045 ok(!pdp->cNamedArgs, "cNamedArgs = %d\n", pdp->cNamedArgs); 1046 ok(!pvarRes, "pvarRes != NULL\n"); 1047 ok(pei != NULL, "pei == NULL\n"); 1048 1049 ok(V_VT(pdp->rgvarg) == VT_BSTR, "V_VT(pdp->rgvarg) = %d\n", V_VT(pdp->rgvarg)); 1050 if(V_VT(pdp->rgvarg) == VT_BSTR) 1051 trace("%s: %s\n", test_name, wine_dbgstr_w(V_BSTR(pdp->rgvarg))); 1052 1053 return S_OK; 1054 1055 case DISPID_GLOBAL_REPORTSUCCESS: 1056 CHECK_EXPECT(global_success_i); 1057 1058 ok(wFlags == INVOKE_FUNC, "wFlags = %x\n", wFlags); 1059 ok(pdp != NULL, "pdp == NULL\n"); 1060 ok(!pdp->rgdispidNamedArgs, "rgdispidNamedArgs != NULL\n"); 1061 ok(pdp->cArgs == 0, "cArgs = %d\n", pdp->cArgs); 1062 ok(!pdp->cNamedArgs, "cNamedArgs = %d\n", pdp->cNamedArgs); 1063 if(!testing_expr) 1064 ok(!pvarRes, "pvarRes != NULL\n"); 1065 ok(pei != NULL, "pei == NULL\n"); 1066 1067 return S_OK; 1068 1069 case DISPID_GLOBAL_TESTPROPGET: 1070 CHECK_EXPECT(global_propget_i); 1071 1072 ok(wFlags == INVOKE_PROPERTYGET, "wFlags = %x\n", wFlags); 1073 ok(pdp != NULL, "pdp == NULL\n"); 1074 ok(!pdp->rgvarg, "rgvarg != NULL\n"); 1075 ok(!pdp->rgdispidNamedArgs, "rgdispidNamedArgs != NULL\n"); 1076 ok(!pdp->cArgs, "cArgs = %d\n", pdp->cArgs); 1077 ok(!pdp->cNamedArgs, "cNamedArgs = %d\n", pdp->cNamedArgs); 1078 ok(pvarRes != NULL, "pvarRes == NULL\n"); 1079 ok(V_VT(pvarRes) == VT_EMPTY, "V_VT(pvarRes) = %d\n", V_VT(pvarRes)); 1080 ok(pei != NULL, "pei == NULL\n"); 1081 1082 V_VT(pvarRes) = VT_I4; 1083 V_I4(pvarRes) = 1; 1084 1085 return S_OK; 1086 1087 case DISPID_GLOBAL_TESTPROPPUT: 1088 CHECK_EXPECT(global_propput_i); 1089 1090 ok(wFlags == INVOKE_PROPERTYPUT, "wFlags = %x\n", wFlags); 1091 ok(pdp != NULL, "pdp == NULL\n"); 1092 ok(pdp->rgvarg != NULL, "rgvarg == NULL\n"); 1093 ok(pdp->rgdispidNamedArgs != NULL, "rgdispidNamedArgs == NULL\n"); 1094 ok(pdp->cArgs == 1, "cArgs = %d\n", pdp->cArgs); 1095 ok(pdp->cNamedArgs == 1, "cNamedArgs = %d\n", pdp->cNamedArgs); 1096 ok(pdp->rgdispidNamedArgs[0] == DISPID_PROPERTYPUT, "pdp->rgdispidNamedArgs[0] = %d\n", pdp->rgdispidNamedArgs[0]); 1097 ok(!pvarRes, "pvarRes != NULL\n"); 1098 1099 ok(V_VT(pdp->rgvarg) == VT_I4, "V_VT(pdp->rgvarg)=%d\n", V_VT(pdp->rgvarg)); 1100 ok(V_I4(pdp->rgvarg) == 1, "V_I4(pdp->rgvarg)=%d\n", V_I4(pdp->rgvarg)); 1101 return S_OK; 1102 1103 case DISPID_GLOBAL_TESTPROPPUTREF: 1104 CHECK_EXPECT(global_propputref_i); 1105 1106 ok(wFlags == (INVOKE_PROPERTYPUT|INVOKE_PROPERTYPUTREF), "wFlags = %x\n", wFlags); 1107 ok(pdp != NULL, "pdp == NULL\n"); 1108 ok(pdp->rgvarg != NULL, "rgvarg == NULL\n"); 1109 ok(pdp->rgdispidNamedArgs != NULL, "rgdispidNamedArgs == NULL\n"); 1110 ok(pdp->cArgs == 1, "cArgs = %d\n", pdp->cArgs); 1111 ok(pdp->cNamedArgs == 1, "cNamedArgs = %d\n", pdp->cNamedArgs); 1112 ok(pdp->rgdispidNamedArgs[0] == DISPID_PROPERTYPUT, "pdp->rgdispidNamedArgs[0] = %d\n", pdp->rgdispidNamedArgs[0]); 1113 ok(!pvarRes, "pvarRes != NULL\n"); 1114 1115 ok(V_VT(pdp->rgvarg) == VT_DISPATCH, "V_VT(pdp->rgvarg)=%d\n", V_VT(pdp->rgvarg)); 1116 return S_OK; 1117 1118 case DISPID_GLOBAL_GETVT: 1119 ok(pdp != NULL, "pdp == NULL\n"); 1120 ok(pdp->rgvarg != NULL, "rgvarg == NULL\n"); 1121 ok(!pdp->rgdispidNamedArgs, "rgdispidNamedArgs != NULL\n"); 1122 ok(pdp->cArgs == 1, "cArgs = %d\n", pdp->cArgs); 1123 ok(!pdp->cNamedArgs, "cNamedArgs = %d\n", pdp->cNamedArgs); 1124 ok(pvarRes != NULL, "pvarRes == NULL\n"); 1125 ok(V_VT(pvarRes) == VT_EMPTY, "V_VT(pvarRes) = %d\n", V_VT(pvarRes)); 1126 ok(pei != NULL, "pei == NULL\n"); 1127 1128 V_VT(pvarRes) = VT_BSTR; 1129 switch(V_VT(pdp->rgvarg)) { 1130 case VT_EMPTY: 1131 V_BSTR(pvarRes) = a2bstr("VT_EMPTY"); 1132 break; 1133 case VT_NULL: 1134 V_BSTR(pvarRes) = a2bstr("VT_NULL"); 1135 break; 1136 case VT_I4: 1137 V_BSTR(pvarRes) = a2bstr("VT_I4"); 1138 break; 1139 case VT_R8: 1140 V_BSTR(pvarRes) = a2bstr("VT_R8"); 1141 break; 1142 case VT_BSTR: 1143 V_BSTR(pvarRes) = a2bstr("VT_BSTR"); 1144 break; 1145 case VT_DISPATCH: 1146 V_BSTR(pvarRes) = a2bstr("VT_DISPATCH"); 1147 break; 1148 case VT_BOOL: 1149 V_BSTR(pvarRes) = a2bstr("VT_BOOL"); 1150 break; 1151 case VT_ARRAY|VT_VARIANT: 1152 V_BSTR(pvarRes) = a2bstr("VT_ARRAY|VT_VARIANT"); 1153 break; 1154 default: 1155 ok(0, "unknown vt %d\n", V_VT(pdp->rgvarg)); 1156 return E_FAIL; 1157 } 1158 1159 return S_OK; 1160 1161 case DISPID_GLOBAL_TESTRES: 1162 ok(pvarRes != NULL, "pvarRes = NULL\n"); 1163 if(pvarRes) { 1164 V_VT(pvarRes) = VT_BOOL; 1165 V_BOOL(pvarRes) = VARIANT_TRUE; 1166 } 1167 return S_OK; 1168 1169 case DISPID_GLOBAL_TESTNORES: 1170 ok(!pvarRes, "pvarRes != NULL\n"); 1171 if(pvarRes) 1172 V_VT(pvarRes) = VT_NULL; 1173 return S_OK; 1174 1175 case DISPID_GLOBAL_TESTOBJ: 1176 ok(wFlags == INVOKE_PROPERTYGET, "wFlags = %x\n", wFlags); 1177 ok(pdp != NULL, "pdp == NULL\n"); 1178 ok(!pdp->rgvarg, "rgvarg != NULL\n"); 1179 ok(!pdp->rgdispidNamedArgs, "rgdispidNamedArgs != NULL\n"); 1180 ok(!pdp->cArgs, "cArgs = %d\n", pdp->cArgs); 1181 ok(!pdp->cNamedArgs, "cNamedArgs = %d\n", pdp->cNamedArgs); 1182 ok(pvarRes != NULL, "pvarRes == NULL\n"); 1183 ok(V_VT(pvarRes) == VT_EMPTY, "V_VT(pvarRes) = %d\n", V_VT(pvarRes)); 1184 ok(pei != NULL, "pei == NULL\n"); 1185 1186 V_VT(pvarRes) = VT_DISPATCH; 1187 V_DISPATCH(pvarRes) = (IDispatch*)&testObj; 1188 return S_OK; 1189 1190 case DISPID_GLOBAL_PUREDISP: 1191 ok(wFlags == INVOKE_PROPERTYGET, "wFlags = %x\n", wFlags); 1192 ok(pdp != NULL, "pdp == NULL\n"); 1193 ok(!pdp->rgvarg, "rgvarg != NULL\n"); 1194 ok(!pdp->rgdispidNamedArgs, "rgdispidNamedArgs != NULL\n"); 1195 ok(!pdp->cArgs, "cArgs = %d\n", pdp->cArgs); 1196 ok(!pdp->cNamedArgs, "cNamedArgs = %d\n", pdp->cNamedArgs); 1197 ok(pvarRes != NULL, "pvarRes == NULL\n"); 1198 ok(V_VT(pvarRes) == VT_EMPTY, "V_VT(pvarRes) = %d\n", V_VT(pvarRes)); 1199 ok(pei != NULL, "pei == NULL\n"); 1200 1201 V_VT(pvarRes) = VT_DISPATCH; 1202 V_DISPATCH(pvarRes) = (IDispatch*)&pureDisp; 1203 return S_OK; 1204 1205 case DISPID_GLOBAL_DISPEXFUNC: 1206 V_VT(pvarRes) = VT_DISPATCH; 1207 V_DISPATCH(pvarRes) = (IDispatch*)&dispexFunc; 1208 return S_OK; 1209 1210 case DISPID_GLOBAL_GETNULLBSTR: 1211 if(pvarRes) { 1212 V_VT(pvarRes) = VT_BSTR; 1213 V_BSTR(pvarRes) = NULL; 1214 } 1215 return S_OK; 1216 1217 case DISPID_GLOBAL_ISNULLBSTR: 1218 ok(pdp != NULL, "pdp == NULL\n"); 1219 ok(pdp->rgvarg != NULL, "rgvarg == NULL\n"); 1220 ok(!pdp->rgdispidNamedArgs, "rgdispidNamedArgs != NULL\n"); 1221 ok(pdp->cArgs == 1, "cArgs = %d\n", pdp->cArgs); 1222 ok(!pdp->cNamedArgs, "cNamedArgs = %d\n", pdp->cNamedArgs); 1223 ok(pvarRes != NULL, "pvarRes == NULL\n"); 1224 ok(V_VT(pvarRes) == VT_EMPTY, "V_VT(pvarRes) = %d\n", V_VT(pvarRes)); 1225 ok(pei != NULL, "pei == NULL\n"); 1226 ok(V_VT(pdp->rgvarg) == VT_BSTR, "V_VT(pdp->rgvarg) = %d\n", V_VT(pdp->rgvarg)); 1227 1228 V_VT(pvarRes) = VT_BOOL; 1229 V_BOOL(pvarRes) = V_BSTR(pdp->rgvarg) ? VARIANT_FALSE : VARIANT_TRUE; 1230 return S_OK; 1231 1232 case DISPID_GLOBAL_ISWIN64: 1233 if(pvarRes) { 1234 V_VT(pvarRes) = VT_BOOL; 1235 V_BOOL(pvarRes) = sizeof(void*) == 8 ? VARIANT_TRUE : VARIANT_FALSE; 1236 } 1237 return S_OK; 1238 1239 case DISPID_GLOBAL_NULL_DISP: 1240 ok(wFlags == INVOKE_PROPERTYGET, "wFlags = %x\n", wFlags); 1241 ok(pdp != NULL, "pdp == NULL\n"); 1242 ok(!pdp->rgvarg, "rgvarg != NULL\n"); 1243 ok(!pdp->rgdispidNamedArgs, "rgdispidNamedArgs != NULL\n"); 1244 ok(!pdp->cArgs, "cArgs = %d\n", pdp->cArgs); 1245 ok(!pdp->cNamedArgs, "cNamedArgs = %d\n", pdp->cNamedArgs); 1246 ok(pvarRes != NULL, "pvarRes == NULL\n"); 1247 ok(V_VT(pvarRes) == VT_EMPTY, "V_VT(pvarRes) = %d\n", V_VT(pvarRes)); 1248 ok(pei != NULL, "pei == NULL\n"); 1249 1250 V_VT(pvarRes) = VT_DISPATCH; 1251 V_DISPATCH(pvarRes) = NULL; 1252 return S_OK; 1253 1254 case DISPID_GLOBAL_TESTTHIS: 1255 ok(pdp != NULL, "pdp == NULL\n"); 1256 ok(pdp->rgvarg != NULL, "rgvarg == NULL\n"); 1257 ok(!pdp->rgdispidNamedArgs, "rgdispidNamedArgs != NULL\n"); 1258 ok(pdp->cArgs == 1, "cArgs = %d\n", pdp->cArgs); 1259 ok(!pdp->cNamedArgs, "cNamedArgs = %d\n", pdp->cNamedArgs); 1260 ok(pvarRes == NULL, "pvarRes != NULL\n"); 1261 ok(pei != NULL, "pei == NULL\n"); 1262 1263 ok(V_VT(pdp->rgvarg) == VT_DISPATCH, "V_VT(pdp->rgvarg) = %d\n", V_VT(pdp->rgvarg)); 1264 ok(V_DISPATCH(pdp->rgvarg) == (IDispatch*)iface, "disp != iface\n"); 1265 1266 return S_OK; 1267 1268 case DISPID_GLOBAL_TESTTHIS2: 1269 ok(pdp != NULL, "pdp == NULL\n"); 1270 ok(pdp->rgvarg != NULL, "rgvarg == NULL\n"); 1271 ok(!pdp->rgdispidNamedArgs, "rgdispidNamedArgs != NULL\n"); 1272 ok(pdp->cArgs == 1, "cArgs = %d\n", pdp->cArgs); 1273 ok(!pdp->cNamedArgs, "cNamedArgs = %d\n", pdp->cNamedArgs); 1274 ok(pvarRes == NULL, "pvarRes != NULL\n"); 1275 ok(pei != NULL, "pei == NULL\n"); 1276 1277 ok(V_VT(pdp->rgvarg) == VT_DISPATCH, "V_VT(arg) = %d\n", V_VT(pdp->rgvarg)); 1278 ok(V_DISPATCH(pdp->rgvarg) != (IDispatch*)iface, "disp == iface\n"); 1279 ok(V_DISPATCH(pdp->rgvarg) == script_disp, "disp != script_disp\n"); 1280 1281 return S_OK; 1282 1283 case DISPID_GLOBAL_INVOKEVERSION: 1284 ok(wFlags == INVOKE_PROPERTYGET, "wFlags = %x\n", wFlags); 1285 ok(pdp != NULL, "pdp == NULL\n"); 1286 ok(!pdp->rgvarg, "rgvarg != NULL\n"); 1287 ok(!pdp->rgdispidNamedArgs, "rgdispidNamedArgs != NULL\n"); 1288 ok(!pdp->cArgs, "cArgs = %d\n", pdp->cArgs); 1289 ok(!pdp->cNamedArgs, "cNamedArgs = %d\n", pdp->cNamedArgs); 1290 ok(pvarRes != NULL, "pvarRes == NULL\n"); 1291 ok(V_VT(pvarRes) == VT_EMPTY, "V_VT(pvarRes) = %d\n", V_VT(pvarRes)); 1292 ok(pei != NULL, "pei == NULL\n"); 1293 1294 V_VT(pvarRes) = VT_I4; 1295 V_I4(pvarRes) = invoke_version; 1296 1297 return S_OK; 1298 1299 case DISPID_GLOBAL_CREATEARRAY: { 1300 SAFEARRAYBOUND bound[2]; 1301 VARIANT *data; 1302 int i,j; 1303 1304 ok(wFlags == INVOKE_FUNC, "wFlags = %x\n", wFlags); 1305 ok(pdp != NULL, "pdp == NULL\n"); 1306 ok(pdp->rgvarg != NULL, "rgvarg == NULL\n"); 1307 ok(!pdp->rgdispidNamedArgs, "rgdispidNamedArgs != NULL\n"); 1308 ok(!pdp->cArgs, "cArgs = %d\n", pdp->cArgs); 1309 ok(!pdp->cNamedArgs, "cNamedArgs = %d\n", pdp->cNamedArgs); 1310 ok(pvarRes != NULL, "pvarRes == NULL\n"); 1311 ok(V_VT(pvarRes) == VT_EMPTY, "V_VT(pvarRes) = %d\n", V_VT(pvarRes)); 1312 ok(pei != NULL, "pei == NULL\n"); 1313 1314 bound[0].lLbound = 0; 1315 bound[0].cElements = 5; 1316 bound[1].lLbound = 2; 1317 bound[1].cElements = 2; 1318 1319 V_VT(pvarRes) = VT_ARRAY|VT_VARIANT; 1320 V_ARRAY(pvarRes) = SafeArrayCreate(VT_VARIANT, 2, bound); 1321 1322 SafeArrayAccessData(V_ARRAY(pvarRes), (void**)&data); 1323 for(i=0; i<5; i++) { 1324 for(j=2; j<4; j++) { 1325 V_VT(data) = VT_I4; 1326 V_I4(data) = i*10+j; 1327 data++; 1328 } 1329 } 1330 SafeArrayUnaccessData(V_ARRAY(pvarRes)); 1331 1332 return S_OK; 1333 } 1334 1335 case DISPID_GLOBAL_PROPGETFUNC: 1336 switch(wFlags) { 1337 case INVOKE_FUNC: 1338 CHECK_EXPECT(invoke_func); 1339 break; 1340 case INVOKE_FUNC|INVOKE_PROPERTYGET: 1341 ok(pdp->cArgs != 0, "pdp->cArgs = %d\n", pdp->cArgs); 1342 ok(pvarRes != NULL, "pdp->pvarRes == NULL\n"); 1343 break; 1344 default: 1345 ok(0, "invalid flag (%x)\n", wFlags); 1346 } 1347 1348 ok(pdp != NULL, "pdp == NULL\n"); 1349 ok(!pdp->rgdispidNamedArgs, "rgdispidNamedArgs != NULL\n"); 1350 ok(!pdp->cNamedArgs, "cNamedArgs = %d\n", pdp->cNamedArgs); 1351 ok(pei != NULL, "pei == NULL\n"); 1352 1353 if(pvarRes) { 1354 ok(V_VT(pvarRes) == VT_EMPTY, "V_VT(pvarRes) = %d\n", V_VT(pvarRes)); 1355 V_VT(pvarRes) = VT_I4; 1356 V_I4(pvarRes) = pdp->cArgs; 1357 } 1358 1359 return S_OK; 1360 1361 case DISPID_GLOBAL_GETSCRIPTSTATE: { 1362 SCRIPTSTATE state; 1363 HRESULT hres; 1364 1365 hres = IActiveScript_GetScriptState(script_engine, &state); 1366 ok(hres == S_OK, "GetScriptState failed: %08x\n", hres); 1367 1368 V_VT(pvarRes) = VT_I4; 1369 V_I4(pvarRes) = state; 1370 return S_OK; 1371 } 1372 1373 case DISPID_GLOBAL_BINDEVENTHANDLER: 1374 V_VT(pvarRes) = VT_DISPATCH; 1375 V_DISPATCH(pvarRes) = (IDispatch*)&bindEventHandlerDisp; 1376 return S_OK; 1377 1378 case DISPID_GLOBAL_PROPARGPUT: 1379 CHECK_EXPECT(global_propargput_i); 1380 ok(wFlags == INVOKE_PROPERTYPUT, "wFlags = %x\n", wFlags); 1381 ok(pdp != NULL, "pdp == NULL\n"); 1382 ok(pdp->rgvarg != NULL, "rgvarg != NULL\n"); 1383 ok(pdp->rgdispidNamedArgs != NULL, "rgdispidNamedArgs == NULL\n"); 1384 ok(pdp->cArgs == 3, "cArgs = %d\n", pdp->cArgs); 1385 ok(pdp->cNamedArgs == 1, "cNamedArgs = %d\n", pdp->cNamedArgs); 1386 ok(pdp->rgdispidNamedArgs[0] == DISPID_PROPERTYPUT, "pdp->rgdispidNamedArgs[0] = %d\n", pdp->rgdispidNamedArgs[0]); 1387 ok(!pvarRes, "pvarRes != NULL\n"); 1388 ok(pei != NULL, "pei == NULL\n"); 1389 1390 ok(V_VT(pdp->rgvarg) == VT_I4, "V_VT(pdp->rgvarg) = %d\n", V_VT(pdp->rgvarg)); 1391 ok(V_I4(pdp->rgvarg) == 2, "V_I4(pdp->rgvarg) = %d\n", V_I4(pdp->rgvarg)); 1392 1393 ok(V_VT(pdp->rgvarg+1) == VT_I4, "V_VT(pdp->rgvarg+1) = %d\n", V_VT(pdp->rgvarg+1)); 1394 ok(V_I4(pdp->rgvarg+1) == 1, "V_I4(pdp->rgvarg+1) = %d\n", V_I4(pdp->rgvarg+1)); 1395 1396 ok(V_VT(pdp->rgvarg+2) == VT_I4, "V_VT(pdp->rgvarg+2) = %d\n", V_VT(pdp->rgvarg+2)); 1397 ok(V_I4(pdp->rgvarg+2) == 0, "V_I4(pdp->rgvarg+2) = %d\n", V_I4(pdp->rgvarg+2)); 1398 return S_OK; 1399 1400 case DISPID_GLOBAL_PROPARGPUTOP: 1401 ok(pdp != NULL, "pdp == NULL\n"); 1402 ok(pdp->rgvarg != NULL, "rgvarg != NULL\n"); 1403 ok(pei != NULL, "pei == NULL\n"); 1404 1405 switch(wFlags) { 1406 case INVOKE_PROPERTYGET | INVOKE_FUNC: 1407 CHECK_EXPECT(global_propargputop_get_i); 1408 1409 ok(pdp->cNamedArgs == 0, "cNamedArgs = %d\n", pdp->cNamedArgs); 1410 ok(!pdp->rgdispidNamedArgs, "rgdispidNamedArgs != NULL\n"); 1411 ok(pdp->cArgs == 2, "cArgs = %d\n", pdp->cArgs); 1412 ok(pdp->cNamedArgs == 0, "cNamedArgs = %d\n", pdp->cNamedArgs); 1413 ok(pvarRes != NULL, "pvarRes = NULL\n"); 1414 1415 ok(V_VT(pdp->rgvarg) == VT_I4, "V_VT(pdp->rgvarg) = %d\n", V_VT(pdp->rgvarg)); 1416 ok(V_I4(pdp->rgvarg) == 1, "V_I4(pdp->rgvarg) = %d\n", V_I4(pdp->rgvarg)); 1417 1418 ok(V_VT(pdp->rgvarg+1) == VT_I4, "V_VT(pdp->rgvarg+1) = %d\n", V_VT(pdp->rgvarg+1)); 1419 ok(V_I4(pdp->rgvarg+1) == 0, "V_I4(pdp->rgvarg+1) = %d\n", V_I4(pdp->rgvarg+1)); 1420 1421 V_VT(pvarRes) = VT_I4; 1422 V_I4(pvarRes) = 6; 1423 break; 1424 case INVOKE_PROPERTYPUT: 1425 CHECK_EXPECT(global_propargputop_put_i); 1426 1427 ok(pdp->cNamedArgs == 1, "cNamedArgs = %d\n", pdp->cNamedArgs); 1428 ok(pdp->rgdispidNamedArgs[0] == DISPID_PROPERTYPUT, "pdp->rgdispidNamedArgs[0] = %d\n", pdp->rgdispidNamedArgs[0]); 1429 ok(pdp->rgdispidNamedArgs != NULL, "rgdispidNamedArgs == NULL\n"); 1430 ok(pdp->cArgs == 3, "cArgs = %d\n", pdp->cArgs); 1431 ok(pdp->cNamedArgs == 1, "cNamedArgs = %d\n", pdp->cNamedArgs); 1432 ok(!pvarRes, "pvarRes != NULL\n"); 1433 1434 ok(V_VT(pdp->rgvarg) == VT_I4, "V_VT(pdp->rgvarg) = %d\n", V_VT(pdp->rgvarg)); 1435 ok(V_I4(pdp->rgvarg) == 8, "V_I4(pdp->rgvarg) = %d\n", V_I4(pdp->rgvarg)); 1436 1437 ok(V_VT(pdp->rgvarg+1) == VT_I4, "V_VT(pdp->rgvarg+1) = %d\n", V_VT(pdp->rgvarg+1)); 1438 ok(V_I4(pdp->rgvarg+1) == 1, "V_I4(pdp->rgvarg+1) = %d\n", V_I4(pdp->rgvarg+1)); 1439 1440 ok(V_VT(pdp->rgvarg+2) == VT_I4, "V_VT(pdp->rgvarg+2) = %d\n", V_VT(pdp->rgvarg+2)); 1441 ok(V_I4(pdp->rgvarg+2) == 0, "V_I4(pdp->rgvarg+2) = %d\n", V_I4(pdp->rgvarg+2)); 1442 break; 1443 default: 1444 ok(0, "wFlags = %x\n", wFlags); 1445 } 1446 1447 return S_OK; 1448 1449 case DISPID_GLOBAL_OBJECT_FLAG: { 1450 IDispatchEx *dispex; 1451 BSTR str; 1452 HRESULT hres; 1453 1454 hres = IDispatch_QueryInterface(script_disp, &IID_IDispatchEx, (void**)&dispex); 1455 ok(hres == S_OK, "hres = %x\n", hres); 1456 1457 str = a2bstr("Object"); 1458 hres = IDispatchEx_GetDispID(dispex, str, fdexNameCaseSensitive, &id); 1459 SysFreeString(str); 1460 ok(hres == S_OK, "hres = %x\n", hres); 1461 1462 hres = IDispatchEx_InvokeEx(dispex, id, lcid, DISPATCH_METHOD, pdp, NULL, pei, pspCaller); 1463 ok(hres == S_OK, "hres = %x\n", hres); 1464 1465 V_VT(pvarRes) = VT_EMPTY; 1466 hres = IDispatchEx_InvokeEx(dispex, id, lcid, DISPATCH_METHOD, pdp, pvarRes, pei, pspCaller); 1467 ok(hres == S_OK, "hres = %x\n", hres); 1468 ok(V_VT(pvarRes) == VT_DISPATCH, "V_VT(pvarRes) = %d\n", V_VT(pvarRes)); 1469 VariantClear(pvarRes); 1470 1471 hres = IDispatchEx_InvokeEx(dispex, id, lcid, DISPATCH_METHOD|DISPATCH_PROPERTYGET, pdp, NULL, pei, pspCaller); 1472 ok(hres == S_OK, "hres = %x\n", hres); 1473 1474 V_VT(pvarRes) = VT_EMPTY; 1475 hres = IDispatchEx_InvokeEx(dispex, id, lcid, DISPATCH_CONSTRUCT, pdp, pvarRes, pei, pspCaller); 1476 ok(hres == S_OK, "hres = %x\n", hres); 1477 ok(V_VT(pvarRes) == VT_DISPATCH, "V_VT(pvarRes) = %d\n", V_VT(pvarRes)); 1478 VariantClear(pvarRes); 1479 1480 hres = IDispatchEx_InvokeEx(dispex, id, lcid, DISPATCH_CONSTRUCT, pdp, NULL, pei, pspCaller); 1481 ok(hres == S_OK, "hres = %x\n", hres); 1482 1483 V_VT(pvarRes) = VT_EMPTY; 1484 hres = IDispatchEx_InvokeEx(dispex, id, lcid, DISPATCH_CONSTRUCT|DISPATCH_PROPERTYGET, pdp, pvarRes, pei, pspCaller); 1485 ok(hres == E_INVALIDARG, "hres = %x\n", hres); 1486 1487 V_VT(pvarRes) = VT_EMPTY; 1488 hres = IDispatchEx_InvokeEx(dispex, id, lcid, wFlags, pdp, pvarRes, pei, pspCaller); 1489 ok(hres == S_OK, "hres = %x\n", hres); 1490 ok(V_VT(pvarRes) == VT_DISPATCH, "V_VT(pvarRes) = %d\n", V_VT(pvarRes)); 1491 IDispatchEx_Release(dispex); 1492 return S_OK; 1493 } 1494 case DISPID_GLOBAL_SHORTPROP: 1495 case DISPID_GLOBAL_GETSHORT: 1496 V_VT(pvarRes) = VT_I2; 1497 V_I2(pvarRes) = 10; 1498 return S_OK; 1499 1500 case DISPID_GLOBAL_INTPROP: 1501 V_VT(pvarRes) = VT_INT; 1502 V_INT(pvarRes) = 22; 1503 return S_OK; 1504 1505 case DISPID_GLOBAL_DISPUNK: 1506 V_VT(pvarRes) = VT_UNKNOWN; 1507 V_UNKNOWN(pvarRes) = (IUnknown*)&testObj; 1508 return S_OK; 1509 1510 case DISPID_GLOBAL_TESTARGTYPES: { 1511 VARIANT args[10], v; 1512 DISPPARAMS dp = {args, NULL, ARRAY_SIZE(args), 0}; 1513 HRESULT hres; 1514 1515 CHECK_EXPECT(global_testargtypes_i); 1516 ok(wFlags == DISPATCH_METHOD, "wFlags = %x\n", wFlags); 1517 ok(pdp != NULL, "pdp == NULL\n"); 1518 ok(pdp->rgvarg != NULL, "rgvarg != NULL\n"); 1519 ok(pdp->cArgs == 6, "cArgs = %d\n", pdp->cArgs); 1520 ok(!pvarRes, "pvarRes != NULL\n"); 1521 1522 ok(V_VT(pdp->rgvarg+1) == VT_I4, "V_VT(pdp->rgvarg+1) = %d\n", V_VT(pdp->rgvarg+1)); 1523 ok(V_I4(pdp->rgvarg+1) == 10, "V_I4(pdp->rgvarg+1) = %d\n", V_I4(pdp->rgvarg+1)); 1524 1525 ok(V_VT(pdp->rgvarg+2) == VT_I4, "V_VT(pdp->rgvarg+2) = %d\n", V_VT(pdp->rgvarg+2)); 1526 ok(V_I4(pdp->rgvarg+2) == 10, "V_I4(pdp->rgvarg+2) = %d\n", V_I4(pdp->rgvarg+2)); 1527 1528 ok(V_VT(pdp->rgvarg+3) == VT_I4, "V_VT(pdp->rgvarg+3) = %d\n", V_VT(pdp->rgvarg+3)); 1529 ok(V_I4(pdp->rgvarg+3) == 22, "V_I4(pdp->rgvarg+3) = %d\n", V_I4(pdp->rgvarg+3)); 1530 1531 ok(V_VT(pdp->rgvarg+4) == VT_I4, "V_VT(pdp->rgvarg+4) = %d\n", V_VT(pdp->rgvarg+4)); 1532 ok(V_I4(pdp->rgvarg+4) == 22, "V_I4(pdp->rgvarg+4) = %d\n", V_I4(pdp->rgvarg+4)); 1533 1534 ok(V_VT(pdp->rgvarg+5) == VT_DISPATCH, "V_VT(pdp->rgvarg+5) = %d\n", V_VT(pdp->rgvarg+5)); 1535 ok(V_DISPATCH(pdp->rgvarg+5) == (IDispatch*)&testObj, "V_DISPATCH(pdp->rgvarg+5) != testObj\n"); 1536 1537 ok(V_VT(pdp->rgvarg) == VT_DISPATCH, "V_VT(pdp->rgvarg) = %d\n", V_VT(pdp->rgvarg)); 1538 1539 V_VT(args) = VT_I2; 1540 V_I2(args) = 2; 1541 V_VT(args+1) = VT_INT; 1542 V_INT(args+1) = 22; 1543 V_VT(args+2) = VT_UNKNOWN; 1544 V_UNKNOWN(args+2) = (IUnknown*)&testObj; 1545 V_VT(args+3) = VT_UNKNOWN; 1546 V_UNKNOWN(args+3) = NULL; 1547 V_VT(args+4) = VT_UI4; 1548 V_UI4(args+4) = 0xffffffff; 1549 V_VT(args+5) = VT_BYREF|VT_VARIANT; 1550 V_VARIANTREF(args+5) = &v; 1551 V_VT(args+6) = VT_R4; 1552 V_R4(args+6) = 0.5; 1553 V_VT(args+7) = VT_UI2; 1554 V_UI2(args+7) = 3; 1555 V_VT(args+8) = VT_UI1; 1556 V_UI1(args+8) = 4; 1557 V_VT(args+9) = VT_I1; 1558 V_I1(args+9) = 5; 1559 V_VT(&v) = VT_I4; 1560 V_I4(&v) = 2; 1561 hres = IDispatch_Invoke(V_DISPATCH(pdp->rgvarg), DISPID_VALUE, &IID_NULL, 0, DISPATCH_METHOD, &dp, NULL, NULL, NULL); 1562 ok(hres == S_OK, "Invoke failed: %08x\n", hres); 1563 1564 return S_OK; 1565 } 1566 1567 case DISPID_GLOBAL_CALLEVAL: { 1568 IDispatchEx *eval_func; 1569 DISPPARAMS params; 1570 VARIANT arg, res; 1571 HRESULT hres; 1572 1573 CHECK_EXPECT(global_calleval_i); 1574 1575 ok(pdp != NULL, "pdp == NULL\n"); 1576 ok(pdp->rgvarg != NULL, "rgvarg == NULL\n"); 1577 ok(!pdp->rgdispidNamedArgs, "rgdispidNamedArgs != NULL\n"); 1578 ok(pdp->cArgs == 1, "cArgs = %d\n", pdp->cArgs); 1579 ok(!pdp->cNamedArgs, "cNamedArgs = %d\n", pdp->cNamedArgs); 1580 ok(pvarRes == NULL, "pvarRes != NULL\n"); 1581 ok(pei != NULL, "pei == NULL\n"); 1582 1583 ok(V_VT(pdp->rgvarg) == VT_DISPATCH, "V_VT(arg) = %d\n", V_VT(pdp->rgvarg)); 1584 hres = IDispatch_QueryInterface(V_DISPATCH(pdp->rgvarg), &IID_IDispatchEx, (void**)&eval_func); 1585 ok(hres == S_OK, "Could not get IDispatchEx iface: %08x\n", hres); 1586 1587 params.rgvarg = &arg; 1588 params.rgdispidNamedArgs = NULL; 1589 params.cArgs = 1; 1590 params.cNamedArgs = 0; 1591 V_VT(&arg) = VT_BSTR; 1592 1593 V_BSTR(&arg) = a2bstr("var x = 5; v"); 1594 V_VT(&res) = VT_ERROR; 1595 hres = IDispatchEx_InvokeEx(eval_func, DISPID_VALUE, 0, DISPATCH_METHOD, ¶ms, &res, NULL, NULL); 1596 ok(hres == S_OK, "InvokeEx failed: %08x\n", hres); 1597 ok(V_VT(&res) == VT_I4, "eval returned type %u\n", V_VT(&res)); 1598 ok(V_I4(&res) == 2, "eval returned %d\n", V_I4(&res)); 1599 SysFreeString(V_BSTR(&arg)); 1600 IDispatchEx_Release(eval_func); 1601 return S_OK; 1602 } 1603 } 1604 1605 ok(0, "unexpected call %x\n", id); 1606 return DISP_E_MEMBERNOTFOUND; 1607 } 1608 1609 static HRESULT WINAPI Global_DeleteMemberByDispID(IDispatchEx *iface, DISPID id) 1610 { 1611 switch(id) { 1612 case DISPID_GLOBAL_TESTPROPDELETE: 1613 CHECK_EXPECT(DeleteMemberByDispID); 1614 return S_OK; 1615 case DISPID_GLOBAL_TESTNOPROPDELETE: 1616 CHECK_EXPECT(DeleteMemberByDispID_false); 1617 return S_FALSE; 1618 case DISPID_GLOBAL_TESTPROPDELETEERROR: 1619 CHECK_EXPECT(DeleteMemberByDispID_error); 1620 return E_FAIL; 1621 default: 1622 ok(0, "id = %d\n", id); 1623 } 1624 1625 return E_FAIL; 1626 } 1627 1628 static IDispatchExVtbl GlobalVtbl = { 1629 DispatchEx_QueryInterface, 1630 DispatchEx_AddRef, 1631 DispatchEx_Release, 1632 DispatchEx_GetTypeInfoCount, 1633 DispatchEx_GetTypeInfo, 1634 DispatchEx_GetIDsOfNames, 1635 DispatchEx_Invoke, 1636 Global_GetDispID, 1637 Global_InvokeEx, 1638 DispatchEx_DeleteMemberByName, 1639 Global_DeleteMemberByDispID, 1640 DispatchEx_GetMemberProperties, 1641 DispatchEx_GetMemberName, 1642 DispatchEx_GetNextDispID, 1643 DispatchEx_GetNameSpaceParent 1644 }; 1645 1646 static IDispatchEx Global = { &GlobalVtbl }; 1647 1648 static HRESULT WINAPI ActiveScriptSite_QueryInterface(IActiveScriptSite *iface, REFIID riid, void **ppv) 1649 { 1650 *ppv = NULL; 1651 1652 if(IsEqualGUID(&IID_IUnknown, riid)) 1653 *ppv = iface; 1654 else if(IsEqualGUID(&IID_IActiveScriptSite, riid)) 1655 *ppv = iface; 1656 else 1657 return E_NOINTERFACE; 1658 1659 IUnknown_AddRef((IUnknown*)*ppv); 1660 return S_OK; 1661 } 1662 1663 static ULONG WINAPI ActiveScriptSite_AddRef(IActiveScriptSite *iface) 1664 { 1665 return 2; 1666 } 1667 1668 static ULONG WINAPI ActiveScriptSite_Release(IActiveScriptSite *iface) 1669 { 1670 return 1; 1671 } 1672 1673 static HRESULT WINAPI ActiveScriptSite_GetLCID(IActiveScriptSite *iface, LCID *plcid) 1674 { 1675 *plcid = GetUserDefaultLCID(); 1676 return S_OK; 1677 } 1678 1679 static HRESULT WINAPI ActiveScriptSite_GetItemInfo(IActiveScriptSite *iface, LPCOLESTR pstrName, 1680 DWORD dwReturnMask, IUnknown **ppiunkItem, ITypeInfo **ppti) 1681 { 1682 ok(dwReturnMask == SCRIPTINFO_IUNKNOWN, "unexpected dwReturnMask %x\n", dwReturnMask); 1683 ok(!ppti, "ppti != NULL\n"); 1684 1685 if(!strcmp_wa(pstrName, test_valA)) 1686 CHECK_EXPECT(GetItemInfo_testVal); 1687 else if(strcmp_wa(pstrName, testA)) 1688 ok(0, "unexpected pstrName %s\n", wine_dbgstr_w(pstrName)); 1689 1690 *ppiunkItem = (IUnknown*)&Global; 1691 return S_OK; 1692 } 1693 1694 static HRESULT WINAPI ActiveScriptSite_GetDocVersionString(IActiveScriptSite *iface, BSTR *pbstrVersion) 1695 { 1696 return E_NOTIMPL; 1697 } 1698 1699 static HRESULT WINAPI ActiveScriptSite_OnScriptTerminate(IActiveScriptSite *iface, 1700 const VARIANT *pvarResult, const EXCEPINFO *pexcepinfo) 1701 { 1702 return E_NOTIMPL; 1703 } 1704 1705 static HRESULT WINAPI ActiveScriptSite_OnStateChange(IActiveScriptSite *iface, SCRIPTSTATE ssScriptState) 1706 { 1707 return E_NOTIMPL; 1708 } 1709 1710 static HRESULT WINAPI ActiveScriptSite_OnScriptError(IActiveScriptSite *iface, IActiveScriptError *pscripterror) 1711 { 1712 return E_NOTIMPL; 1713 } 1714 1715 static HRESULT WINAPI ActiveScriptSite_OnEnterScript(IActiveScriptSite *iface) 1716 { 1717 return E_NOTIMPL; 1718 } 1719 1720 static HRESULT WINAPI ActiveScriptSite_OnLeaveScript(IActiveScriptSite *iface) 1721 { 1722 return E_NOTIMPL; 1723 } 1724 1725 #undef ACTSCPSITE_THIS 1726 1727 static const IActiveScriptSiteVtbl ActiveScriptSiteVtbl = { 1728 ActiveScriptSite_QueryInterface, 1729 ActiveScriptSite_AddRef, 1730 ActiveScriptSite_Release, 1731 ActiveScriptSite_GetLCID, 1732 ActiveScriptSite_GetItemInfo, 1733 ActiveScriptSite_GetDocVersionString, 1734 ActiveScriptSite_OnScriptTerminate, 1735 ActiveScriptSite_OnStateChange, 1736 ActiveScriptSite_OnScriptError, 1737 ActiveScriptSite_OnEnterScript, 1738 ActiveScriptSite_OnLeaveScript 1739 }; 1740 1741 static IActiveScriptSite ActiveScriptSite = { &ActiveScriptSiteVtbl }; 1742 1743 static HRESULT WINAPI ActiveScriptSite_OnScriptError_CheckError(IActiveScriptSite *iface, IActiveScriptError *pscripterror) 1744 { 1745 ok(pscripterror != NULL, "ActiveScriptSite_OnScriptError -- expected pscripterror to be set, got NULL\n"); 1746 1747 script_error = pscripterror; 1748 IActiveScriptError_AddRef(script_error); 1749 1750 CHECK_EXPECT(ActiveScriptSite_OnScriptError); 1751 1752 return S_OK; 1753 } 1754 1755 static const IActiveScriptSiteVtbl ActiveScriptSite_CheckErrorVtbl = { 1756 ActiveScriptSite_QueryInterface, 1757 ActiveScriptSite_AddRef, 1758 ActiveScriptSite_Release, 1759 ActiveScriptSite_GetLCID, 1760 ActiveScriptSite_GetItemInfo, 1761 ActiveScriptSite_GetDocVersionString, 1762 ActiveScriptSite_OnScriptTerminate, 1763 ActiveScriptSite_OnStateChange, 1764 ActiveScriptSite_OnScriptError_CheckError, 1765 ActiveScriptSite_OnEnterScript, 1766 ActiveScriptSite_OnLeaveScript 1767 }; 1768 1769 static IActiveScriptSite ActiveScriptSite_CheckError = { &ActiveScriptSite_CheckErrorVtbl }; 1770 1771 static HRESULT set_script_prop(IActiveScript *engine, DWORD property, VARIANT *val) 1772 { 1773 IActiveScriptProperty *script_prop; 1774 HRESULT hres; 1775 1776 hres = IActiveScript_QueryInterface(engine, &IID_IActiveScriptProperty, 1777 (void**)&script_prop); 1778 ok(hres == S_OK, "Could not get IActiveScriptProperty iface: %08x\n", hres); 1779 1780 hres = IActiveScriptProperty_SetProperty(script_prop, property, NULL, val); 1781 IActiveScriptProperty_Release(script_prop); 1782 1783 return hres; 1784 } 1785 1786 static IActiveScript *create_script(void) 1787 { 1788 IActiveScript *script; 1789 VARIANT v; 1790 HRESULT hres; 1791 1792 hres = CoCreateInstance(engine_clsid, NULL, CLSCTX_INPROC_SERVER|CLSCTX_INPROC_HANDLER, 1793 &IID_IActiveScript, (void**)&script); 1794 ok(hres == S_OK, "CoCreateInstance failed: %08x\n", hres); 1795 1796 V_VT(&v) = VT_I4; 1797 V_I4(&v) = invoke_version; 1798 hres = set_script_prop(script, SCRIPTPROP_INVOKEVERSIONING, &v); 1799 ok(hres == S_OK || broken(hres == E_NOTIMPL), "SetProperty(SCRIPTPROP_INVOKEVERSIONING) failed: %08x\n", hres); 1800 if(invoke_version && FAILED(hres)) { 1801 IActiveScript_Release(script); 1802 return NULL; 1803 } 1804 1805 return script; 1806 } 1807 1808 static HRESULT parse_script(DWORD flags, BSTR script_str) 1809 { 1810 IActiveScriptParse *parser; 1811 IActiveScript *engine; 1812 HRESULT hres; 1813 1814 engine = create_script(); 1815 if(!engine) 1816 return S_OK; 1817 1818 hres = IActiveScript_QueryInterface(engine, &IID_IActiveScriptParse, (void**)&parser); 1819 ok(hres == S_OK, "Could not get IActiveScriptParse: %08x\n", hres); 1820 if (FAILED(hres)) 1821 { 1822 IActiveScript_Release(engine); 1823 return hres; 1824 } 1825 1826 hres = IActiveScriptParse_InitNew(parser); 1827 ok(hres == S_OK, "InitNew failed: %08x\n", hres); 1828 1829 hres = IActiveScript_SetScriptSite(engine, &ActiveScriptSite); 1830 ok(hres == S_OK, "SetScriptSite failed: %08x\n", hres); 1831 1832 hres = IActiveScript_AddNamedItem(engine, testW, 1833 SCRIPTITEM_ISVISIBLE|SCRIPTITEM_ISSOURCE|flags); 1834 ok(hres == S_OK, "AddNamedItem failed: %08x\n", hres); 1835 1836 hres = IActiveScript_SetScriptState(engine, SCRIPTSTATE_STARTED); 1837 ok(hres == S_OK, "SetScriptState(SCRIPTSTATE_STARTED) failed: %08x\n", hres); 1838 1839 hres = IActiveScript_GetScriptDispatch(engine, NULL, &script_disp); 1840 ok(hres == S_OK, "GetScriptDispatch failed: %08x\n", hres); 1841 ok(script_disp != NULL, "script_disp == NULL\n"); 1842 ok(script_disp != (IDispatch*)&Global, "script_disp == Global\n"); 1843 1844 hres = IActiveScriptParse_ParseScriptText(parser, script_str, NULL, NULL, NULL, 0, 0, 0, NULL, NULL); 1845 1846 IDispatch_Release(script_disp); 1847 IActiveScript_Release(engine); 1848 IActiveScriptParse_Release(parser); 1849 1850 return hres; 1851 } 1852 1853 static HRESULT invoke_procedure(const char *argsa, const char *sourcea, DISPPARAMS *dp) 1854 { 1855 IActiveScriptParseProcedure2 *parse_proc; 1856 IActiveScriptParse *parser; 1857 IActiveScript *engine; 1858 IDispatchEx *dispex; 1859 EXCEPINFO ei = {0}; 1860 BSTR source, args; 1861 IDispatch *disp; 1862 VARIANT res; 1863 HRESULT hres; 1864 1865 engine = create_script(); 1866 if(!engine) 1867 return S_OK; 1868 1869 hres = IActiveScript_QueryInterface(engine, &IID_IActiveScriptParse, (void**)&parser); 1870 ok(hres == S_OK, "Could not get IActiveScriptParse: %08x\n", hres); 1871 1872 hres = IActiveScriptParse_InitNew(parser); 1873 ok(hres == S_OK, "InitNew failed: %08x\n", hres); 1874 1875 hres = IActiveScript_SetScriptSite(engine, &ActiveScriptSite); 1876 ok(hres == S_OK, "SetScriptSite failed: %08x\n", hres); 1877 1878 hres = IActiveScript_SetScriptState(engine, SCRIPTSTATE_STARTED); 1879 ok(hres == S_OK, "SetScriptState(SCRIPTSTATE_STARTED) failed: %08x\n", hres); 1880 1881 hres = IActiveScript_QueryInterface(engine, &IID_IActiveScriptParseProcedure2, (void**)&parse_proc); 1882 ok(hres == S_OK, "Could not get IActiveScriptParse: %08x\n", hres); 1883 1884 source = a2bstr(sourcea); 1885 args = argsa ? a2bstr(argsa) : NULL; 1886 hres = IActiveScriptParseProcedure2_ParseProcedureText(parse_proc, source, args, emptyW, NULL, NULL, NULL, 0, 0, 1887 SCRIPTPROC_HOSTMANAGESSOURCE|SCRIPTPROC_IMPLICIT_THIS|SCRIPTPROC_IMPLICIT_PARENTS, &disp); 1888 ok(hres == S_OK, "ParseProcedureText failed: %08x\n", hres); 1889 SysFreeString(source); 1890 SysFreeString(args); 1891 1892 hres = IDispatch_QueryInterface(disp, &IID_IDispatchEx, (void**)&dispex); 1893 ok(hres == S_OK, "Could not get IDispatchEx iface: %08x\n", hres); 1894 IDispatch_Release(disp); 1895 1896 V_VT(&res) = VT_EMPTY; 1897 hres = IDispatchEx_InvokeEx(dispex, DISPID_VALUE, 0, DISPATCH_METHOD, dp, &res, &ei, NULL); 1898 ok(hres == S_OK, "InvokeEx failed: %08x\n", hres); 1899 ok(V_VT(&res) == VT_BOOL && V_BOOL(&res), "InvokeEx returned vt %d (%x)\n", V_VT(&res), V_I4(&res)); 1900 IDispatchEx_Release(dispex); 1901 1902 IActiveScriptParseProcedure2_Release(parse_proc); 1903 IActiveScript_Release(engine); 1904 IActiveScriptParse_Release(parser); 1905 1906 return hres; 1907 } 1908 1909 static HRESULT parse_htmlscript(BSTR script_str) 1910 { 1911 IActiveScriptParse *parser; 1912 IActiveScript *engine; 1913 HRESULT hres; 1914 BSTR tmp = a2bstr("</SCRIPT>"); 1915 1916 engine = create_script(); 1917 if(!engine) 1918 return E_FAIL; 1919 1920 hres = IActiveScript_QueryInterface(engine, &IID_IActiveScriptParse, (void**)&parser); 1921 ok(hres == S_OK, "Could not get IActiveScriptParse: %08x\n", hres); 1922 if (FAILED(hres)) 1923 { 1924 IActiveScript_Release(engine); 1925 return E_FAIL; 1926 } 1927 1928 hres = IActiveScriptParse_InitNew(parser); 1929 ok(hres == S_OK, "InitNew failed: %08x\n", hres); 1930 1931 hres = IActiveScript_SetScriptSite(engine, &ActiveScriptSite); 1932 ok(hres == S_OK, "SetScriptSite failed: %08x\n", hres); 1933 1934 hres = IActiveScript_AddNamedItem(engine, testW, 1935 SCRIPTITEM_ISVISIBLE|SCRIPTITEM_ISSOURCE|SCRIPTITEM_GLOBALMEMBERS); 1936 ok(hres == S_OK, "AddNamedItem failed: %08x\n", hres); 1937 1938 hres = IActiveScript_SetScriptState(engine, SCRIPTSTATE_STARTED); 1939 ok(hres == S_OK, "SetScriptState(SCRIPTSTATE_STARTED) failed: %08x\n", hres); 1940 1941 hres = IActiveScriptParse_ParseScriptText(parser, script_str, NULL, NULL, tmp, 0, 0, 0, NULL, NULL); 1942 1943 IActiveScript_Release(engine); 1944 IActiveScriptParse_Release(parser); 1945 SysFreeString(tmp); 1946 1947 return hres; 1948 } 1949 1950 static void test_IActiveScriptError(IActiveScriptError *error, SCODE errorcode, ULONG line, LONG pos, BSTR script_source, BSTR description, BSTR line_text) 1951 { 1952 HRESULT hres; 1953 DWORD source_context; 1954 ULONG line_number; 1955 LONG char_position; 1956 BSTR linetext; 1957 EXCEPINFO excep; 1958 1959 /* IActiveScriptError_GetSourcePosition */ 1960 1961 hres = IActiveScriptError_GetSourcePosition(error, NULL, NULL, NULL); 1962 ok(hres == S_OK, "IActiveScriptError_GetSourcePosition -- hres: expected S_OK, got 0x%08x\n", hres); 1963 1964 source_context = 0xdeadbeef; 1965 hres = IActiveScriptError_GetSourcePosition(error, &source_context, NULL, NULL); 1966 ok(hres == S_OK, "IActiveScriptError_GetSourcePosition -- hres: expected S_OK, got 0x%08x\n", hres); 1967 ok(source_context == 0, "IActiveScriptError_GetSourcePosition -- source_context: expected 0, got 0x%08x\n", source_context); 1968 1969 line_number = 0xdeadbeef; 1970 hres = IActiveScriptError_GetSourcePosition(error, NULL, &line_number, NULL); 1971 ok(hres == S_OK, "IActiveScriptError_GetSourcePosition -- hres: expected S_OK, got 0x%08x\n", hres); 1972 ok(line_number == line, "IActiveScriptError_GetSourcePosition -- line_number: expected %d, got %d\n", line, line_number); 1973 1974 char_position = 0xdeadbeef; 1975 hres = IActiveScriptError_GetSourcePosition(error, NULL, NULL, &char_position); 1976 ok(hres == S_OK, "IActiveScriptError_GetSourcePosition -- hres: expected S_OK, got 0x%08x\n", hres); 1977 ok(char_position == pos, "IActiveScriptError_GetSourcePosition -- char_position: expected %d, got %d\n", pos, char_position); 1978 1979 /* IActiveScriptError_GetSourceLineText */ 1980 1981 hres = IActiveScriptError_GetSourceLineText(error, NULL); 1982 ok(hres == E_POINTER, "IActiveScriptError_GetSourceLineText -- hres: expected E_POINTER, got 0x%08x\n", hres); 1983 1984 linetext = NULL; 1985 hres = IActiveScriptError_GetSourceLineText(error, &linetext); 1986 if (line_text) { 1987 ok(hres == S_OK, "IActiveScriptError_GetSourceLineText -- hres: expected S_OK, got 0x%08x\n", hres); 1988 ok(linetext != NULL && !lstrcmpW(linetext, line_text), 1989 "IActiveScriptError_GetSourceLineText -- expected %s, got %s\n", wine_dbgstr_w(line_text), wine_dbgstr_w(linetext)); 1990 } else { 1991 ok(hres == E_FAIL, "IActiveScriptError_GetSourceLineText -- hres: expected S_OK, got 0x%08x\n", hres); 1992 ok(linetext == NULL, 1993 "IActiveScriptError_GetSourceLineText -- expected NULL, got %s\n", wine_dbgstr_w(linetext)); 1994 } 1995 SysFreeString(linetext); 1996 1997 /* IActiveScriptError_GetExceptionInfo */ 1998 1999 hres = IActiveScriptError_GetExceptionInfo(error, NULL); 2000 ok(hres == E_POINTER, "IActiveScriptError_GetExceptionInfo -- hres: expected E_POINTER, got 0x%08x\n", hres); 2001 2002 excep.wCode = 0xdead; 2003 excep.wReserved = 0xdead; 2004 excep.bstrSource = (BSTR)0xdeadbeef; 2005 excep.bstrDescription = (BSTR)0xdeadbeef; 2006 excep.bstrHelpFile = (BSTR)0xdeadbeef; 2007 excep.dwHelpContext = 0xdeadbeef; 2008 excep.pvReserved = (void *)0xdeadbeef; 2009 excep.pfnDeferredFillIn = (void *)0xdeadbeef; 2010 excep.scode = 0xdeadbeef; 2011 2012 hres = IActiveScriptError_GetExceptionInfo(error, &excep); 2013 ok(hres == S_OK, "IActiveScriptError_GetExceptionInfo -- hres: expected S_OK, got 0x%08x\n", hres); 2014 2015 ok(excep.wCode == 0, "IActiveScriptError_GetExceptionInfo -- excep.wCode: expected 0, got 0x%08x\n", excep.wCode); 2016 ok(excep.wReserved == 0, "IActiveScriptError_GetExceptionInfo -- excep.wReserved: expected 0, got %d\n", excep.wReserved); 2017 if (!is_lang_english()) 2018 skip("Non-english UI (test with hardcoded strings)\n"); 2019 else { 2020 ok(excep.bstrSource != NULL && !lstrcmpW(excep.bstrSource, script_source), 2021 "IActiveScriptError_GetExceptionInfo -- excep.bstrSource is not valid: expected %s, got %s\n", 2022 wine_dbgstr_w(script_source), wine_dbgstr_w(excep.bstrSource)); 2023 ok(excep.bstrDescription != NULL && !lstrcmpW(excep.bstrDescription, description), 2024 "IActiveScriptError_GetExceptionInfo -- excep.bstrDescription is not valid: got %s\n", wine_dbgstr_w(excep.bstrDescription)); 2025 } 2026 ok(excep.bstrHelpFile == NULL, 2027 "IActiveScriptError_GetExceptionInfo -- excep.bstrHelpFile: expected NULL, got %s\n", wine_dbgstr_w(excep.bstrHelpFile)); 2028 ok(excep.dwHelpContext == 0, "IActiveScriptError_GetExceptionInfo -- excep.dwHelpContext: expected 0, got %d\n", excep.dwHelpContext); 2029 ok(excep.pvReserved == NULL, "IActiveScriptError_GetExceptionInfo -- excep.pvReserved: expected NULL, got %p\n", excep.pvReserved); 2030 ok(excep.pfnDeferredFillIn == NULL, "IActiveScriptError_GetExceptionInfo -- excep.pfnDeferredFillIn: expected NULL, got %p\n", excep.pfnDeferredFillIn); 2031 ok(excep.scode == errorcode, "IActiveScriptError_GetExceptionInfo -- excep.scode: expected 0x%08x, got 0x%08x\n", errorcode, excep.scode); 2032 2033 SysFreeString(excep.bstrSource); 2034 SysFreeString(excep.bstrDescription); 2035 SysFreeString(excep.bstrHelpFile); 2036 } 2037 2038 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) 2039 { 2040 IActiveScriptParse *parser; 2041 IActiveScript *engine; 2042 HRESULT hres; 2043 2044 engine = create_script(); 2045 if(!engine) 2046 return; 2047 2048 hres = IActiveScript_QueryInterface(engine, &IID_IActiveScriptParse, (void**)&parser); 2049 ok(hres == S_OK, "Could not get IActiveScriptParse: %08x\n", hres); 2050 if (FAILED(hres)) 2051 { 2052 IActiveScript_Release(engine); 2053 return; 2054 } 2055 2056 hres = IActiveScriptParse_InitNew(parser); 2057 ok(hres == S_OK, "InitNew failed: %08x\n", hres); 2058 2059 hres = IActiveScript_SetScriptSite(engine, &ActiveScriptSite_CheckError); 2060 ok(hres == S_OK, "SetScriptSite failed: %08x\n", hres); 2061 2062 hres = IActiveScript_AddNamedItem(engine, testW, 2063 SCRIPTITEM_ISVISIBLE|SCRIPTITEM_ISSOURCE|flags); 2064 ok(hres == S_OK, "AddNamedItem failed: %08x\n", hres); 2065 2066 hres = IActiveScript_SetScriptState(engine, SCRIPTSTATE_STARTED); 2067 ok(hres == S_OK, "SetScriptState(SCRIPTSTATE_STARTED) failed: %08x\n", hres); 2068 2069 hres = IActiveScript_GetScriptDispatch(engine, NULL, &script_disp); 2070 ok(hres == S_OK, "GetScriptDispatch failed: %08x\n", hres); 2071 ok(script_disp != NULL, "script_disp == NULL\n"); 2072 ok(script_disp != (IDispatch*)&Global, "script_disp == Global\n"); 2073 2074 script_error = NULL; 2075 SET_EXPECT(ActiveScriptSite_OnScriptError); 2076 hres = IActiveScriptParse_ParseScriptText(parser, script_str, NULL, NULL, NULL, 0, 0, 0, NULL, NULL); 2077 todo_wine ok(hres == 0x80020101, "parse_script_with_error should have returned 0x80020101, got: 0x%08x\n", hres); 2078 todo_wine CHECK_CALLED(ActiveScriptSite_OnScriptError); 2079 2080 if (script_error) 2081 { 2082 test_IActiveScriptError(script_error, errorcode, line, pos, script_source, description, line_text); 2083 2084 IActiveScriptError_Release(script_error); 2085 } 2086 2087 IDispatch_Release(script_disp); 2088 IActiveScript_Release(engine); 2089 IActiveScriptParse_Release(parser); 2090 } 2091 2092 static void parse_script_af(DWORD flags, const char *src) 2093 { 2094 BSTR tmp; 2095 HRESULT hres; 2096 2097 tmp = a2bstr(src); 2098 hres = parse_script(flags, tmp); 2099 SysFreeString(tmp); 2100 ok(hres == S_OK, "parse_script failed: %08x\n", hres); 2101 } 2102 2103 static void parse_script_a(const char *src) 2104 { 2105 parse_script_af(SCRIPTITEM_GLOBALMEMBERS, src); 2106 } 2107 2108 static void parse_script_ae(const char *src, HRESULT exhres) 2109 { 2110 BSTR tmp; 2111 HRESULT hres; 2112 2113 tmp = a2bstr(src); 2114 hres = parse_script(SCRIPTITEM_GLOBALMEMBERS, tmp); 2115 SysFreeString(tmp); 2116 ok(hres == exhres, "parse_script failed: %08x, expected %08x\n", hres, exhres); 2117 } 2118 2119 static void parse_script_with_error_a(const char *src, SCODE errorcode, ULONG line, LONG pos, LPCSTR source, LPCSTR desc, LPCSTR linetext) 2120 { 2121 BSTR tmp, script_source, description, line_text; 2122 2123 tmp = a2bstr(src); 2124 script_source = a2bstr(source); 2125 description = a2bstr(desc); 2126 line_text = a2bstr(linetext); 2127 2128 parse_script_with_error(SCRIPTITEM_GLOBALMEMBERS, tmp, errorcode, line, pos, script_source, description, line_text); 2129 2130 SysFreeString(line_text); 2131 SysFreeString(description); 2132 SysFreeString(script_source); 2133 SysFreeString(tmp); 2134 } 2135 2136 static HRESULT parse_htmlscript_a(const char *src) 2137 { 2138 HRESULT hres; 2139 BSTR tmp = a2bstr(src); 2140 hres = parse_htmlscript(tmp); 2141 SysFreeString(tmp); 2142 2143 return hres; 2144 } 2145 2146 static BSTR get_script_from_file(const char *filename) 2147 { 2148 DWORD size, len; 2149 HANDLE file, map; 2150 const char *file_map; 2151 BSTR ret; 2152 2153 file = CreateFileA(filename, GENERIC_READ, 0, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_READONLY, NULL); 2154 if(file == INVALID_HANDLE_VALUE) { 2155 trace("Could not open file: %u\n", GetLastError()); 2156 return NULL; 2157 } 2158 2159 size = GetFileSize(file, NULL); 2160 2161 map = CreateFileMappingW(file, NULL, PAGE_READONLY, 0, 0, NULL); 2162 CloseHandle(file); 2163 if(map == INVALID_HANDLE_VALUE) { 2164 trace("Could not create file mapping: %u\n", GetLastError()); 2165 return NULL; 2166 } 2167 2168 file_map = MapViewOfFile(map, FILE_MAP_READ, 0, 0, 0); 2169 CloseHandle(map); 2170 if(!file_map) { 2171 trace("MapViewOfFile failed: %u\n", GetLastError()); 2172 return NULL; 2173 } 2174 2175 len = MultiByteToWideChar(CP_ACP, 0, file_map, size, NULL, 0); 2176 ret = SysAllocStringLen(NULL, len); 2177 MultiByteToWideChar(CP_ACP, 0, file_map, size, ret, len); 2178 2179 UnmapViewOfFile(file_map); 2180 2181 return ret; 2182 } 2183 2184 static void run_from_file(const char *filename) 2185 { 2186 BSTR script_str; 2187 HRESULT hres; 2188 2189 script_str = get_script_from_file(filename); 2190 if(!script_str) 2191 return; 2192 2193 strict_dispid_check = FALSE; 2194 hres = parse_script(SCRIPTITEM_GLOBALMEMBERS, script_str); 2195 SysFreeString(script_str); 2196 ok(hres == S_OK, "parse_script failed: %08x\n", hres); 2197 } 2198 2199 static BSTR load_res(const char *name) 2200 { 2201 const char *data; 2202 DWORD size, len; 2203 BSTR str; 2204 HRSRC src; 2205 2206 strict_dispid_check = FALSE; 2207 test_name = name; 2208 2209 src = FindResourceA(NULL, name, (LPCSTR)40); 2210 ok(src != NULL, "Could not find resource %s\n", name); 2211 2212 size = SizeofResource(NULL, src); 2213 data = LoadResource(NULL, src); 2214 2215 len = MultiByteToWideChar(CP_ACP, 0, data, size, NULL, 0); 2216 str = SysAllocStringLen(NULL, len); 2217 MultiByteToWideChar(CP_ACP, 0, data, size, str, len); 2218 2219 return str; 2220 } 2221 2222 static void run_from_res(const char *name) 2223 { 2224 BSTR str; 2225 HRESULT hres; 2226 2227 str = load_res(name); 2228 2229 SET_EXPECT(global_success_d); 2230 SET_EXPECT(global_success_i); 2231 hres = parse_script(SCRIPTITEM_GLOBALMEMBERS, str); 2232 CHECK_CALLED(global_success_d); 2233 CHECK_CALLED(global_success_i); 2234 2235 ok(hres == S_OK, "parse_script failed: %08x\n", hres); 2236 SysFreeString(str); 2237 } 2238 2239 static void test_isvisible(BOOL global_members) 2240 { 2241 IActiveScriptParse *parser; 2242 IActiveScript *engine; 2243 HRESULT hres; 2244 2245 static const WCHAR script_textW[] = 2246 {'v','a','r',' ','v',' ','=',' ','t','e','s','t','V','a','l',';',0}; 2247 2248 engine = create_script(); 2249 if(!engine) 2250 return; 2251 2252 hres = IActiveScript_QueryInterface(engine, &IID_IActiveScriptParse, (void**)&parser); 2253 ok(hres == S_OK, "Could not get IActiveScriptParse: %08x\n", hres); 2254 if (FAILED(hres)) 2255 { 2256 IActiveScript_Release(engine); 2257 return; 2258 } 2259 2260 hres = IActiveScriptParse_InitNew(parser); 2261 ok(hres == S_OK, "InitNew failed: %08x\n", hres); 2262 2263 hres = IActiveScript_SetScriptSite(engine, &ActiveScriptSite); 2264 ok(hres == S_OK, "SetScriptSite failed: %08x\n", hres); 2265 2266 if(global_members) 2267 SET_EXPECT(GetItemInfo_testVal); 2268 hres = IActiveScript_AddNamedItem(engine, test_valW, 2269 SCRIPTITEM_ISVISIBLE|SCRIPTITEM_ISSOURCE| 2270 (global_members ? SCRIPTITEM_GLOBALMEMBERS : 0)); 2271 ok(hres == S_OK, "AddNamedItem failed: %08x\n", hres); 2272 if(global_members) 2273 CHECK_CALLED(GetItemInfo_testVal); 2274 2275 hres = IActiveScript_SetScriptState(engine, SCRIPTSTATE_STARTED); 2276 ok(hres == S_OK, "SetScriptState(SCRIPTSTATE_STARTED) failed: %08x\n", hres); 2277 2278 if(!global_members) 2279 SET_EXPECT(GetItemInfo_testVal); 2280 hres = IActiveScriptParse_ParseScriptText(parser, script_textW, NULL, NULL, NULL, 0, 0, 0, NULL, NULL); 2281 ok(hres == S_OK, "ParseScriptText failed: %08x\n", hres); 2282 if(!global_members) 2283 CHECK_CALLED(GetItemInfo_testVal); 2284 2285 hres = IActiveScriptParse_ParseScriptText(parser, script_textW, NULL, NULL, NULL, 0, 0, 0, NULL, NULL); 2286 ok(hres == S_OK, "ParseScriptText failed: %08x\n", hres); 2287 2288 IActiveScript_Release(engine); 2289 IActiveScriptParse_Release(parser); 2290 } 2291 2292 static void test_start(void) 2293 { 2294 IActiveScriptParse *parser; 2295 IActiveScript *engine; 2296 BSTR str; 2297 HRESULT hres; 2298 2299 script_engine = engine = create_script(); 2300 if(!engine) 2301 return; 2302 2303 hres = IActiveScript_QueryInterface(engine, &IID_IActiveScriptParse, (void**)&parser); 2304 ok(hres == S_OK, "Could not get IActiveScriptParse: %08x\n", hres); 2305 2306 hres = IActiveScriptParse_InitNew(parser); 2307 ok(hres == S_OK, "InitNew failed: %08x\n", hres); 2308 2309 hres = IActiveScript_SetScriptSite(engine, &ActiveScriptSite); 2310 ok(hres == S_OK, "SetScriptSite failed: %08x\n", hres); 2311 2312 hres = IActiveScript_AddNamedItem(engine, testW, SCRIPTITEM_ISVISIBLE|SCRIPTITEM_ISSOURCE|SCRIPTITEM_GLOBALMEMBERS); 2313 ok(hres == S_OK, "AddNamedItem failed: %08x\n", hres); 2314 2315 str = a2bstr("ok(getScriptState() === 5, \"getScriptState = \" + getScriptState());\n" 2316 "reportSuccess();"); 2317 hres = IActiveScriptParse_ParseScriptText(parser, str, NULL, NULL, NULL, 0, 0, 0, NULL, NULL); 2318 ok(hres == S_OK, "ParseScriptText failed: %08x\n", hres); 2319 SysFreeString(str); 2320 2321 SET_EXPECT(global_success_d); 2322 SET_EXPECT(global_success_i); 2323 hres = IActiveScript_SetScriptState(engine, SCRIPTSTATE_STARTED); 2324 ok(hres == S_OK, "SetScriptState(SCRIPTSTATE_STARTED) failed: %08x\n", hres); 2325 CHECK_CALLED(global_success_d); 2326 CHECK_CALLED(global_success_i); 2327 2328 IActiveScript_Release(engine); 2329 IActiveScriptParse_Release(parser); 2330 script_engine = NULL; 2331 } 2332 2333 static void test_automagic(void) 2334 { 2335 IActiveScriptParse *parser; 2336 IActiveScript *engine; 2337 BSTR str; 2338 HRESULT hres; 2339 2340 script_engine = engine = create_script(); 2341 if(!engine) 2342 return; 2343 2344 hres = IActiveScript_QueryInterface(engine, &IID_IActiveScriptParse, (void**)&parser); 2345 ok(hres == S_OK, "Could not get IActiveScriptParse: %08x\n", hres); 2346 2347 hres = IActiveScriptParse_InitNew(parser); 2348 ok(hres == S_OK, "InitNew failed: %08x\n", hres); 2349 2350 hres = IActiveScript_SetScriptSite(engine, &ActiveScriptSite); 2351 ok(hres == S_OK, "SetScriptSite failed: %08x\n", hres); 2352 2353 hres = IActiveScript_AddNamedItem(engine, testW, SCRIPTITEM_ISVISIBLE|SCRIPTITEM_ISSOURCE|SCRIPTITEM_GLOBALMEMBERS); 2354 ok(hres == S_OK, "AddNamedItem failed: %08x\n", hres); 2355 2356 str = a2bstr("function bindEventHandler::eventName() {}\n" 2357 "reportSuccess();"); 2358 hres = IActiveScriptParse_ParseScriptText(parser, str, NULL, NULL, NULL, 0, 0, 0, NULL, NULL); 2359 ok(hres == S_OK, "ParseScriptText failed: %08x\n", hres); 2360 SysFreeString(str); 2361 2362 SET_EXPECT(BindHandler); 2363 SET_EXPECT(global_success_d); 2364 SET_EXPECT(global_success_i); 2365 hres = IActiveScript_SetScriptState(engine, SCRIPTSTATE_STARTED); 2366 ok(hres == S_OK, "SetScriptState(SCRIPTSTATE_STARTED) failed: %08x\n", hres); 2367 CHECK_CALLED(BindHandler); 2368 CHECK_CALLED(global_success_d); 2369 CHECK_CALLED(global_success_i); 2370 2371 IActiveScript_Release(engine); 2372 IActiveScriptParse_Release(parser); 2373 script_engine = NULL; 2374 } 2375 2376 static HRESULT parse_script_expr(const char *expr, VARIANT *res, IActiveScript **engine_ret) 2377 { 2378 IActiveScriptParse *parser; 2379 IActiveScript *engine; 2380 BSTR str; 2381 HRESULT hres; 2382 2383 engine = create_script(); 2384 if(!engine) 2385 return E_FAIL; 2386 2387 hres = IActiveScript_QueryInterface(engine, &IID_IActiveScriptParse, (void**)&parser); 2388 ok(hres == S_OK, "Could not get IActiveScriptParse: %08x\n", hres); 2389 2390 hres = IActiveScriptParse_InitNew(parser); 2391 ok(hres == S_OK, "InitNew failed: %08x\n", hres); 2392 2393 hres = IActiveScript_SetScriptSite(engine, &ActiveScriptSite); 2394 ok(hres == S_OK, "SetScriptSite failed: %08x\n", hres); 2395 2396 SET_EXPECT(GetItemInfo_testVal); 2397 hres = IActiveScript_AddNamedItem(engine, test_valW, 2398 SCRIPTITEM_ISVISIBLE|SCRIPTITEM_ISSOURCE|SCRIPTITEM_GLOBALMEMBERS); 2399 ok(hres == S_OK, "AddNamedItem failed: %08x\n", hres); 2400 CHECK_CALLED(GetItemInfo_testVal); 2401 2402 hres = IActiveScript_SetScriptState(engine, SCRIPTSTATE_STARTED); 2403 ok(hres == S_OK, "SetScriptState(SCRIPTSTATE_STARTED) failed: %08x\n", hres); 2404 2405 str = a2bstr(expr); 2406 hres = IActiveScriptParse_ParseScriptText(parser, str, NULL, NULL, NULL, 0, 0, SCRIPTTEXT_ISEXPRESSION, res, NULL); 2407 SysFreeString(str); 2408 2409 IActiveScriptParse_Release(parser); 2410 2411 if(engine_ret) { 2412 *engine_ret = engine; 2413 }else { 2414 IActiveScript_Close(engine); 2415 IActiveScript_Release(engine); 2416 } 2417 return hres; 2418 } 2419 2420 static void test_retval(void) 2421 { 2422 BSTR str = a2bstr("reportSuccess(), true"); 2423 IActiveScriptParse *parser; 2424 IActiveScript *engine; 2425 SCRIPTSTATE state; 2426 VARIANT res; 2427 HRESULT hres; 2428 2429 engine = create_script(); 2430 if(!engine) 2431 return; 2432 2433 hres = IActiveScript_QueryInterface(engine, &IID_IActiveScriptParse, (void**)&parser); 2434 ok(hres == S_OK, "Could not get IActiveScriptParse: %08x\n", hres); 2435 2436 hres = IActiveScriptParse_InitNew(parser); 2437 ok(hres == S_OK, "InitNew failed: %08x\n", hres); 2438 2439 hres = IActiveScript_SetScriptSite(engine, &ActiveScriptSite); 2440 ok(hres == S_OK, "SetScriptSite failed: %08x\n", hres); 2441 2442 SET_EXPECT(GetItemInfo_testVal); 2443 hres = IActiveScript_AddNamedItem(engine, test_valW, 2444 SCRIPTITEM_ISVISIBLE|SCRIPTITEM_ISSOURCE|SCRIPTITEM_GLOBALMEMBERS); 2445 ok(hres == S_OK, "AddNamedItem failed: %08x\n", hres); 2446 CHECK_CALLED(GetItemInfo_testVal); 2447 2448 V_VT(&res) = VT_NULL; 2449 SET_EXPECT(global_success_d); 2450 SET_EXPECT(global_success_i); 2451 hres = IActiveScriptParse_ParseScriptText(parser, str, NULL, NULL, NULL, 0, 0, 0, &res, NULL); 2452 CHECK_CALLED(global_success_d); 2453 CHECK_CALLED(global_success_i); 2454 ok(hres == S_OK, "ParseScriptText failed: %08x\n", hres); 2455 ok(V_VT(&res) == VT_EMPTY, "V_VT(&res) = %d\n", V_VT(&res)); 2456 2457 hres = IActiveScript_GetScriptState(engine, &state); 2458 ok(hres == S_OK, "GetScriptState failed: %08x\n", hres); 2459 ok(state == SCRIPTSTATE_INITIALIZED, "state = %d\n", state); 2460 2461 hres = IActiveScript_SetScriptState(engine, SCRIPTSTATE_STARTED); 2462 ok(hres == S_OK, "SetScriptState(SCRIPTSTATE_STARTED) failed: %08x\n", hres); 2463 2464 hres = IActiveScript_Close(engine); 2465 ok(hres == S_OK, "Close failed: %08x\n", hres); 2466 2467 IActiveScriptParse_Release(parser); 2468 IActiveScript_Release(engine); 2469 SysFreeString(str); 2470 } 2471 2472 static void test_default_value(void) 2473 { 2474 DISPPARAMS dp = {0}; 2475 IDispatch *disp; 2476 VARIANT v; 2477 HRESULT hres; 2478 2479 hres = parse_script_expr("new Date()", &v, NULL); 2480 ok(hres == S_OK, "parse_script_expr failed: %08x\n", hres); 2481 ok(V_VT(&v) == VT_DISPATCH, "V_VT(v) = %d\n", V_VT(&v)); 2482 disp = V_DISPATCH(&v); 2483 2484 V_VT(&v) = VT_EMPTY; 2485 hres = IDispatch_Invoke(disp, DISPID_VALUE, &IID_NULL, 0, DISPATCH_PROPERTYGET, &dp, &v, NULL, NULL); 2486 ok(hres == S_OK || broken(hres == 0x8000ffff), "Invoke failed: %08x\n", hres); 2487 if(hres == S_OK) 2488 { 2489 ok(V_VT(&v) == VT_BSTR, "V_VT(v) = %d\n", V_VT(&v)); 2490 } 2491 2492 VariantClear(&v); 2493 IDispatch_Release(disp); 2494 } 2495 2496 static void test_script_exprs(void) 2497 { 2498 VARIANT v; 2499 HRESULT hres; 2500 2501 testing_expr = TRUE; 2502 2503 hres = parse_script_expr("true", &v, NULL); 2504 ok(hres == S_OK, "parse_script_expr failed: %08x\n", hres); 2505 ok(V_VT(&v) == VT_BOOL, "V_VT(v) = %d\n", V_VT(&v)); 2506 ok(V_BOOL(&v) == VARIANT_TRUE, "V_BOOL(v) = %x\n", V_BOOL(&v)); 2507 2508 hres = parse_script_expr("false, true", &v, NULL); 2509 ok(hres == S_OK, "parse_script_expr failed: %08x\n", hres); 2510 ok(V_VT(&v) == VT_BOOL, "V_VT(v) = %d\n", V_VT(&v)); 2511 ok(V_BOOL(&v) == VARIANT_TRUE, "V_BOOL(v) = %x\n", V_BOOL(&v)); 2512 2513 SET_EXPECT(global_success_d); 2514 SET_EXPECT(global_success_i); 2515 hres = parse_script_expr("reportSuccess(); true", &v, NULL); 2516 ok(hres == S_OK, "parse_script_expr failed: %08x\n", hres); 2517 ok(V_VT(&v) == VT_BOOL, "V_VT(v) = %d\n", V_VT(&v)); 2518 ok(V_BOOL(&v) == VARIANT_TRUE, "V_BOOL(v) = %x\n", V_BOOL(&v)); 2519 CHECK_CALLED(global_success_d); 2520 CHECK_CALLED(global_success_i); 2521 2522 hres = parse_script_expr("if(false) true", &v, NULL); 2523 ok(hres == S_OK, "parse_script_expr failed: %08x\n", hres); 2524 ok(V_VT(&v) == VT_EMPTY, "V_VT(v) = %d\n", V_VT(&v)); 2525 2526 hres = parse_script_expr("return testPropGet", &v, NULL); 2527 ok(hres == 0x800a03fa, "parse_script_expr failed: %08x\n", hres); 2528 2529 hres = parse_script_expr("reportSuccess(); return true", &v, NULL); 2530 ok(hres == 0x800a03fa, "parse_script_expr failed: %08x\n", hres); 2531 2532 SET_EXPECT(global_success_d); 2533 SET_EXPECT(global_success_i); 2534 hres = parse_script_expr("reportSuccess(); true", NULL, NULL); 2535 ok(hres == S_OK, "parse_script_expr failed: %08x\n", hres); 2536 CHECK_CALLED(global_success_d); 2537 CHECK_CALLED(global_success_i); 2538 2539 test_default_value(); 2540 test_retval(); 2541 2542 testing_expr = FALSE; 2543 } 2544 2545 static void test_invokeex(void) 2546 { 2547 DISPID func_id, prop_id; 2548 DISPPARAMS dp = {NULL}; 2549 IActiveScript *script; 2550 IDispatchEx *dispex; 2551 VARIANT v; 2552 BSTR str; 2553 HRESULT hres; 2554 2555 hres = parse_script_expr("var o = {func: function() {return 3;}, prop: 6}; o", &v, &script); 2556 ok(hres == S_OK, "parse_script_expr failed: %08x\n", hres); 2557 ok(V_VT(&v) == VT_DISPATCH, "V_VT(v) = %d\n", V_VT(&v)); 2558 2559 hres = IDispatch_QueryInterface(V_DISPATCH(&v), &IID_IDispatchEx, (void**)&dispex); 2560 ok(hres == S_OK, "Could not get IDispatchEx iface: %08x\n", hres); 2561 VariantClear(&v); 2562 2563 str = a2bstr("func"); 2564 hres = IDispatchEx_GetDispID(dispex, str, 0, &func_id); 2565 SysFreeString(str); 2566 ok(hres == S_OK, "GetDispID failed: %08x\n", hres); 2567 2568 str = a2bstr("prop"); 2569 hres = IDispatchEx_GetDispID(dispex, str, 0, &prop_id); 2570 SysFreeString(str); 2571 ok(hres == S_OK, "GetDispID failed: %08x\n", hres); 2572 2573 hres = IDispatchEx_InvokeEx(dispex, func_id, 0, DISPATCH_METHOD, &dp, &v, NULL, NULL); 2574 ok(hres == S_OK, "InvokeEx failed: %08x\n", hres); 2575 ok(V_VT(&v) == VT_I4, "V_VT(v) = %d\n", V_VT(&v)); 2576 ok(V_I4(&v) == 3, "V_I4(v) = %d\n", V_I4(&v)); 2577 2578 hres = IDispatchEx_InvokeEx(dispex, prop_id, 0, DISPATCH_PROPERTYGET, &dp, &v, NULL, NULL); 2579 ok(hres == S_OK, "InvokeEx failed: %08x\n", hres); 2580 ok(V_VT(&v) == VT_I4, "V_VT(v) = %d\n", V_VT(&v)); 2581 ok(V_I4(&v) == 6, "V_I4(v) = %d\n", V_I4(&v)); 2582 2583 hres = IActiveScript_SetScriptState(script, SCRIPTSTATE_UNINITIALIZED); 2584 ok(hres == S_OK, "SetScriptState(SCRIPTSTATE_STARTED) failed: %08x\n", hres); 2585 2586 str = a2bstr("func"); 2587 hres = IDispatchEx_GetDispID(dispex, str, 0, &func_id); 2588 SysFreeString(str); 2589 ok(hres == S_OK, "GetDispID failed: %08x\n", hres); 2590 2591 hres = IDispatchEx_InvokeEx(dispex, func_id, 0, DISPATCH_METHOD, &dp, &v, NULL, NULL); 2592 ok(hres == E_UNEXPECTED || broken(hres == 0x800a1393), "InvokeEx failed: %08x\n", hres); 2593 2594 hres = IDispatchEx_InvokeEx(dispex, prop_id, 0, DISPATCH_PROPERTYGET, &dp, &v, NULL, NULL); 2595 ok(hres == S_OK, "InvokeEx failed: %08x\n", hres); 2596 ok(V_VT(&v) == VT_I4, "V_VT(v) = %d\n", V_VT(&v)); 2597 ok(V_I4(&v) == 6, "V_I4(v) = %d\n", V_I4(&v)); 2598 2599 IDispatchEx_Release(dispex); 2600 IActiveScript_Release(script); 2601 } 2602 2603 static void test_eval(void) 2604 { 2605 IActiveScriptParse *parser; 2606 IDispatchEx *script_dispex; 2607 IDispatch *script_disp; 2608 IActiveScript *engine; 2609 VARIANT arg, res; 2610 DISPPARAMS params; 2611 DISPID id, v_id; 2612 BSTR str; 2613 HRESULT hres; 2614 2615 engine = create_script(); 2616 2617 hres = IActiveScript_QueryInterface(engine, &IID_IActiveScriptParse, (void**)&parser); 2618 ok(hres == S_OK, "Could not get IActiveScriptParse: %08x\n", hres); 2619 2620 hres = IActiveScriptParse_InitNew(parser); 2621 ok(hres == S_OK, "InitNew failed: %08x\n", hres); 2622 2623 hres = IActiveScript_SetScriptSite(engine, &ActiveScriptSite); 2624 ok(hres == S_OK, "SetScriptSite failed: %08x\n", hres); 2625 2626 SET_EXPECT(GetItemInfo_testVal); 2627 hres = IActiveScript_AddNamedItem(engine, test_valW, 2628 SCRIPTITEM_ISVISIBLE|SCRIPTITEM_ISSOURCE|SCRIPTITEM_GLOBALMEMBERS); 2629 ok(hres == S_OK, "AddNamedItem failed: %08x\n", hres); 2630 CHECK_CALLED(GetItemInfo_testVal); 2631 2632 hres = IActiveScript_SetScriptState(engine, SCRIPTSTATE_STARTED); 2633 ok(hres == S_OK, "SetScriptState(SCRIPTSTATE_STARTED) failed: %08x\n", hres); 2634 2635 hres = IActiveScript_GetScriptDispatch(engine, NULL, &script_disp); 2636 ok(hres == S_OK, "GetScriptDispatch failed: %08x\n", hres); 2637 ok(script_disp != NULL, "script_disp == NULL\n"); 2638 2639 hres = IDispatch_QueryInterface(script_disp, &IID_IDispatchEx, (void**)&script_dispex); 2640 ok(hres == S_OK, "Could not get IDispatchEx iface: %08x\n", hres); 2641 IDispatch_Release(script_disp); 2642 2643 str = a2bstr("eval"); 2644 hres = IDispatchEx_GetDispID(script_dispex, str, 0, &id); 2645 ok(hres == S_OK, "Could not get eval dispid: %08x\n", hres); 2646 SysFreeString(str); 2647 2648 params.rgvarg = &arg; 2649 params.rgdispidNamedArgs = NULL; 2650 params.cArgs = 1; 2651 params.cNamedArgs = 0; 2652 V_VT(&arg) = VT_BSTR; 2653 2654 V_BSTR(&arg) = a2bstr("var v = 1;"); 2655 V_VT(&res) = VT_ERROR; 2656 hres = IDispatchEx_InvokeEx(script_dispex, id, 0, DISPATCH_METHOD, ¶ms, &res, NULL, NULL); 2657 ok(hres == S_OK, "InvokeEx failed: %08x\n", hres); 2658 ok(V_VT(&res) == VT_EMPTY, "eval returned type %u\n", V_VT(&res)); 2659 SysFreeString(V_BSTR(&arg)); 2660 2661 V_BSTR(&arg) = a2bstr("v"); 2662 V_VT(&res) = VT_ERROR; 2663 hres = IDispatchEx_InvokeEx(script_dispex, id, 0, DISPATCH_METHOD, ¶ms, &res, NULL, NULL); 2664 ok(hres == S_OK, "InvokeEx failed: %08x\n", hres); 2665 ok(V_VT(&res) == VT_I4, "eval returned type %u\n", V_VT(&res)); 2666 ok(V_I4(&res) == 1, "eval returned %d\n", V_I4(&res)); 2667 SysFreeString(V_BSTR(&arg)); 2668 2669 str = a2bstr("v"); 2670 hres = IDispatchEx_GetDispID(script_dispex, str, 0, &v_id); 2671 ok(hres == S_OK, "Could not get v dispid: %08x\n", hres); 2672 SysFreeString(str); 2673 2674 params.rgvarg = NULL; 2675 params.cArgs = 0; 2676 V_VT(&res) = VT_ERROR; 2677 hres = IDispatchEx_InvokeEx(script_dispex, v_id, 0, DISPATCH_PROPERTYGET, ¶ms, &res, NULL, NULL); 2678 ok(hres == S_OK, "InvokeEx failed: %08x\n", hres); 2679 ok(V_VT(&res) == VT_I4, "eval returned type %u\n", V_VT(&res)); 2680 ok(V_I4(&res) == 1, "eval returned %d\n", V_I4(&res)); 2681 2682 SET_EXPECT(global_calleval_i); 2683 str = a2bstr("(function(){" 2684 " var v = 2;" 2685 " callEval(eval);" 2686 " ok(x === 5, 'x = ' + x);" 2687 "})();"); 2688 hres = IActiveScriptParse_ParseScriptText(parser, str, NULL, NULL, NULL, 0, 0, 0, NULL, NULL); 2689 ok(hres == S_OK, "ParseScriptText failed: %08x\n", hres); 2690 SysFreeString(str); 2691 CHECK_CALLED(global_calleval_i); 2692 2693 str = a2bstr("x"); 2694 hres = IDispatchEx_GetDispID(script_dispex, str, 0, &id); 2695 ok(hres == DISP_E_UNKNOWNNAME, "GetDispID(x) returned %08x\n", hres); 2696 SysFreeString(str); 2697 2698 IDispatchEx_Release(script_dispex); 2699 IActiveScriptParse_Release(parser); 2700 IActiveScript_Close(engine); 2701 IActiveScript_Release(engine); 2702 } 2703 2704 struct bom_test 2705 { 2706 WCHAR str[1024]; 2707 HRESULT hres; 2708 }; 2709 2710 static void run_bom_tests(void) 2711 { 2712 BSTR src; 2713 int i; 2714 HRESULT hres; 2715 struct bom_test bom_tests[] = { 2716 {{'v','a','r',' ','a',' ','=',' ','1',';',' ','r','e','p','o','r','t','S','u','c','c','e','s','s','(',')',';','\0'}, S_OK}, 2717 {{0xFEFF,'v','a','r',' ','a',' ','=',' ','1',';',' ','r','e','p','o','r','t','S','u','c','c','e','s','s','(',')',';','\0'}, S_OK}, 2718 {{'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}, 2719 {{'v','a','r',0xFEFF,' ','a',' ','=',' ','1',';',' ','r','e','p','o','r','t','S','u','c','c','e','s','s','(',')',';','\0'}, S_OK}, 2720 {{'v','a','r',' ','a',' ','=',' ','1',';',' ',0xFEFF,'r','e','p','o','r','t','S','u','c','c','e','s','s','(',')',';','\0'}, S_OK}, 2721 {{'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}, 2722 {{'v','a','r',' ','a',' ','=',' ','1',';',' ','r','e','p','o','r','t','S','u','c','c','e','s','s',0xFEFF,'(',')',';','\0'}, S_OK}, 2723 {{'v','a','r',' ','a',' ','=',' ','1',';',' ','r','e','p','o','r','t','S','u','c','c','e','s','s','(',0xFEFF,')',';','\0'}, S_OK}, 2724 {{'v','a','r',' ','a',' ','=',0xFEFF,' ','1',';',' ','r','e','p','o','r','t','S','u','c','c','e','s','s','(',0xFEFF,')',';','\0'}, S_OK}, 2725 {{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}, 2726 {{0}} 2727 }; 2728 2729 engine_clsid = &CLSID_JScript; 2730 2731 for (i = 0; bom_tests[i].str[0]; i++) 2732 { 2733 if(bom_tests[i].hres == S_OK) 2734 { 2735 SET_EXPECT(global_success_d); 2736 SET_EXPECT(global_success_i); 2737 src = SysAllocString(bom_tests[i].str); 2738 hres = parse_script(SCRIPTITEM_GLOBALMEMBERS, src); 2739 ok(hres == S_OK, "test %s failed with %08x\n", wine_dbgstr_w(src), hres); 2740 SysFreeString(src); 2741 CHECK_CALLED(global_success_d); 2742 CHECK_CALLED(global_success_i); 2743 } 2744 else 2745 { 2746 src = SysAllocString(bom_tests[i].str); 2747 hres = parse_script(SCRIPTITEM_GLOBALMEMBERS, src); 2748 todo_wine ok(hres == bom_tests[i].hres, "test %s returned with %08x\n", wine_dbgstr_w(src), hres); 2749 SysFreeString(src); 2750 } 2751 } 2752 } 2753 2754 static BOOL run_tests(void) 2755 { 2756 HRESULT hres; 2757 2758 if(invoke_version) { 2759 IActiveScript *script; 2760 2761 script = create_script(); 2762 if(!script) { 2763 win_skip("Could not create script\n"); 2764 return FALSE; 2765 } 2766 IActiveScript_Release(script); 2767 } 2768 2769 strict_dispid_check = TRUE; 2770 2771 parse_script_a(""); 2772 parse_script_a("/* empty */ ;"); 2773 2774 SET_EXPECT(global_propget_d); 2775 SET_EXPECT(global_propget_i); 2776 parse_script_a("testPropGet;"); 2777 CHECK_CALLED(global_propget_d); 2778 CHECK_CALLED(global_propget_i); 2779 2780 SET_EXPECT(global_propput_d); 2781 SET_EXPECT(global_propput_i); 2782 parse_script_a("testPropPut = 1;"); 2783 CHECK_CALLED(global_propput_d); 2784 CHECK_CALLED(global_propput_i); 2785 2786 SET_EXPECT(global_propputref_d); 2787 SET_EXPECT(global_propputref_i); 2788 parse_script_a("testPropPutRef = new Object();"); 2789 CHECK_CALLED(global_propputref_d); 2790 CHECK_CALLED(global_propputref_i); 2791 2792 SET_EXPECT(global_propputref_d); 2793 SET_EXPECT(global_propputref_i); 2794 parse_script_a("testPropPutRef = testObj;"); 2795 CHECK_CALLED(global_propputref_d); 2796 CHECK_CALLED(global_propputref_i); 2797 2798 SET_EXPECT(global_success_d); 2799 SET_EXPECT(global_success_i); 2800 parse_script_a("reportSuccess();"); 2801 CHECK_CALLED(global_success_d); 2802 CHECK_CALLED(global_success_i); 2803 2804 SET_EXPECT(testobj_delete_test); 2805 parse_script_a("ok((delete testObj.deleteTest) === true, 'delete testObj.deleteTest did not return true');"); 2806 CHECK_CALLED(testobj_delete_test); 2807 2808 SET_EXPECT(testobj_delete_nodelete); 2809 parse_script_a("ok((delete testObj.noDeleteTest) === false, 'delete testObj.noDeleteTest did not return false');"); 2810 CHECK_CALLED(testobj_delete_nodelete); 2811 2812 SET_EXPECT(global_propdelete_d); 2813 SET_EXPECT(DeleteMemberByDispID); 2814 parse_script_a("ok((delete testPropDelete) === true, 'delete testPropDelete did not return true');"); 2815 CHECK_CALLED(global_propdelete_d); 2816 CHECK_CALLED(DeleteMemberByDispID); 2817 2818 SET_EXPECT(global_nopropdelete_d); 2819 SET_EXPECT(DeleteMemberByDispID_false); 2820 parse_script_a("ok((delete testNoPropDelete) === false, 'delete testPropDelete did not return false');"); 2821 CHECK_CALLED(global_nopropdelete_d); 2822 CHECK_CALLED(DeleteMemberByDispID_false); 2823 2824 SET_EXPECT(global_propdeleteerror_d); 2825 SET_EXPECT(DeleteMemberByDispID_error); 2826 parse_script_ae("delete testPropDeleteError;", E_FAIL); 2827 CHECK_CALLED(global_propdeleteerror_d); 2828 CHECK_CALLED(DeleteMemberByDispID_error); 2829 2830 SET_EXPECT(puredisp_prop_d); 2831 parse_script_a("ok((delete pureDisp.prop) === false, 'delete pureDisp.prop did not return true');"); 2832 CHECK_CALLED(puredisp_prop_d); 2833 2834 SET_EXPECT(puredisp_noprop_d); 2835 parse_script_a("ok((delete pureDisp.noprop) === true, 'delete pureDisp.noprop did not return false');"); 2836 CHECK_CALLED(puredisp_noprop_d); 2837 2838 SET_EXPECT(puredisp_value); 2839 parse_script_a("var t=pureDisp; t=t(false);"); 2840 CHECK_CALLED(puredisp_value); 2841 2842 SET_EXPECT(puredisp_value); 2843 parse_script_a("var t = {func: pureDisp}; t = t.func(false);"); 2844 CHECK_CALLED(puredisp_value); 2845 2846 SET_EXPECT(dispexfunc_value); 2847 parse_script_a("var t = dispexFunc; t = t(false);"); 2848 CHECK_CALLED(dispexfunc_value); 2849 2850 SET_EXPECT(dispexfunc_value); 2851 parse_script_a("var t = {func: dispexFunc}; t = t.func(false);"); 2852 CHECK_CALLED(dispexfunc_value); 2853 2854 SET_EXPECT(dispexfunc_value); 2855 parse_script_a("Function.prototype.apply.call(dispexFunc, testObj, [true]);"); 2856 CHECK_CALLED(dispexfunc_value); 2857 2858 SET_EXPECT(puredisp_value); 2859 parse_script_a("Function.prototype.apply.call(pureDisp, testObj, [true]);"); 2860 CHECK_CALLED(puredisp_value); 2861 2862 parse_script_a("(function reportSuccess() {})()"); 2863 2864 parse_script_a("ok(typeof(test) === 'object', \"typeof(test) != 'object'\");"); 2865 2866 parse_script_a("function reportSuccess() {}; reportSuccess();"); 2867 2868 SET_EXPECT(global_propget_d); 2869 parse_script_a("var testPropGet"); 2870 CHECK_CALLED(global_propget_d); 2871 2872 SET_EXPECT(global_propget_d); 2873 parse_script_a("eval('var testPropGet;');"); 2874 CHECK_CALLED(global_propget_d); 2875 2876 parse_script_a("var testPropGet; function testPropGet() {}"); 2877 2878 SET_EXPECT(global_notexists_d); 2879 parse_script_a("var notExists; notExists = 1;"); 2880 CHECK_CALLED(global_notexists_d); 2881 2882 SET_EXPECT(testobj_notexists_d); 2883 parse_script_a("testObj.notExists;"); 2884 CHECK_CALLED(testobj_notexists_d); 2885 2886 parse_script_a("function f() { var testPropGet; }"); 2887 parse_script_a("(function () { var testPropGet; })();"); 2888 parse_script_a("(function () { eval('var testPropGet;'); })();"); 2889 2890 SET_EXPECT(invoke_func); 2891 parse_script_a("ok(propGetFunc() == 0, \"Incorrect propGetFunc value\");"); 2892 CHECK_CALLED(invoke_func); 2893 parse_script_a("ok(propGetFunc(1) == 1, \"Incorrect propGetFunc value\");"); 2894 parse_script_a("ok(propGetFunc(1, 2) == 2, \"Incorrect propGetFunc value\");"); 2895 SET_EXPECT(invoke_func); 2896 parse_script_a("ok(propGetFunc().toString() == 0, \"Incorrect propGetFunc value\");"); 2897 CHECK_CALLED(invoke_func); 2898 parse_script_a("ok(propGetFunc(1).toString() == 1, \"Incorrect propGetFunc value\");"); 2899 SET_EXPECT(invoke_func); 2900 parse_script_a("propGetFunc(1);"); 2901 CHECK_CALLED(invoke_func); 2902 2903 parse_script_a("objectFlag(1).toString();"); 2904 2905 parse_script_a("(function() { var tmp = (function () { return testObj; })()(1);})();"); 2906 parse_script_a("(function() { var tmp = (function () { return testObj; })()();})();"); 2907 2908 parse_script_a("ok((testObj instanceof Object) === false, 'testObj is instance of Object');"); 2909 2910 SET_EXPECT(testobj_prop_d); 2911 parse_script_a("ok(('prop' in testObj) === true, 'prop is not in testObj');"); 2912 CHECK_CALLED(testobj_prop_d); 2913 2914 SET_EXPECT(testobj_noprop_d); 2915 parse_script_a("ok(('noprop' in testObj) === false, 'noprop is in testObj');"); 2916 CHECK_CALLED(testobj_noprop_d); 2917 2918 SET_EXPECT(testobj_prop_d); 2919 parse_script_a("ok(Object.prototype.hasOwnProperty.call(testObj, 'prop') === true, 'hasOwnProperty(\\\"prop\\\") returned false');"); 2920 CHECK_CALLED(testobj_prop_d); 2921 2922 SET_EXPECT(testobj_noprop_d); 2923 parse_script_a("ok(Object.prototype.hasOwnProperty.call(testObj, 'noprop') === false, 'hasOwnProperty(\\\"noprop\\\") returned true');"); 2924 CHECK_CALLED(testobj_noprop_d); 2925 2926 SET_EXPECT(puredisp_prop_d); 2927 parse_script_a("ok(Object.prototype.hasOwnProperty.call(pureDisp, 'prop') === true, 'hasOwnProperty(\\\"noprop\\\") returned false');"); 2928 CHECK_CALLED(puredisp_prop_d); 2929 2930 SET_EXPECT(puredisp_noprop_d); 2931 parse_script_a("ok(Object.prototype.hasOwnProperty.call(pureDisp, 'noprop') === false, 'hasOwnProperty(\\\"noprop\\\") returned true');"); 2932 CHECK_CALLED(puredisp_noprop_d); 2933 2934 SET_EXPECT(testobj_value); 2935 parse_script_a("ok(String(testObj) === '1', 'wrong testObj value');"); 2936 CHECK_CALLED(testobj_value); 2937 2938 SET_EXPECT(testobj_value); 2939 parse_script_a("ok(String.prototype.concat.call(testObj, ' OK') === '1 OK', 'wrong concat result');"); 2940 CHECK_CALLED(testobj_value); 2941 2942 SET_EXPECT(testobj_construct); 2943 parse_script_a("var t = new testObj(1);"); 2944 CHECK_CALLED(testobj_construct); 2945 2946 SET_EXPECT(global_propget_d); 2947 SET_EXPECT(global_propget_i); 2948 parse_script_a("this.testPropGet;"); 2949 CHECK_CALLED(global_propget_d); 2950 CHECK_CALLED(global_propget_i); 2951 2952 SET_EXPECT(global_propputref_d); 2953 SET_EXPECT(global_propputref_i); 2954 parse_script_a("testPropPutRef = nullDisp;"); 2955 CHECK_CALLED(global_propputref_d); 2956 CHECK_CALLED(global_propputref_i); 2957 2958 SET_EXPECT(global_propget_d); 2959 SET_EXPECT(global_propget_i); 2960 parse_script_a("(function () { this.testPropGet; })();"); 2961 CHECK_CALLED(global_propget_d); 2962 CHECK_CALLED(global_propget_i); 2963 2964 parse_script_a("testThis(this);"); 2965 parse_script_a("(function () { testThis(this); })();"); 2966 parse_script_a("function x() { testThis(this); }; x();"); 2967 parse_script_a("var t = {func: function () { ok(this === t, 'this !== t'); }}; with(t) { func(); }"); 2968 parse_script_a("function x() { testThis(this); }; with({y: 1}) { x(); }"); 2969 parse_script_a("(function () { function x() { testThis(this);} x(); })();"); 2970 2971 SET_EXPECT(testobj_onlydispid_d); 2972 SET_EXPECT(testobj_onlydispid_i); 2973 parse_script_a("ok(typeof(testObj.onlyDispID) === 'unknown', 'unexpected typeof(testObj.onlyDispID)');"); 2974 CHECK_CALLED(testobj_onlydispid_d); 2975 CHECK_CALLED(testobj_onlydispid_i); 2976 2977 SET_EXPECT(global_propargput_d); 2978 SET_EXPECT(global_propargput_i); 2979 parse_script_a("var t=0; propArgPutG(t++, t++) = t++;"); 2980 CHECK_CALLED(global_propargput_d); 2981 CHECK_CALLED(global_propargput_i); 2982 2983 SET_EXPECT(global_propargput_d); 2984 SET_EXPECT(global_propargput_i); 2985 parse_script_a("var t=0; test.propArgPutO(t++, t++) = t++;"); 2986 CHECK_CALLED(global_propargput_d); 2987 CHECK_CALLED(global_propargput_i); 2988 2989 SET_EXPECT(global_propargputop_d); 2990 SET_EXPECT(global_propargputop_get_i); 2991 SET_EXPECT(global_propargputop_put_i); 2992 parse_script_a("var t=0; propArgPutOp(t++, t++) += t++;"); 2993 CHECK_CALLED(global_propargputop_d); 2994 CHECK_CALLED(global_propargputop_get_i); 2995 CHECK_CALLED(global_propargputop_put_i); 2996 2997 SET_EXPECT(global_propargputop_d); 2998 SET_EXPECT(global_propargputop_get_i); 2999 SET_EXPECT(global_propargputop_put_i); 3000 parse_script_a("var t=0; propArgPutOp(t++, t++) ^= 14;"); 3001 CHECK_CALLED(global_propargputop_d); 3002 CHECK_CALLED(global_propargputop_get_i); 3003 CHECK_CALLED(global_propargputop_put_i); 3004 3005 SET_EXPECT(global_testargtypes_i); 3006 parse_script_a("testArgTypes(dispUnk, intProp(), intProp, getShort(), shortProp," 3007 "function(i1,ui1,ui2,r4,i4ref,ui4,nullunk,d,i,s) {" 3008 " ok(getVT(i) === 'VT_I4', 'getVT(i) = ' + getVT(i));" 3009 " ok(getVT(s) === 'VT_I4', 'getVT(s) = ' + getVT(s));" 3010 " ok(getVT(d) === 'VT_DISPATCH', 'getVT(d) = ' + getVT(d));" 3011 " ok(getVT(nullunk) === 'VT_DISPATCH', 'getVT(nullunk) = ' + getVT(nullunk));" 3012 " ok(nullunk === null, 'nullunk !== null');" 3013 " ok(getVT(ui4) === 'VT_R8', 'getVT(ui4) = ' + getVT(ui4));" 3014 " ok(ui4 > 0, 'ui4 = ' + ui4);" 3015 " ok(getVT(i4ref) === 'VT_I4', 'getVT(i4ref) = ' + getVT(i4ref));" 3016 " ok(i4ref === 2, 'i4ref = ' + i4ref);" 3017 " ok(r4 === 0.5, 'r4 = ' + r4);" 3018 " ok(getVT(r4) === 'VT_R8', 'getVT(r4) = ' + getVT(r4));" 3019 " ok(getVT(ui2) === 'VT_I4', 'getVT(ui2) = ' + getVT(ui2));" 3020 " ok(getVT(ui1) === 'VT_I4', 'getVT(ui1) = ' + getVT(ui1));" 3021 " ok(ui1 === 4, 'ui1 = ' + ui1);" 3022 " ok(getVT(i1) === 'VT_I4', 'getVT(i1) = ' + getVT(i1));" 3023 " ok(i1 === 5, 'i1 = ' + i1);" 3024 "});"); 3025 CHECK_CALLED(global_testargtypes_i); 3026 3027 SET_EXPECT(testobj_withprop_d); 3028 SET_EXPECT(testobj_withprop_i); 3029 parse_script_a("var t = (function () { with(testObj) { return withProp; }})(); ok(t === 1, 't = ' + t);"); 3030 CHECK_CALLED(testobj_withprop_d); 3031 CHECK_CALLED(testobj_withprop_i); 3032 3033 parse_script_a("@set @t=2\nok(@t === 2, '@t = ' + @t);"); 3034 3035 SET_EXPECT(global_success_d); 3036 SET_EXPECT(global_success_i); 3037 parse_script_a("@if(true)\nif(@_jscript) reportSuccess();\n@end"); 3038 CHECK_CALLED(global_success_d); 3039 CHECK_CALLED(global_success_i); 3040 3041 EnumVARIANT_index = 0; 3042 EnumVARIANT_next_0_count = 1; 3043 SET_EXPECT(testobj_newenum); 3044 SET_EXPECT(enumvariant_next_0); 3045 parse_script_a("new Enumerator(testObj);"); 3046 CHECK_CALLED(testobj_newenum); 3047 CHECK_CALLED(enumvariant_next_0); 3048 3049 EnumVARIANT_index = 0; 3050 EnumVARIANT_next_0_count = 2; 3051 SET_EXPECT(testobj_newenum); 3052 SET_EXPECT(enumvariant_next_0); 3053 SET_EXPECT(enumvariant_reset); 3054 parse_script_a("(function () {" 3055 " var testEnumObj = new Enumerator(testObj);" 3056 " var tmp = testEnumObj.moveFirst();" 3057 " ok(tmp == undefined, \"testEnumObj.moveFirst() = \" + tmp);" 3058 "})()"); 3059 CHECK_CALLED(testobj_newenum); 3060 CHECK_CALLED(enumvariant_next_0); 3061 CHECK_CALLED(enumvariant_reset); 3062 3063 EnumVARIANT_index = 0; 3064 EnumVARIANT_next_0_count = 1; 3065 SET_EXPECT(testobj_newenum); 3066 SET_EXPECT(enumvariant_next_0); 3067 SET_EXPECT(enumvariant_next_1); 3068 parse_script_a("(function () {" 3069 " var testEnumObj = new Enumerator(testObj);" 3070 " while (!testEnumObj.atEnd())" 3071 " {" 3072 " ok(testEnumObj.item() == 123, " 3073 " \"testEnumObj.item() = \"+testEnumObj.item());" 3074 " testEnumObj.moveNext();" 3075 " }" 3076 "})()"); 3077 CHECK_CALLED(testobj_newenum); 3078 CHECK_CALLED(enumvariant_next_0); 3079 CHECK_CALLED(enumvariant_next_1); 3080 3081 run_from_res("lang.js"); 3082 run_from_res("api.js"); 3083 run_from_res("regexp.js"); 3084 run_from_res("cc.js"); 3085 3086 test_isvisible(FALSE); 3087 test_isvisible(TRUE); 3088 test_start(); 3089 test_automagic(); 3090 3091 parse_script_af(0, "test.testThis2(this);"); 3092 parse_script_af(0, "(function () { test.testThis2(this); })();"); 3093 3094 hres = parse_htmlscript_a("<!--"); 3095 ok(hres == S_OK, "ParseScriptText failed: %08x\n", hres); 3096 hres = parse_htmlscript_a("-->"); 3097 ok(hres == S_OK, "ParseScriptText failed: %08x\n", hres); 3098 hres = parse_htmlscript_a("<!--\nvar a=1;\n-->\n"); 3099 ok(hres == S_OK, "ParseScriptText failed: %08x\n", hres); 3100 hres = parse_htmlscript_a("<!--\n<!-- ignore this\n-->\n"); 3101 ok(hres == S_OK, "ParseScriptText failed: %08x\n", hres); 3102 hres = parse_htmlscript_a("var a=1;\nif(a-->0) a=5;\n"); 3103 ok(hres == S_OK, "ParseScriptText failed: %08x\n", hres); 3104 hres = parse_htmlscript_a("var a=1;\nif(a\n-->0) a=5;\n"); 3105 ok(hres != S_OK, "ParseScriptText have not failed\n"); 3106 3107 test_script_exprs(); 3108 test_invokeex(); 3109 test_eval(); 3110 3111 parse_script_with_error_a( 3112 "?", 3113 0x800a03ea, 0, 0, 3114 "Microsoft JScript compilation error", 3115 "Syntax error", 3116 "?"); 3117 3118 parse_script_with_error_a( 3119 "var a=1;\nif(a\n-->0) a=5;\n", 3120 0x800a03ee, 2, 0, 3121 "Microsoft JScript compilation error", 3122 "Expected ')'", 3123 "-->0) a=5;"); 3124 3125 parse_script_with_error_a( 3126 "new 3;", 3127 0x800a01bd, 0, 0, 3128 "Microsoft JScript runtime error", 3129 "Object doesn't support this action", 3130 NULL); 3131 3132 parse_script_with_error_a( 3133 "new null;", 3134 0x800a138f, 0, 0, 3135 "Microsoft JScript runtime error", 3136 "Object expected", 3137 NULL); 3138 3139 parse_script_with_error_a( 3140 "var a;\nnew null;", 3141 0x800a138f, 1, 0, 3142 "Microsoft JScript runtime error", 3143 "Object expected", 3144 NULL); 3145 3146 parse_script_with_error_a( 3147 "var a; new null;", 3148 0x800a138f, 0, 7, 3149 "Microsoft JScript runtime error", 3150 "Object expected", 3151 NULL); 3152 3153 run_bom_tests(); 3154 3155 return TRUE; 3156 } 3157 3158 static void test_parse_proc(void) 3159 { 3160 VARIANT args[2]; 3161 DISPPARAMS dp = {args}; 3162 3163 dp.cArgs = 0; 3164 invoke_procedure(NULL, "return true;", &dp); 3165 3166 dp.cArgs = 1; 3167 V_VT(args) = VT_EMPTY; 3168 invoke_procedure(NULL, "return arguments.length == 1;", &dp); 3169 3170 V_VT(args) = VT_BOOL; 3171 V_BOOL(args) = VARIANT_TRUE; 3172 invoke_procedure(" x ", "return x;", &dp); 3173 3174 dp.cArgs = 2; 3175 V_VT(args) = VT_I4; 3176 V_I4(args) = 2; 3177 V_VT(args+1) = VT_I4; 3178 V_I4(args+1) = 1; 3179 invoke_procedure(" _x1 , y_2", "return _x1 === 1 && y_2 === 2;", &dp); 3180 } 3181 3182 static void run_encoded_tests(void) 3183 { 3184 BSTR src; 3185 HRESULT hres; 3186 3187 engine_clsid = &CLSID_JScriptEncode; 3188 3189 SET_EXPECT(global_success_d); 3190 SET_EXPECT(global_success_i); 3191 /* |reportSuccess(); | */ 3192 parse_script_a("#@~^EAAAAA==.\x7fwGMYUEm1+kd`*iAQYAAA==^#~@"); 3193 CHECK_CALLED(global_success_d); 3194 CHECK_CALLED(global_success_i); 3195 3196 SET_EXPECT(global_success_d); 3197 SET_EXPECT(global_success_i); 3198 parse_script_a("reportSuccess();"); 3199 CHECK_CALLED(global_success_d); 3200 CHECK_CALLED(global_success_i); 3201 3202 SET_EXPECT(global_success_d); 3203 SET_EXPECT(global_success_i); 3204 /* |Success | */ 3205 parse_script_a("report#@~^BwAAAA==j!m^\x7f/k2QIAAA==^#~@();"); 3206 CHECK_CALLED(global_success_d); 3207 CHECK_CALLED(global_success_i); 3208 3209 SET_EXPECT(global_success_d); 3210 SET_EXPECT(global_success_i); 3211 /* |\r\n\treportSuccess();\r\n | */ 3212 parse_script_a("#@~^GQAAAA==@#@&d.\x7fwKDYUE1^+k/c#p@#@&OAYAAA==^#~@"); 3213 CHECK_CALLED(global_success_d); 3214 CHECK_CALLED(global_success_i); 3215 3216 /* v */ 3217 src = a2bstr("#@~^EAA*AA==.\x7fwGMYUEm1+kd`*iAQYAAA==^#~@"); 3218 hres = parse_script(SCRIPTITEM_GLOBALMEMBERS, src); 3219 SysFreeString(src); 3220 ok(hres == JS_E_INVALID_CHAR, "parse_script failed %08x\n", hres); 3221 3222 /* vv */ 3223 src = a2bstr("#@~^EAAAAAAA==.\x7fwGMYUEm1+kd`*iAQYAAA==^#~@"); 3224 hres = parse_script(SCRIPTITEM_GLOBALMEMBERS, src); 3225 SysFreeString(src); 3226 ok(hres == JS_E_INVALID_CHAR, "parse_script failed %08x\n", hres); 3227 3228 /* v */ 3229 src = a2bstr("#@~^EAAAAA^=.\x7fwGMYUEm1+kd`*iAQYAAA==^#~@"); 3230 hres = parse_script(SCRIPTITEM_GLOBALMEMBERS, src); 3231 SysFreeString(src); 3232 ok(hres == JS_E_INVALID_CHAR, "parse_script failed %08x\n", hres); 3233 3234 /* v */ 3235 src = a2bstr("#@~^EAAAAA==.\x7fwGMYUEm1ekd`*iAQYAAA==^#~@"); 3236 hres = parse_script(SCRIPTITEM_GLOBALMEMBERS, src); 3237 SysFreeString(src); 3238 ok(hres == JS_E_INVALID_CHAR, "parse_script failed %08x\n", hres); 3239 3240 /* vv */ 3241 src = a2bstr("#@~^EAAAAA==.\x7fwGMYUEm1+kd`*iAQYAAA==^~#@"); 3242 hres = parse_script(SCRIPTITEM_GLOBALMEMBERS, src); 3243 SysFreeString(src); 3244 ok(hres == JS_E_INVALID_CHAR, "parse_script failed %08x\n", hres); 3245 } 3246 3247 static void run_benchmark(const char *script_name) 3248 { 3249 IActiveScriptParse *parser; 3250 IActiveScript *engine; 3251 ULONG start, end; 3252 BSTR src; 3253 HRESULT hres; 3254 3255 engine = create_script(); 3256 if(!engine) 3257 return; 3258 3259 hres = IActiveScript_QueryInterface(engine, &IID_IActiveScriptParse, (void**)&parser); 3260 ok(hres == S_OK, "Could not get IActiveScriptParse: %08x\n", hres); 3261 if (FAILED(hres)) { 3262 IActiveScript_Release(engine); 3263 return; 3264 } 3265 3266 hres = IActiveScriptParse_InitNew(parser); 3267 ok(hres == S_OK, "InitNew failed: %08x\n", hres); 3268 3269 hres = IActiveScript_SetScriptSite(engine, &ActiveScriptSite); 3270 ok(hres == S_OK, "SetScriptSite failed: %08x\n", hres); 3271 3272 hres = IActiveScript_AddNamedItem(engine, testW, 3273 SCRIPTITEM_ISVISIBLE|SCRIPTITEM_ISSOURCE); 3274 ok(hres == S_OK, "AddNamedItem failed: %08x\n", hres); 3275 3276 hres = IActiveScript_SetScriptState(engine, SCRIPTSTATE_STARTED); 3277 ok(hres == S_OK, "SetScriptState(SCRIPTSTATE_STARTED) failed: %08x\n", hres); 3278 3279 src = load_res(script_name); 3280 3281 start = GetTickCount(); 3282 hres = IActiveScriptParse_ParseScriptText(parser, src, NULL, NULL, NULL, 0, 0, 0, NULL, NULL); 3283 end = GetTickCount(); 3284 ok(hres == S_OK, "%s: ParseScriptText failed: %08x\n", script_name, hres); 3285 3286 trace("%s ran in %u ms\n", script_name, end-start); 3287 3288 IActiveScript_Release(engine); 3289 IActiveScriptParse_Release(parser); 3290 SysFreeString(src); 3291 } 3292 3293 static void run_benchmarks(void) 3294 { 3295 trace("Running benchmarks...\n"); 3296 3297 run_benchmark("dna.js"); 3298 run_benchmark("base64.js"); 3299 run_benchmark("validateinput.js"); 3300 } 3301 3302 static BOOL check_jscript(void) 3303 { 3304 IActiveScriptProperty *script_prop; 3305 BSTR str; 3306 HRESULT hres; 3307 3308 hres = CoCreateInstance(&CLSID_JScript, NULL, CLSCTX_INPROC_SERVER|CLSCTX_INPROC_HANDLER, 3309 &IID_IActiveScriptProperty, (void**)&script_prop); 3310 if(FAILED(hres)) 3311 return FALSE; 3312 IActiveScriptProperty_Release(script_prop); 3313 3314 str = a2bstr("if(!('localeCompare' in String.prototype)) throw 1;"); 3315 hres = parse_script(0, str); 3316 SysFreeString(str); 3317 3318 return hres == S_OK; 3319 } 3320 3321 START_TEST(run) 3322 { 3323 int argc; 3324 char **argv; 3325 3326 argc = winetest_get_mainargs(&argv); 3327 3328 CoInitialize(NULL); 3329 3330 if(!check_jscript()) { 3331 win_skip("Broken engine, probably too old\n"); 3332 }else if(argc > 2) { 3333 invoke_version = 2; 3334 run_from_file(argv[2]); 3335 }else { 3336 trace("invoke version 0\n"); 3337 invoke_version = 0; 3338 run_tests(); 3339 3340 trace("invoke version 2\n"); 3341 invoke_version = 2; 3342 if(run_tests()) { 3343 trace("JSctipt.Encode tests...\n"); 3344 run_encoded_tests(); 3345 trace("ParseProcedureText tests...\n"); 3346 test_parse_proc(); 3347 } 3348 3349 if(winetest_interactive) 3350 run_benchmarks(); 3351 } 3352 3353 CoUninitialize(); 3354 } 3355