1967{
1968 static struct
1969 {
1973 {
1982 };
1983 static struct
1984 {
1987 {
1991 };
1993 "var global_var = 42;\n"
1994
1995 "function emptyfn() { }\n"
1996 "function voidfn() { return void(0); }\n"
1997 "function math(x, y) { return x - y; }\n"
1998 "function foobar(x) { return \"foobar\"; }\n"
1999
2000 "function C() {\n"
2001 " this.x;\n"
2002 " this.strret = function() { return \"ret\"; }\n"
2003 "}\n"
2004
2005 "var uninit;\n"
2006 "var obj = new C();\n"
2007
2008 "var funcvar = function(x, y) { return x * y; };\n"
2009 "var native_func = decodeURI;\n"
2010
2011 "(function() {\n"
2012 " f1 = function infuncexpr(x) { return 1; }\n"
2013 " f2 = function infuncexpr(x) { return 2; }\n"
2014 "})();\n";
2017
2020 IActiveScriptParse *
parser;
2022 FUNCDESC *funcdesc;
2023 VARDESC *vardesc;
2025 DESCKIND desckind;
2028 HREFTYPE reftype;
2029 BINDPTR bindptr;
2030 MEMBERID memid;
2034 BSTR bstr, bstrs[5];
2037
2038 if (parse_func_name)
2040 else
2041 trace(
"Testing TypeInfo for script dispatch...\n");
2042
2044
2045 hr = IActiveScript_QueryInterface(
script, &IID_IActiveScriptParse, (
void**)&
parser);
2046 ok(
hr ==
S_OK,
"Could not get IActiveScriptParse iface: %08lx\n",
hr);
2047
2050 ok(
hr ==
S_OK,
"SetScriptSite failed: %08lx\n",
hr);
2052
2055 ok(
hr ==
S_OK,
"InitNew failed: %08lx\n",
hr);
2057
2060 ok(
hr ==
S_OK,
"SetScriptState(SCRIPTSTATE_CONNECTED) failed: %08lx\n",
hr);
2062
2063 if (parse_func_name)
2064 {
2065 IActiveScriptParseProcedure2 *parse_proc;
2067
2068 hr = IActiveScript_QueryInterface(
script, &IID_IActiveScriptParseProcedure2, (
void**)&parse_proc);
2069 ok(
hr ==
S_OK,
"Could not get IActiveScriptParse: %08lx\n",
hr);
2070
2072 NULL,
NULL,
NULL, 0, 0, SCRIPTPROC_IMPLICIT_THIS | SCRIPTPROC_IMPLICIT_PARENTS, &proc_disp);
2073 ok(
hr ==
S_OK,
"ParseProcedureText failed: %08lx\n",
hr);
2075
2076 hr = IDispatch_QueryInterface(proc_disp, &IID_IDispatchEx, (
void**)&disp);
2077 ok(
hr ==
S_OK,
"Could not get IDispatchEx: %08lx\n",
hr);
2078 IDispatch_Release(proc_disp);
2079 }
2080 else
2081 {
2084 }
2085
2086 hr = IDispatchEx_QueryInterface(disp, &IID_ITypeInfo, (
void**)&
typeinfo);
2091 ok(
hr ==
S_OK,
"GetTypeInfo failed: %08lx\n",
hr);
2093 ok(
hr ==
S_OK,
"GetTypeInfo failed: %08lx\n",
hr);
2094 ok(
typeinfo != typeinfo2,
"TypeInfo was not supposed to be shared.\n");
2095 ITypeInfo_Release(typeinfo2);
2096
2097 obj = (
void*)0xdeadbeef;
2104 ok(!
obj,
"Unexpected non-null obj %p.\n",
obj);
2105
2107 ok(
hr ==
S_OK,
"GetDocumentation(MEMBERID_NIL) failed: %08lx\n",
hr);
2110
2112 ok(
hr ==
S_OK,
"GetTypeAttr failed: %08lx\n",
hr);
2115 ok(
attr->memidConstructor ==
MEMBERID_NIL,
"Unexpected constructor memid %lu\n",
attr->memidConstructor);
2117 ok(
attr->cbSizeInstance == 4,
"Unexpected cbSizeInstance %lu\n",
attr->cbSizeInstance);
2119 ok(
attr->cFuncs == expected_funcs_cnt,
"Unexpected cFuncs %u\n",
attr->cFuncs);
2120 ok(
attr->cVars == expected_vars_cnt,
"Unexpected cVars %u\n",
attr->cVars);
2121 ok(
attr->cImplTypes == 1,
"Unexpected cImplTypes %u\n",
attr->cImplTypes);
2122 ok(
attr->cbSizeVft ==
sizeof(IDispatchVtbl),
"Unexpected cbSizeVft %u\n",
attr->cbSizeVft);
2123 ok(
attr->cbAlignment == 4,
"Unexpected cbAlignment %u\n",
attr->cbAlignment);
2124 ok(
attr->wTypeFlags == TYPEFLAG_FDISPATCHABLE,
"Unexpected wTypeFlags 0x%x\n",
attr->wTypeFlags);
2125 ok(
attr->tdescAlias.vt ==
VT_EMPTY,
"Unexpected tdescAlias.vt %d\n",
attr->tdescAlias.vt);
2126 ok(
attr->idldescType.wIDLFlags == IDLFLAG_NONE,
"Unexpected idldescType.wIDLFlags 0x%x\n",
attr->idldescType.wIDLFlags);
2128
2129
2132 hr = ITypeInfo_GetImplTypeFlags(
typeinfo, 1, &implTypeFlags);
2134 hr = ITypeInfo_GetImplTypeFlags(
typeinfo, -1, &implTypeFlags);
2136 hr = ITypeInfo_GetImplTypeFlags(
typeinfo, 0, &implTypeFlags);
2137 ok(
hr ==
S_OK,
"GetImplTypeFlags failed: %08lx\n",
hr);
2138 ok(implTypeFlags == 0,
"Unexpected implTypeFlags 0x%x\n", implTypeFlags);
2139
2142 hr = ITypeInfo_GetRefTypeOfImplType(
typeinfo, 1, &reftype);
2144 hr = ITypeInfo_GetRefTypeOfImplType(
typeinfo, -1, &reftype);
2146 hr = ITypeInfo_GetRefTypeOfImplType(
typeinfo, 0, &reftype);
2147 ok(
hr ==
S_OK,
"GetRefTypeOfImplType failed: %08lx\n",
hr);
2148 ok(reftype == 1,
"Unexpected reftype %ld\n", reftype);
2149
2152 hr = ITypeInfo_GetRefTypeInfo(
typeinfo, -1, &typeinfo2);
2154 hr = ITypeInfo_GetRefTypeInfo(
typeinfo, 4, &typeinfo2);
2155 ok(
hr ==
E_FAIL,
"GetRefTypeInfo returned: %08lx\n",
hr);
2156 hr = ITypeInfo_GetRefTypeInfo(
typeinfo, 0, &typeinfo2);
2157 ok(
hr ==
S_OK,
"GetRefTypeInfo failed: %08lx\n",
hr);
2158 ok(
typeinfo == typeinfo2,
"Unexpected TypeInfo %p (expected %p)\n", typeinfo2,
typeinfo);
2159 ITypeInfo_Release(typeinfo2);
2160 hr = ITypeInfo_GetRefTypeInfo(
typeinfo, reftype, &typeinfo2);
2161 ok(
hr ==
S_OK,
"GetRefTypeInfo failed: %08lx\n",
hr);
2163 ok(
hr ==
S_OK,
"GetDocumentation(MEMBERID_NIL) failed: %08lx\n",
hr);
2165 ITypeInfo_Release(typeinfo2);
2167
2168
2177 ok(
hr ==
S_OK,
"GetIDsOfNames failed: %08lx\n",
hr);
2179 if (expected_funcs_cnt)
2180 {
2183 ok(
hr ==
S_OK,
"GetIDsOfNames failed: %08lx\n",
hr);
2190 ok(
hr ==
S_OK,
"GetNames failed: %08lx\n",
hr);
2193 ok(
hr ==
S_OK,
"GetNames failed: %08lx\n",
hr);
2199
2202 hr = ITypeInfo_GetMops(
typeinfo, memid, &bstr);
2203 ok(
hr ==
S_OK,
"GetMops failed: %08lx\n",
hr);
2206 ok(
hr ==
S_OK,
"GetMops failed: %08lx\n",
hr);
2208
2209
2210 obj = (
void*)0xdeadbeef;
2211 hr = ITypeInfo_AddressOfMember(
typeinfo, memid, INVOKE_FUNC,
NULL);
2213 hr = ITypeInfo_AddressOfMember(
typeinfo, memid, INVOKE_FUNC, &
obj);
2215 ok(!
obj,
"Unexpected non-null obj %p.\n",
obj);
2216 bstr = (
BSTR)0xdeadbeef;
2219 ok(!bstr,
"Unexpected non-null str %p.\n", bstr);
2222 ok(
hr ==
S_OK,
"GetIDsOfNames failed: %08lx\n",
hr);
2223 obj = (
void*)0xdeadbeef;
2224 hr = ITypeInfo_AddressOfMember(
typeinfo, memid, INVOKE_FUNC, &
obj);
2226 ok(!
obj,
"Unexpected non-null obj %p.\n",
obj);
2227 bstr = (
BSTR)0xdeadbeef;
2230 ok(!bstr,
"Unexpected non-null str %p.\n", bstr);
2231 }
2232
2233
2236 hr = ITypeInfo_GetVarDesc(
typeinfo, 1337, &vardesc);
2238 for (
i = 0;
i < expected_vars_cnt;
i++)
2239 {
2241 ok(
hr ==
S_OK,
"GetVarDesc(%u) failed: %08lx\n",
i,
hr);
2242 hr = ITypeInfo_GetDocumentation(
typeinfo, vardesc->memid, &bstr, &bstrs[0],
NULL,
NULL);
2243 ok(
hr ==
S_OK,
"[%u] GetDocumentation failed: %08lx\n",
i,
hr);
2246 ok(!bstrs[0],
"[%u] Unexpected doc string %s\n",
i,
wine_dbgstr_w(bstrs[0]));
2248 ok(vardesc->memid <= 0xFFFF,
"[%u] Unexpected memid 0x%lx\n",
i, vardesc->memid);
2249 ok(vardesc->lpstrSchema ==
NULL,
"[%u] Unexpected lpstrSchema %p\n",
i, vardesc->lpstrSchema);
2250 ok(vardesc->oInst == 0,
"[%u] Unexpected oInst %lu\n",
i, vardesc->oInst);
2251 ok(vardesc->varkind == VAR_DISPATCH,
"[%u] Unexpected varkind %d\n",
i, vardesc->varkind);
2252 ok(vardesc->wVarFlags == 0,
"[%u] Unexpected wVarFlags 0x%x\n",
i, vardesc->wVarFlags);
2254 "[%u] Unexpected variable type vt %d (expected %d)\n",
i, vardesc->elemdescVar.tdesc.vt, 0);
2255 ok(vardesc->elemdescVar.paramdesc.pparamdescex ==
NULL,
2256 "[%u] Unexpected variable type pparamdescex %p\n",
i, vardesc->elemdescVar.paramdesc.pparamdescex);
2257 ok(vardesc->elemdescVar.paramdesc.wParamFlags == PARAMFLAG_NONE,
2258 "[%u] Unexpected variable type wParamFlags 0x%x\n",
i, vardesc->elemdescVar.paramdesc.wParamFlags);
2259 ITypeInfo_ReleaseVarDesc(
typeinfo, vardesc);
2260 }
2261
2262
2265 hr = ITypeInfo_GetFuncDesc(
typeinfo, 1337, &funcdesc);
2267 for (
i = 0;
i < expected_funcs_cnt;
i++)
2268 {
2269 hr = ITypeInfo_GetFuncDesc(
typeinfo,
i, &funcdesc);
2270 ok(
hr ==
S_OK,
"GetFuncDesc(%u) failed: %08lx\n",
i,
hr);
2271 hr = ITypeInfo_GetDocumentation(
typeinfo, funcdesc->memid, &bstr, &bstrs[0],
NULL,
NULL);
2272 ok(
hr ==
S_OK,
"[%u] GetDocumentation failed: %08lx\n",
i,
hr);
2275 ok(!bstrs[0],
"[%u] Unexpected doc string %s\n",
i,
wine_dbgstr_w(bstrs[0]));
2277 ok(funcdesc->memid <= 0xFFFF,
"[%u] Unexpected memid 0x%lx\n",
i, funcdesc->memid);
2278 ok(funcdesc->lprgscode ==
NULL,
"[%u] Unexpected lprgscode %p\n",
i, funcdesc->lprgscode);
2279 ok(
func[
i].num_args ? (funcdesc->lprgelemdescParam !=
NULL) : (funcdesc->lprgelemdescParam ==
NULL),
2280 "[%u] Unexpected lprgelemdescParam %p\n",
i, funcdesc->lprgelemdescParam);
2281 ok(funcdesc->funckind == FUNC_DISPATCH,
"[%u] Unexpected funckind %u\n",
i, funcdesc->funckind);
2282 ok(funcdesc->invkind == INVOKE_FUNC,
"[%u] Unexpected invkind %u\n",
i, funcdesc->invkind);
2283 ok(funcdesc->callconv ==
CC_STDCALL,
"[%u] Unexpected callconv %u\n",
i, funcdesc->callconv);
2284 ok(funcdesc->cParams ==
func[
i].num_args,
"[%u] Unexpected cParams %d (expected %d)\n",
2285 i, funcdesc->cParams,
func[
i].num_args);
2286 ok(funcdesc->cParamsOpt == 0,
"[%u] Unexpected cParamsOpt %d\n",
i, funcdesc->cParamsOpt);
2287 ok(funcdesc->cScodes == 0,
"[%u] Unexpected cScodes %d\n",
i, funcdesc->cScodes);
2288 ok(funcdesc->wFuncFlags == 0,
"[%u] Unexpected wFuncFlags 0x%x\n",
i, funcdesc->wFuncFlags);
2290 "[%u] Unexpected return type vt %d\n",
i, funcdesc->elemdescFunc.tdesc.vt);
2291 ok(funcdesc->elemdescFunc.paramdesc.pparamdescex ==
NULL,
2292 "[%u] Unexpected return type pparamdescex %p\n",
i, funcdesc->elemdescFunc.paramdesc.pparamdescex);
2293 ok(funcdesc->elemdescFunc.paramdesc.wParamFlags == PARAMFLAG_NONE,
2294 "[%u] Unexpected return type wParamFlags 0x%x\n",
i, funcdesc->elemdescFunc.paramdesc.wParamFlags);
2295 if (funcdesc->lprgelemdescParam)
2297 {
2299 "[%u] Unexpected parameter %u vt %d\n",
i,
index, funcdesc->lprgelemdescParam[
index].tdesc.vt);
2300 ok(funcdesc->lprgelemdescParam[
index].paramdesc.pparamdescex ==
NULL,
2301 "[%u] Unexpected parameter %u pparamdescex %p\n",
i,
index, funcdesc->lprgelemdescParam[
index].paramdesc.pparamdescex);
2302 ok(funcdesc->lprgelemdescParam[
index].paramdesc.wParamFlags == PARAMFLAG_NONE,
2303 "[%u] Unexpected parameter %u wParamFlags 0x%x\n",
i,
index, funcdesc->lprgelemdescParam[
index].paramdesc.wParamFlags);
2304 }
2305 ITypeInfo_ReleaseFuncDesc(
typeinfo, funcdesc);
2306 }
2307
2308
2309 hr = ITypeInfo_QueryInterface(
typeinfo, &IID_ITypeComp, (
void**)&typecomp);
2310 ok(
hr ==
S_OK,
"QueryInterface(IID_ITypeComp) failed: %08lx\n",
hr);
2313 hr = ITypeInfo_GetTypeComp(
typeinfo, &typecomp2);
2314 ok(
hr ==
S_OK,
"GetTypeComp failed: %08lx\n",
hr);
2315 ok(typecomp == typecomp2,
"QueryInterface(IID_ITypeComp) and GetTypeComp returned different TypeComps\n");
2316 ITypeComp_Release(typecomp2);
2318 hr = ITypeComp_Bind(typecomp,
NULL, 0, 0, &typeinfo2, &desckind, &bindptr);
2320 hr = ITypeComp_Bind(typecomp,
str, 0, 0,
NULL, &desckind, &bindptr);
2322 hr = ITypeComp_Bind(typecomp,
str, 0, 0, &typeinfo2,
NULL, &bindptr);
2324 hr = ITypeComp_Bind(typecomp,
str, 0, 0, &typeinfo2, &desckind,
NULL);
2326 hr = ITypeComp_Bind(typecomp,
str, 0, 0, &typeinfo2, &desckind, &bindptr);
2328 ok(desckind == DESCKIND_NONE,
"Unexpected desckind %u\n", desckind);
2330 hr = ITypeComp_Bind(typecomp,
str, 0, 0, &typeinfo2, &desckind, &bindptr);
2332 ok(desckind == DESCKIND_FUNCDESC,
"Unexpected desckind %u\n", desckind);
2334 ITypeInfo_ReleaseFuncDesc(typeinfo2, bindptr.lpfuncdesc);
2335 ITypeInfo_Release(typeinfo2);
2336 for (
i = 0;
i < expected_vars_cnt;
i++)
2337 {
2339 hr = ITypeComp_Bind(typecomp,
str, 0, INVOKE_PROPERTYGET, &typeinfo2, &desckind, &bindptr);
2341 ok(desckind == DESCKIND_VARDESC,
"Unexpected desckind %u\n", desckind);
2342 ITypeInfo_ReleaseVarDesc(typeinfo2, bindptr.lpvardesc);
2343 ITypeInfo_Release(typeinfo2);
2344 }
2345 for (
i = 0;
i < expected_funcs_cnt;
i++)
2346 {
2348 hr = ITypeComp_Bind(typecomp,
str, 0, INVOKE_FUNC, &typeinfo2, &desckind, &bindptr);
2350 ok(desckind == DESCKIND_FUNCDESC,
"Unexpected desckind %u\n", desckind);
2351 ITypeInfo_ReleaseFuncDesc(typeinfo2, bindptr.lpfuncdesc);
2352 ITypeInfo_Release(typeinfo2);
2353 }
2355 hr = ITypeComp_BindType(typecomp,
NULL, 0, &typeinfo2, &typecomp2);
2357 hr = ITypeComp_BindType(typecomp,
str, 0,
NULL, &typecomp2);
2359 hr = ITypeComp_BindType(typecomp,
str, 0, &typeinfo2,
NULL);
2361 hr = ITypeComp_BindType(typecomp,
str, 0, &typeinfo2, &typecomp2);
2362 ok(
hr ==
S_OK,
"BindType failed: %08lx\n",
hr);
2363 ok(!typeinfo2,
"Unexpected TypeInfo %p (expected null)\n", typeinfo2);
2364 ok(!typecomp2,
"Unexpected TypeComp %p (expected null)\n", typecomp2);
2366 hr = ITypeComp_BindType(typecomp,
str, 0, &typeinfo2, &typecomp2);
2367 ok(
hr ==
S_OK,
"BindType failed: %08lx\n",
hr);
2368 ok(!typeinfo2,
"Unexpected TypeInfo %p (expected null)\n", typeinfo2);
2369 ok(!typecomp2,
"Unexpected TypeComp %p (expected null)\n", typecomp2);
2371 hr = ITypeComp_BindType(typecomp,
str, 0, &typeinfo2, &typecomp2);
2372 ok(
hr ==
S_OK,
"BindType failed: %08lx\n",
hr);
2373 ok(!typeinfo2,
"Unexpected TypeInfo %p (expected null)\n", typeinfo2);
2374 ok(!typecomp2,
"Unexpected TypeComp %p (expected null)\n", typecomp2);
2375 ITypeComp_Release(typecomp);
2376
2377
2378
2379 if (!parse_func_name)
2380 {
2382 "var new_var;\n"
2383 "function new_func() { }\n");
2384
2386 ok(
hr ==
S_OK,
"GetTypeInfo failed: %08lx\n",
hr);
2388 ok(
hr ==
S_OK,
"GetTypeAttr failed: %08lx\n",
hr);
2389 ok(
attr->cFuncs == expected_funcs_cnt,
"Unexpected cFuncs %u\n",
attr->cFuncs);
2390 ok(
attr->cVars == expected_vars_cnt,
"Unexpected cVars %u\n",
attr->cVars);
2392 hr = ITypeInfo_GetTypeAttr(typeinfo2, &
attr);
2393 ok(
hr ==
S_OK,
"GetTypeAttr failed: %08lx\n",
hr);
2394 ok(
attr->cFuncs == expected_funcs_cnt + 1,
"Unexpected cFuncs %u\n",
attr->cFuncs);
2395 ok(
attr->cVars == expected_vars_cnt + 1,
"Unexpected cVars %u\n",
attr->cVars);
2396 ITypeInfo_ReleaseTypeAttr(typeinfo2,
attr);
2397 ITypeInfo_Release(typeinfo2);
2398
2399
2400
2404 }
2405
2407 IDispatchEx_Release(disp);
2409
2418
2419 IActiveScript_Release(
script);
2420}
int WINAPI lstrcmpW(LPCWSTR str1, LPCWSTR str2)
GLuint GLuint GLsizei count
#define IActiveScriptParseProcedure2_ParseProcedureText
#define IActiveScriptParseProcedure2_Release
#define LOCALE_USER_DEFAULT
static __inline const char * wine_dbgstr_guid(const GUID *id)
#define TYPE_E_BADMODULEKIND
#define TYPE_E_ELEMENTNOTFOUND
#define TYPE_E_AMBIGUOUSNAME