vbscript: Added AddNamedItem implementation.
This commit is contained in:
parent
aff6961bac
commit
bbed41fa6a
|
@ -87,6 +87,18 @@ static HRESULT set_ctx_site(VBScript *This)
|
|||
|
||||
static void destroy_script(script_ctx_t *ctx)
|
||||
{
|
||||
while(!list_empty(&ctx->named_items)) {
|
||||
named_item_t *iter = LIST_ENTRY(list_head(&ctx->named_items), named_item_t, entry);
|
||||
|
||||
list_remove(&iter->entry);
|
||||
if(iter->disp)
|
||||
IDispatch_Release(iter->disp);
|
||||
heap_free(iter->name);
|
||||
heap_free(iter);
|
||||
}
|
||||
|
||||
if(ctx->host_global)
|
||||
IDispatch_Release(ctx->host_global);
|
||||
if(ctx->site)
|
||||
IActiveScriptSite_Release(ctx->site);
|
||||
if(ctx->script_obj)
|
||||
|
@ -295,7 +307,55 @@ static HRESULT WINAPI VBScript_Close(IActiveScript *iface)
|
|||
static HRESULT WINAPI VBScript_AddNamedItem(IActiveScript *iface, LPCOLESTR pstrName, DWORD dwFlags)
|
||||
{
|
||||
VBScript *This = impl_from_IActiveScript(iface);
|
||||
FIXME("(%p)->(%s %x)\n", This, debugstr_w(pstrName), dwFlags);
|
||||
named_item_t *item;
|
||||
IDispatch *disp = NULL;
|
||||
HRESULT hres;
|
||||
|
||||
TRACE("(%p)->(%s %x)\n", This, debugstr_w(pstrName), dwFlags);
|
||||
|
||||
if(This->thread_id != GetCurrentThreadId() || !This->ctx || This->state == SCRIPTSTATE_CLOSED)
|
||||
return E_UNEXPECTED;
|
||||
|
||||
if(dwFlags & SCRIPTITEM_GLOBALMEMBERS) {
|
||||
IUnknown *unk;
|
||||
|
||||
hres = IActiveScriptSite_GetItemInfo(This->site, pstrName, SCRIPTINFO_IUNKNOWN, &unk, NULL);
|
||||
if(FAILED(hres)) {
|
||||
WARN("GetItemInfo failed: %08x\n", hres);
|
||||
return hres;
|
||||
}
|
||||
|
||||
hres = IUnknown_QueryInterface(unk, &IID_IDispatch, (void**)&disp);
|
||||
IUnknown_Release(unk);
|
||||
if(FAILED(hres)) {
|
||||
WARN("object does not implement IDispatch\n");
|
||||
return hres;
|
||||
}
|
||||
|
||||
if(This->ctx->host_global)
|
||||
IDispatch_Release(This->ctx->host_global);
|
||||
IDispatch_AddRef(disp);
|
||||
This->ctx->host_global = disp;
|
||||
}
|
||||
|
||||
item = heap_alloc(sizeof(*item));
|
||||
if(!item) {
|
||||
if(disp)
|
||||
IDispatch_Release(disp);
|
||||
return E_OUTOFMEMORY;
|
||||
}
|
||||
|
||||
item->disp = disp;
|
||||
item->flags = dwFlags;
|
||||
item->name = heap_strdupW(pstrName);
|
||||
if(!item->name) {
|
||||
if(disp)
|
||||
IDispatch_Release(disp);
|
||||
heap_free(item);
|
||||
return E_OUTOFMEMORY;
|
||||
}
|
||||
|
||||
list_add_tail(&This->ctx->named_items, &item->entry);
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
|
@ -421,6 +481,8 @@ static HRESULT WINAPI VBScriptParse_InitNew(IActiveScriptParse *iface)
|
|||
if(!ctx)
|
||||
return E_OUTOFMEMORY;
|
||||
|
||||
list_init(&ctx->named_items);
|
||||
|
||||
old_ctx = InterlockedCompareExchangePointer((void**)&This->ctx, ctx, NULL);
|
||||
if(old_ctx) {
|
||||
destroy_script(ctx);
|
||||
|
|
|
@ -28,6 +28,17 @@
|
|||
|
||||
#include "vbscript_classes.h"
|
||||
|
||||
#include "wine/list.h"
|
||||
#include "wine/unicode.h"
|
||||
|
||||
typedef struct named_item_t {
|
||||
IDispatch *disp;
|
||||
DWORD flags;
|
||||
LPWSTR name;
|
||||
|
||||
struct list entry;
|
||||
} named_item_t;
|
||||
|
||||
typedef struct {
|
||||
IDispatchEx IDispatchEx_iface;
|
||||
|
||||
|
@ -38,7 +49,11 @@ typedef struct {
|
|||
IActiveScriptSite *site;
|
||||
LCID lcid;
|
||||
|
||||
IDispatch *host_global;
|
||||
|
||||
vbdisp_t *script_obj;
|
||||
|
||||
struct list named_items;
|
||||
} script_ctx_t;
|
||||
|
||||
HRESULT init_global(script_ctx_t*);
|
||||
|
@ -59,3 +74,19 @@ static inline BOOL heap_free(void *mem)
|
|||
{
|
||||
return HeapFree(GetProcessHeap(), 0, mem);
|
||||
}
|
||||
|
||||
static inline LPWSTR heap_strdupW(LPCWSTR str)
|
||||
{
|
||||
LPWSTR ret = NULL;
|
||||
|
||||
if(str) {
|
||||
DWORD size;
|
||||
|
||||
size = (strlenW(str)+1)*sizeof(WCHAR);
|
||||
ret = heap_alloc(size);
|
||||
if(ret)
|
||||
memcpy(ret, str, size);
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue