2008-09-01 01:23:38 +02:00
|
|
|
/*
|
|
|
|
* Copyright 2008 Jacek Caban for CodeWeavers
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
|
|
|
|
*/
|
|
|
|
|
2011-12-16 11:43:31 +01:00
|
|
|
#include <assert.h>
|
|
|
|
|
2008-09-01 01:23:38 +02:00
|
|
|
#include "jscript.h"
|
|
|
|
|
|
|
|
#include "wine/unicode.h"
|
|
|
|
#include "wine/debug.h"
|
|
|
|
|
|
|
|
WINE_DEFAULT_DEBUG_CHANNEL(jscript);
|
|
|
|
|
2008-09-09 01:20:26 +02:00
|
|
|
/*
|
2010-09-06 16:11:49 +02:00
|
|
|
* This IID is used to get jsdisp_t objecto from interface.
|
2008-09-09 01:20:26 +02:00
|
|
|
* We might consider using private insteface instead.
|
|
|
|
*/
|
|
|
|
static const IID IID_IDispatchJS =
|
|
|
|
{0x719c3050,0xf9d3,0x11cf,{0xa4,0x93,0x00,0x40,0x05,0x23,0xa8,0xa6}};
|
|
|
|
|
2009-10-19 20:39:56 +02:00
|
|
|
#define FDEX_VERSION_MASK 0xf0000000
|
2011-09-02 12:24:25 +02:00
|
|
|
#define GOLDEN_RATIO 0x9E3779B9U
|
2009-10-19 20:39:56 +02:00
|
|
|
|
2008-09-08 00:14:38 +02:00
|
|
|
typedef enum {
|
|
|
|
PROP_VARIANT,
|
|
|
|
PROP_BUILTIN,
|
|
|
|
PROP_PROTREF,
|
|
|
|
PROP_DELETED
|
|
|
|
} prop_type_t;
|
|
|
|
|
|
|
|
struct _dispex_prop_t {
|
|
|
|
WCHAR *name;
|
2011-09-02 12:24:35 +02:00
|
|
|
unsigned hash;
|
2008-09-08 00:14:38 +02:00
|
|
|
prop_type_t type;
|
|
|
|
DWORD flags;
|
|
|
|
|
|
|
|
union {
|
|
|
|
VARIANT var;
|
|
|
|
const builtin_prop_t *p;
|
|
|
|
DWORD ref;
|
|
|
|
} u;
|
2011-09-02 12:24:25 +02:00
|
|
|
|
|
|
|
int bucket_head;
|
|
|
|
int bucket_next;
|
2008-09-08 00:14:38 +02:00
|
|
|
};
|
|
|
|
|
2010-09-06 16:11:49 +02:00
|
|
|
static inline DISPID prop_to_id(jsdisp_t *This, dispex_prop_t *prop)
|
2008-09-08 00:14:58 +02:00
|
|
|
{
|
|
|
|
return prop - This->props;
|
|
|
|
}
|
|
|
|
|
2010-09-06 16:11:49 +02:00
|
|
|
static inline dispex_prop_t *get_prop(jsdisp_t *This, DISPID id)
|
2008-09-09 01:20:26 +02:00
|
|
|
{
|
|
|
|
if(id < 0 || id >= This->prop_cnt || This->props[id].type == PROP_DELETED)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
return This->props+id;
|
|
|
|
}
|
|
|
|
|
2010-09-06 16:11:49 +02:00
|
|
|
static DWORD get_flags(jsdisp_t *This, dispex_prop_t *prop)
|
2008-09-09 01:20:52 +02:00
|
|
|
{
|
|
|
|
if(prop->type == PROP_PROTREF) {
|
|
|
|
dispex_prop_t *parent = get_prop(This->prototype, prop->u.ref);
|
|
|
|
if(!parent) {
|
|
|
|
prop->type = PROP_DELETED;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
return get_flags(This->prototype, parent);
|
|
|
|
}
|
|
|
|
|
|
|
|
return prop->flags;
|
|
|
|
}
|
|
|
|
|
2010-09-06 16:11:49 +02:00
|
|
|
static const builtin_prop_t *find_builtin_prop(jsdisp_t *This, const WCHAR *name)
|
2008-09-08 00:14:58 +02:00
|
|
|
{
|
|
|
|
int min = 0, max, i, r;
|
|
|
|
|
|
|
|
max = This->builtin_info->props_cnt-1;
|
|
|
|
while(min <= max) {
|
|
|
|
i = (min+max)/2;
|
|
|
|
|
|
|
|
r = strcmpW(name, This->builtin_info->props[i].name);
|
|
|
|
if(!r)
|
|
|
|
return This->builtin_info->props + i;
|
|
|
|
|
|
|
|
if(r < 0)
|
|
|
|
max = i-1;
|
|
|
|
else
|
|
|
|
min = i+1;
|
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2011-09-02 12:24:25 +02:00
|
|
|
static inline unsigned string_hash(const WCHAR *name)
|
2008-09-08 00:14:58 +02:00
|
|
|
{
|
2011-09-02 12:24:25 +02:00
|
|
|
unsigned h = 0;
|
|
|
|
for(; *name; name++)
|
|
|
|
h = (h>>(sizeof(unsigned)*8-4)) ^ (h<<4) ^ tolowerW(*name);
|
|
|
|
return h;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline unsigned get_props_idx(jsdisp_t *This, unsigned hash)
|
|
|
|
{
|
|
|
|
return (hash*GOLDEN_RATIO) & (This->buf_size-1);
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline HRESULT resize_props(jsdisp_t *This)
|
|
|
|
{
|
|
|
|
dispex_prop_t *props;
|
|
|
|
int i, bucket;
|
|
|
|
|
|
|
|
if(This->buf_size != This->prop_cnt)
|
|
|
|
return S_FALSE;
|
|
|
|
|
|
|
|
props = heap_realloc(This->props, sizeof(dispex_prop_t)*This->buf_size*2);
|
|
|
|
if(!props)
|
|
|
|
return E_OUTOFMEMORY;
|
|
|
|
This->buf_size *= 2;
|
|
|
|
This->props = props;
|
2008-09-08 00:14:58 +02:00
|
|
|
|
2011-09-02 12:24:25 +02:00
|
|
|
for(i=0; i<This->buf_size; i++) {
|
|
|
|
This->props[i].bucket_head = 0;
|
|
|
|
This->props[i].bucket_next = 0;
|
2008-09-08 00:14:58 +02:00
|
|
|
}
|
|
|
|
|
2011-09-02 12:24:25 +02:00
|
|
|
for(i=1; i<This->prop_cnt; i++) {
|
|
|
|
props = This->props+i;
|
|
|
|
|
2011-09-02 12:24:35 +02:00
|
|
|
bucket = get_props_idx(This, props->hash);
|
2011-09-02 12:24:25 +02:00
|
|
|
props->bucket_next = This->props[bucket].bucket_head;
|
|
|
|
This->props[bucket].bucket_head = i;
|
|
|
|
}
|
|
|
|
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline dispex_prop_t* alloc_prop(jsdisp_t *This, const WCHAR *name, prop_type_t type, DWORD flags)
|
|
|
|
{
|
|
|
|
dispex_prop_t *prop;
|
|
|
|
unsigned bucket;
|
|
|
|
|
|
|
|
if(FAILED(resize_props(This)))
|
2008-09-08 00:14:58 +02:00
|
|
|
return NULL;
|
|
|
|
|
2011-09-02 12:24:25 +02:00
|
|
|
prop = &This->props[This->prop_cnt];
|
|
|
|
prop->name = heap_strdupW(name);
|
|
|
|
if(!prop->name)
|
|
|
|
return NULL;
|
|
|
|
prop->type = type;
|
|
|
|
prop->flags = flags;
|
2011-09-02 12:24:35 +02:00
|
|
|
prop->hash = string_hash(name);
|
2011-09-02 12:24:25 +02:00
|
|
|
|
2011-09-02 12:24:35 +02:00
|
|
|
bucket = get_props_idx(This, prop->hash);
|
2011-09-02 12:24:25 +02:00
|
|
|
prop->bucket_next = This->props[bucket].bucket_head;
|
|
|
|
This->props[bucket].bucket_head = This->prop_cnt++;
|
|
|
|
return prop;
|
2008-09-08 00:14:58 +02:00
|
|
|
}
|
|
|
|
|
2010-09-06 16:11:49 +02:00
|
|
|
static dispex_prop_t *alloc_protref(jsdisp_t *This, const WCHAR *name, DWORD ref)
|
2008-09-08 00:14:58 +02:00
|
|
|
{
|
|
|
|
dispex_prop_t *ret;
|
|
|
|
|
|
|
|
ret = alloc_prop(This, name, PROP_PROTREF, 0);
|
|
|
|
if(!ret)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
ret->u.ref = ref;
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2011-09-02 12:24:35 +02:00
|
|
|
static HRESULT find_prop_name(jsdisp_t *This, unsigned hash, const WCHAR *name, dispex_prop_t **ret)
|
2008-09-08 00:14:58 +02:00
|
|
|
{
|
|
|
|
const builtin_prop_t *builtin;
|
2011-09-02 12:24:25 +02:00
|
|
|
unsigned bucket, pos, prev = 0;
|
2008-09-08 00:14:58 +02:00
|
|
|
dispex_prop_t *prop;
|
|
|
|
|
2011-09-02 12:24:35 +02:00
|
|
|
bucket = get_props_idx(This, hash);
|
2011-09-02 12:24:25 +02:00
|
|
|
pos = This->props[bucket].bucket_head;
|
|
|
|
while(pos != 0) {
|
|
|
|
if(!strcmpW(name, This->props[pos].name)) {
|
|
|
|
if(prev != 0) {
|
|
|
|
This->props[prev].bucket_next = This->props[pos].bucket_next;
|
|
|
|
This->props[pos].bucket_next = This->props[bucket].bucket_head;
|
|
|
|
This->props[bucket].bucket_head = pos;
|
|
|
|
}
|
|
|
|
|
|
|
|
*ret = &This->props[pos];
|
2008-09-08 00:14:58 +02:00
|
|
|
return S_OK;
|
|
|
|
}
|
2011-09-02 12:24:25 +02:00
|
|
|
|
|
|
|
prev = pos;
|
|
|
|
pos = This->props[pos].bucket_next;
|
2008-09-08 00:14:58 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
builtin = find_builtin_prop(This, name);
|
|
|
|
if(builtin) {
|
|
|
|
prop = alloc_prop(This, name, PROP_BUILTIN, builtin->flags);
|
|
|
|
if(!prop)
|
|
|
|
return E_OUTOFMEMORY;
|
|
|
|
|
|
|
|
prop->u.p = builtin;
|
|
|
|
*ret = prop;
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
*ret = NULL;
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
2011-09-02 12:24:35 +02:00
|
|
|
static HRESULT find_prop_name_prot(jsdisp_t *This, unsigned hash, const WCHAR *name, dispex_prop_t **ret)
|
2008-09-08 00:14:58 +02:00
|
|
|
{
|
2011-09-02 12:24:25 +02:00
|
|
|
dispex_prop_t *prop, *del=NULL;
|
2008-09-08 00:14:58 +02:00
|
|
|
HRESULT hres;
|
|
|
|
|
2011-09-02 12:24:35 +02:00
|
|
|
hres = find_prop_name(This, hash, name, &prop);
|
2008-09-08 00:14:58 +02:00
|
|
|
if(FAILED(hres))
|
|
|
|
return hres;
|
2011-09-02 12:24:25 +02:00
|
|
|
if(prop && prop->type==PROP_DELETED) {
|
|
|
|
del = prop;
|
|
|
|
} else if(prop) {
|
2008-09-08 00:14:58 +02:00
|
|
|
*ret = prop;
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(This->prototype) {
|
2011-09-02 12:24:35 +02:00
|
|
|
hres = find_prop_name_prot(This->prototype, hash, name, &prop);
|
2008-09-08 00:14:58 +02:00
|
|
|
if(FAILED(hres))
|
|
|
|
return hres;
|
|
|
|
if(prop) {
|
2011-09-02 12:24:25 +02:00
|
|
|
if(del) {
|
|
|
|
del->type = PROP_PROTREF;
|
|
|
|
del->flags = 0;
|
|
|
|
del->u.ref = prop - This->prototype->props;
|
|
|
|
prop = del;
|
|
|
|
}else {
|
|
|
|
prop = alloc_protref(This, prop->name, prop - This->prototype->props);
|
|
|
|
if(!prop)
|
|
|
|
return E_OUTOFMEMORY;
|
|
|
|
}
|
|
|
|
|
2008-09-08 00:14:58 +02:00
|
|
|
*ret = prop;
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-09-02 12:24:25 +02:00
|
|
|
*ret = del;
|
2010-02-05 23:15:07 +01:00
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
2010-09-06 16:11:49 +02:00
|
|
|
static HRESULT ensure_prop_name(jsdisp_t *This, const WCHAR *name, BOOL search_prot, DWORD create_flags, dispex_prop_t **ret)
|
2010-02-05 23:15:07 +01:00
|
|
|
{
|
|
|
|
dispex_prop_t *prop;
|
|
|
|
HRESULT hres;
|
|
|
|
|
2010-02-05 23:17:06 +01:00
|
|
|
if(search_prot)
|
2011-09-02 12:24:35 +02:00
|
|
|
hres = find_prop_name_prot(This, string_hash(name), name, &prop);
|
2010-02-05 23:17:06 +01:00
|
|
|
else
|
2011-09-02 12:24:35 +02:00
|
|
|
hres = find_prop_name(This, string_hash(name), name, &prop);
|
2011-09-02 12:24:25 +02:00
|
|
|
if(SUCCEEDED(hres) && (!prop || prop->type==PROP_DELETED)) {
|
2008-09-08 00:14:58 +02:00
|
|
|
TRACE("creating prop %s\n", debugstr_w(name));
|
|
|
|
|
2011-09-02 12:24:25 +02:00
|
|
|
if(prop) {
|
|
|
|
prop->type = PROP_VARIANT;
|
|
|
|
prop->flags = create_flags;
|
|
|
|
}else {
|
|
|
|
prop = alloc_prop(This, name, PROP_VARIANT, create_flags);
|
|
|
|
if(!prop)
|
|
|
|
return E_OUTOFMEMORY;
|
|
|
|
}
|
|
|
|
|
2008-09-08 00:14:58 +02:00
|
|
|
VariantInit(&prop->u.var);
|
|
|
|
}
|
|
|
|
|
|
|
|
*ret = prop;
|
2010-02-05 23:15:07 +01:00
|
|
|
return hres;
|
2008-09-08 00:14:58 +02:00
|
|
|
}
|
|
|
|
|
2008-09-09 01:20:26 +02:00
|
|
|
static HRESULT set_this(DISPPARAMS *dp, DISPPARAMS *olddp, IDispatch *jsthis)
|
|
|
|
{
|
|
|
|
VARIANTARG *oldargs;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
static DISPID this_id = DISPID_THIS;
|
|
|
|
|
|
|
|
*dp = *olddp;
|
|
|
|
|
|
|
|
for(i = 0; i < dp->cNamedArgs; i++) {
|
|
|
|
if(dp->rgdispidNamedArgs[i] == DISPID_THIS)
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
oldargs = dp->rgvarg;
|
|
|
|
dp->rgvarg = heap_alloc((dp->cArgs+1) * sizeof(VARIANTARG));
|
|
|
|
if(!dp->rgvarg)
|
|
|
|
return E_OUTOFMEMORY;
|
|
|
|
memcpy(dp->rgvarg+1, oldargs, dp->cArgs*sizeof(VARIANTARG));
|
|
|
|
V_VT(dp->rgvarg) = VT_DISPATCH;
|
|
|
|
V_DISPATCH(dp->rgvarg) = jsthis;
|
|
|
|
dp->cArgs++;
|
|
|
|
|
|
|
|
if(dp->cNamedArgs) {
|
|
|
|
DISPID *old = dp->rgdispidNamedArgs;
|
|
|
|
dp->rgdispidNamedArgs = heap_alloc((dp->cNamedArgs+1)*sizeof(DISPID));
|
|
|
|
if(!dp->rgdispidNamedArgs) {
|
|
|
|
heap_free(dp->rgvarg);
|
|
|
|
return E_OUTOFMEMORY;
|
|
|
|
}
|
|
|
|
|
|
|
|
memcpy(dp->rgdispidNamedArgs+1, old, dp->cNamedArgs*sizeof(DISPID));
|
|
|
|
dp->rgdispidNamedArgs[0] = DISPID_THIS;
|
|
|
|
dp->cNamedArgs++;
|
|
|
|
}else {
|
|
|
|
dp->rgdispidNamedArgs = &this_id;
|
|
|
|
dp->cNamedArgs = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
2010-09-06 16:11:49 +02:00
|
|
|
static HRESULT invoke_prop_func(jsdisp_t *This, jsdisp_t *jsthis, dispex_prop_t *prop, WORD flags,
|
2008-09-09 01:20:26 +02:00
|
|
|
DISPPARAMS *dp, VARIANT *retv, jsexcept_t *ei, IServiceProvider *caller)
|
|
|
|
{
|
|
|
|
HRESULT hres;
|
|
|
|
|
|
|
|
switch(prop->type) {
|
2009-09-23 16:18:39 +02:00
|
|
|
case PROP_BUILTIN: {
|
|
|
|
vdisp_t vthis;
|
|
|
|
|
2010-10-19 23:14:16 +02:00
|
|
|
if(flags == DISPATCH_CONSTRUCT && (prop->flags & PROPF_METHOD)) {
|
2008-09-09 01:20:26 +02:00
|
|
|
WARN("%s is not a constructor\n", debugstr_w(prop->name));
|
|
|
|
return E_INVALIDARG;
|
|
|
|
}
|
2009-09-23 16:18:39 +02:00
|
|
|
|
|
|
|
set_jsdisp(&vthis, jsthis);
|
2012-03-14 12:32:43 +01:00
|
|
|
hres = prop->u.p->invoke(This->ctx, &vthis, flags, dp, retv, ei);
|
2009-09-23 16:18:39 +02:00
|
|
|
vdisp_release(&vthis);
|
|
|
|
return hres;
|
|
|
|
}
|
2008-09-09 01:20:26 +02:00
|
|
|
case PROP_PROTREF:
|
2009-09-23 16:10:06 +02:00
|
|
|
return invoke_prop_func(This->prototype, jsthis, This->prototype->props+prop->u.ref, flags, dp, retv, ei, caller);
|
2008-09-09 01:20:26 +02:00
|
|
|
case PROP_VARIANT: {
|
|
|
|
DISPPARAMS new_dp;
|
|
|
|
|
|
|
|
if(V_VT(&prop->u.var) != VT_DISPATCH) {
|
|
|
|
FIXME("invoke vt %d\n", V_VT(&prop->u.var));
|
|
|
|
return E_FAIL;
|
|
|
|
}
|
|
|
|
|
|
|
|
TRACE("call %s %p\n", debugstr_w(prop->name), V_DISPATCH(&prop->u.var));
|
|
|
|
|
2010-09-07 15:42:01 +02:00
|
|
|
hres = set_this(&new_dp, dp, to_disp(jsthis));
|
2008-09-09 01:20:26 +02:00
|
|
|
if(FAILED(hres))
|
|
|
|
return hres;
|
|
|
|
|
2012-03-08 14:28:33 +01:00
|
|
|
hres = disp_call(This->ctx, V_DISPATCH(&prop->u.var), DISPID_VALUE, flags, &new_dp, retv, ei);
|
2008-09-09 01:20:26 +02:00
|
|
|
|
|
|
|
if(new_dp.rgvarg != dp->rgvarg) {
|
|
|
|
heap_free(new_dp.rgvarg);
|
|
|
|
if(new_dp.cNamedArgs > 1)
|
|
|
|
heap_free(new_dp.rgdispidNamedArgs);
|
|
|
|
}
|
|
|
|
|
|
|
|
return hres;
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
ERR("type %d\n", prop->type);
|
|
|
|
}
|
|
|
|
|
|
|
|
return E_FAIL;
|
|
|
|
}
|
|
|
|
|
2010-09-06 16:11:49 +02:00
|
|
|
static HRESULT prop_get(jsdisp_t *This, dispex_prop_t *prop, DISPPARAMS *dp,
|
2008-09-09 01:20:26 +02:00
|
|
|
VARIANT *retv, jsexcept_t *ei, IServiceProvider *caller)
|
|
|
|
{
|
|
|
|
HRESULT hres;
|
|
|
|
|
|
|
|
switch(prop->type) {
|
|
|
|
case PROP_BUILTIN:
|
|
|
|
if(prop->u.p->flags & PROPF_METHOD) {
|
2010-09-06 16:11:49 +02:00
|
|
|
jsdisp_t *obj;
|
2009-09-17 01:04:44 +02:00
|
|
|
hres = create_builtin_function(This->ctx, prop->u.p->invoke, prop->u.p->name, NULL,
|
|
|
|
prop->u.p->flags, NULL, &obj);
|
2008-09-09 01:27:01 +02:00
|
|
|
if(FAILED(hres))
|
|
|
|
break;
|
|
|
|
|
|
|
|
prop->type = PROP_VARIANT;
|
2010-09-07 15:41:40 +02:00
|
|
|
var_set_jsdisp(&prop->u.var, obj);
|
2008-09-09 01:27:01 +02:00
|
|
|
hres = VariantCopy(retv, &prop->u.var);
|
2008-09-09 01:20:26 +02:00
|
|
|
}else {
|
2009-09-23 16:18:39 +02:00
|
|
|
vdisp_t vthis;
|
|
|
|
|
|
|
|
set_jsdisp(&vthis, This);
|
2012-03-14 12:32:43 +01:00
|
|
|
hres = prop->u.p->invoke(This->ctx, &vthis, DISPATCH_PROPERTYGET, dp, retv, ei);
|
2009-09-23 16:18:39 +02:00
|
|
|
vdisp_release(&vthis);
|
2008-09-09 01:20:26 +02:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case PROP_PROTREF:
|
2009-09-23 16:10:36 +02:00
|
|
|
hres = prop_get(This->prototype, This->prototype->props+prop->u.ref, dp, retv, ei, caller);
|
2008-09-09 01:20:26 +02:00
|
|
|
break;
|
|
|
|
case PROP_VARIANT:
|
|
|
|
hres = VariantCopy(retv, &prop->u.var);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
ERR("type %d\n", prop->type);
|
|
|
|
return E_FAIL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(FAILED(hres)) {
|
|
|
|
TRACE("fail %08x\n", hres);
|
|
|
|
return hres;
|
|
|
|
}
|
|
|
|
|
|
|
|
TRACE("%s ret %s\n", debugstr_w(prop->name), debugstr_variant(retv));
|
|
|
|
return hres;
|
|
|
|
}
|
|
|
|
|
2010-09-06 16:11:49 +02:00
|
|
|
static HRESULT prop_put(jsdisp_t *This, dispex_prop_t *prop, VARIANT *val,
|
2008-09-09 01:20:26 +02:00
|
|
|
jsexcept_t *ei, IServiceProvider *caller)
|
|
|
|
{
|
|
|
|
HRESULT hres;
|
|
|
|
|
2010-05-26 19:17:21 +02:00
|
|
|
if(prop->flags & PROPF_CONST)
|
|
|
|
return S_OK;
|
|
|
|
|
2008-09-09 01:20:26 +02:00
|
|
|
switch(prop->type) {
|
|
|
|
case PROP_BUILTIN:
|
2009-09-23 16:18:39 +02:00
|
|
|
if(!(prop->flags & PROPF_METHOD)) {
|
2010-02-05 23:15:46 +01:00
|
|
|
DISPPARAMS dp = {val, NULL, 1, 0};
|
2009-09-23 16:18:39 +02:00
|
|
|
vdisp_t vthis;
|
|
|
|
|
|
|
|
set_jsdisp(&vthis, This);
|
2012-03-14 12:32:43 +01:00
|
|
|
hres = prop->u.p->invoke(This->ctx, &vthis, DISPATCH_PROPERTYPUT, &dp, NULL, ei);
|
2009-09-23 16:18:39 +02:00
|
|
|
vdisp_release(&vthis);
|
|
|
|
return hres;
|
|
|
|
}
|
2008-09-09 01:20:26 +02:00
|
|
|
case PROP_PROTREF:
|
|
|
|
prop->type = PROP_VARIANT;
|
|
|
|
prop->flags = PROPF_ENUM;
|
|
|
|
V_VT(&prop->u.var) = VT_EMPTY;
|
|
|
|
break;
|
|
|
|
case PROP_VARIANT:
|
|
|
|
VariantClear(&prop->u.var);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
ERR("type %d\n", prop->type);
|
|
|
|
return E_FAIL;
|
|
|
|
}
|
|
|
|
|
2010-02-05 23:15:46 +01:00
|
|
|
hres = VariantCopy(&prop->u.var, val);
|
2008-09-09 01:20:26 +02:00
|
|
|
if(FAILED(hres))
|
|
|
|
return hres;
|
|
|
|
|
|
|
|
if(This->builtin_info->on_put)
|
|
|
|
This->builtin_info->on_put(This, prop->name);
|
|
|
|
|
2010-02-05 23:15:46 +01:00
|
|
|
TRACE("%s = %s\n", debugstr_w(prop->name), debugstr_variant(val));
|
2008-09-09 01:20:26 +02:00
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
2010-09-06 16:11:49 +02:00
|
|
|
static HRESULT fill_protrefs(jsdisp_t *This)
|
2008-09-09 01:20:52 +02:00
|
|
|
{
|
|
|
|
dispex_prop_t *iter, *prop;
|
|
|
|
HRESULT hres;
|
|
|
|
|
|
|
|
if(!This->prototype)
|
|
|
|
return S_OK;
|
|
|
|
|
|
|
|
fill_protrefs(This->prototype);
|
|
|
|
|
|
|
|
for(iter = This->prototype->props; iter < This->prototype->props+This->prototype->prop_cnt; iter++) {
|
2008-09-19 00:43:21 +02:00
|
|
|
if(!iter->name)
|
|
|
|
continue;
|
2011-09-02 12:24:35 +02:00
|
|
|
hres = find_prop_name(This, iter->hash, iter->name, &prop);
|
2008-09-09 01:20:52 +02:00
|
|
|
if(FAILED(hres))
|
|
|
|
return hres;
|
2011-09-02 12:24:25 +02:00
|
|
|
if(!prop || prop->type==PROP_DELETED) {
|
|
|
|
if(prop) {
|
|
|
|
prop->type = PROP_PROTREF;
|
|
|
|
prop->flags = 0;
|
|
|
|
prop->u.ref = iter - This->prototype->props;
|
|
|
|
}else {
|
|
|
|
prop = alloc_protref(This, iter->name, iter - This->prototype->props);
|
|
|
|
if(!prop)
|
|
|
|
return E_OUTOFMEMORY;
|
|
|
|
}
|
2008-09-09 01:20:52 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
2011-01-16 21:27:20 +01:00
|
|
|
static inline jsdisp_t *impl_from_IDispatchEx(IDispatchEx *iface)
|
|
|
|
{
|
|
|
|
return CONTAINING_RECORD(iface, jsdisp_t, IDispatchEx_iface);
|
|
|
|
}
|
2008-09-01 01:23:38 +02:00
|
|
|
|
|
|
|
static HRESULT WINAPI DispatchEx_QueryInterface(IDispatchEx *iface, REFIID riid, void **ppv)
|
|
|
|
{
|
2011-01-16 21:27:20 +01:00
|
|
|
jsdisp_t *This = impl_from_IDispatchEx(iface);
|
2008-09-01 01:23:38 +02:00
|
|
|
|
|
|
|
if(IsEqualGUID(&IID_IUnknown, riid)) {
|
|
|
|
TRACE("(%p)->(IID_IUnknown %p)\n", This, ppv);
|
2011-01-16 21:27:20 +01:00
|
|
|
*ppv = &This->IDispatchEx_iface;
|
2008-09-01 01:23:38 +02:00
|
|
|
}else if(IsEqualGUID(&IID_IDispatch, riid)) {
|
|
|
|
TRACE("(%p)->(IID_IDispatch %p)\n", This, ppv);
|
2011-01-16 21:27:20 +01:00
|
|
|
*ppv = &This->IDispatchEx_iface;
|
2008-09-01 01:23:38 +02:00
|
|
|
}else if(IsEqualGUID(&IID_IDispatchEx, riid)) {
|
|
|
|
TRACE("(%p)->(IID_IDispatchEx %p)\n", This, ppv);
|
2011-01-16 21:27:20 +01:00
|
|
|
*ppv = &This->IDispatchEx_iface;
|
2008-09-09 01:20:26 +02:00
|
|
|
}else if(IsEqualGUID(&IID_IDispatchJS, riid)) {
|
|
|
|
TRACE("(%p)->(IID_IDispatchJS %p)\n", This, ppv);
|
2010-09-07 15:42:34 +02:00
|
|
|
jsdisp_addref(This);
|
2008-09-09 01:20:26 +02:00
|
|
|
*ppv = This;
|
|
|
|
return S_OK;
|
2008-09-01 01:23:38 +02:00
|
|
|
}else {
|
|
|
|
WARN("(%p)->(%s %p)\n", This, debugstr_guid(riid), ppv);
|
|
|
|
*ppv = NULL;
|
|
|
|
return E_NOINTERFACE;
|
|
|
|
}
|
|
|
|
|
|
|
|
IUnknown_AddRef((IUnknown*)*ppv);
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
static ULONG WINAPI DispatchEx_AddRef(IDispatchEx *iface)
|
|
|
|
{
|
2011-01-16 21:27:20 +01:00
|
|
|
jsdisp_t *This = impl_from_IDispatchEx(iface);
|
2008-09-01 01:23:38 +02:00
|
|
|
LONG ref = InterlockedIncrement(&This->ref);
|
|
|
|
|
|
|
|
TRACE("(%p) ref=%d\n", This, ref);
|
|
|
|
|
|
|
|
return ref;
|
|
|
|
}
|
|
|
|
|
|
|
|
static ULONG WINAPI DispatchEx_Release(IDispatchEx *iface)
|
|
|
|
{
|
2011-01-16 21:27:20 +01:00
|
|
|
jsdisp_t *This = impl_from_IDispatchEx(iface);
|
2008-09-01 01:23:38 +02:00
|
|
|
LONG ref = InterlockedDecrement(&This->ref);
|
|
|
|
|
|
|
|
TRACE("(%p) ref=%d\n", This, ref);
|
|
|
|
|
|
|
|
if(!ref) {
|
2008-09-08 00:14:38 +02:00
|
|
|
dispex_prop_t *prop;
|
|
|
|
|
|
|
|
for(prop = This->props; prop < This->props+This->prop_cnt; prop++) {
|
|
|
|
if(prop->type == PROP_VARIANT)
|
|
|
|
VariantClear(&prop->u.var);
|
|
|
|
heap_free(prop->name);
|
|
|
|
}
|
|
|
|
heap_free(This->props);
|
2008-09-01 01:23:38 +02:00
|
|
|
script_release(This->ctx);
|
2009-12-31 13:03:01 +01:00
|
|
|
if(This->prototype)
|
|
|
|
jsdisp_release(This->prototype);
|
2008-09-08 00:14:38 +02:00
|
|
|
|
|
|
|
if(This->builtin_info->destructor)
|
|
|
|
This->builtin_info->destructor(This);
|
|
|
|
else
|
|
|
|
heap_free(This);
|
2008-09-01 01:23:38 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return ref;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI DispatchEx_GetTypeInfoCount(IDispatchEx *iface, UINT *pctinfo)
|
|
|
|
{
|
2011-01-16 21:27:20 +01:00
|
|
|
jsdisp_t *This = impl_from_IDispatchEx(iface);
|
2008-09-01 01:23:38 +02:00
|
|
|
|
|
|
|
TRACE("(%p)->(%p)\n", This, pctinfo);
|
|
|
|
|
|
|
|
*pctinfo = 1;
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
2009-09-23 16:12:12 +02:00
|
|
|
static HRESULT WINAPI DispatchEx_GetTypeInfo(IDispatchEx *iface, UINT iTInfo, LCID lcid,
|
|
|
|
ITypeInfo **ppTInfo)
|
2008-09-01 01:23:38 +02:00
|
|
|
{
|
2011-01-16 21:27:20 +01:00
|
|
|
jsdisp_t *This = impl_from_IDispatchEx(iface);
|
2008-09-01 01:23:38 +02:00
|
|
|
FIXME("(%p)->(%u %u %p)\n", This, iTInfo, lcid, ppTInfo);
|
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI DispatchEx_GetIDsOfNames(IDispatchEx *iface, REFIID riid,
|
2009-09-23 16:12:12 +02:00
|
|
|
LPOLESTR *rgszNames, UINT cNames, LCID lcid,
|
|
|
|
DISPID *rgDispId)
|
2008-09-01 01:23:38 +02:00
|
|
|
{
|
2011-01-16 21:27:20 +01:00
|
|
|
jsdisp_t *This = impl_from_IDispatchEx(iface);
|
2008-09-01 01:24:23 +02:00
|
|
|
UINT i;
|
|
|
|
HRESULT hres;
|
|
|
|
|
|
|
|
TRACE("(%p)->(%s %p %u %u %p)\n", This, debugstr_guid(riid), rgszNames, cNames,
|
2008-09-01 01:23:38 +02:00
|
|
|
lcid, rgDispId);
|
2008-09-01 01:24:23 +02:00
|
|
|
|
|
|
|
for(i=0; i < cNames; i++) {
|
2011-01-16 21:27:20 +01:00
|
|
|
hres = IDispatchEx_GetDispID(&This->IDispatchEx_iface, rgszNames[i], 0, rgDispId+i);
|
2008-09-01 01:24:23 +02:00
|
|
|
if(FAILED(hres))
|
|
|
|
return hres;
|
|
|
|
}
|
|
|
|
|
|
|
|
return S_OK;
|
2008-09-01 01:23:38 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI DispatchEx_Invoke(IDispatchEx *iface, DISPID dispIdMember,
|
2009-09-23 16:12:12 +02:00
|
|
|
REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS *pDispParams,
|
2008-09-01 01:23:38 +02:00
|
|
|
VARIANT *pVarResult, EXCEPINFO *pExcepInfo, UINT *puArgErr)
|
|
|
|
{
|
2011-01-16 21:27:20 +01:00
|
|
|
jsdisp_t *This = impl_from_IDispatchEx(iface);
|
2008-09-01 01:24:57 +02:00
|
|
|
|
|
|
|
TRACE("(%p)->(%d %s %d %d %p %p %p %p)\n", This, dispIdMember, debugstr_guid(riid),
|
2008-09-01 01:23:38 +02:00
|
|
|
lcid, wFlags, pDispParams, pVarResult, pExcepInfo, puArgErr);
|
2008-09-01 01:24:57 +02:00
|
|
|
|
2011-01-16 21:27:20 +01:00
|
|
|
return IDispatchEx_InvokeEx(&This->IDispatchEx_iface, dispIdMember, lcid, wFlags,
|
2008-09-01 01:24:57 +02:00
|
|
|
pDispParams, pVarResult, pExcepInfo, NULL);
|
2008-09-01 01:23:38 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI DispatchEx_GetDispID(IDispatchEx *iface, BSTR bstrName, DWORD grfdex, DISPID *pid)
|
|
|
|
{
|
2011-01-16 21:27:20 +01:00
|
|
|
jsdisp_t *This = impl_from_IDispatchEx(iface);
|
2008-09-08 00:14:58 +02:00
|
|
|
|
|
|
|
TRACE("(%p)->(%s %x %p)\n", This, debugstr_w(bstrName), grfdex, pid);
|
|
|
|
|
2009-10-19 20:39:56 +02:00
|
|
|
if(grfdex & ~(fdexNameCaseSensitive|fdexNameEnsure|fdexNameImplicit|FDEX_VERSION_MASK)) {
|
2008-09-08 00:14:58 +02:00
|
|
|
FIXME("Unsupported grfdex %x\n", grfdex);
|
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
2008-09-30 17:47:24 +02:00
|
|
|
return jsdisp_get_id(This, bstrName, grfdex, pid);
|
2008-09-01 01:23:38 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI DispatchEx_InvokeEx(IDispatchEx *iface, DISPID id, LCID lcid, WORD wFlags, DISPPARAMS *pdp,
|
|
|
|
VARIANT *pvarRes, EXCEPINFO *pei, IServiceProvider *pspCaller)
|
|
|
|
{
|
2011-01-16 21:27:20 +01:00
|
|
|
jsdisp_t *This = impl_from_IDispatchEx(iface);
|
2008-09-09 01:20:26 +02:00
|
|
|
dispex_prop_t *prop;
|
|
|
|
jsexcept_t jsexcept;
|
|
|
|
HRESULT hres;
|
|
|
|
|
|
|
|
TRACE("(%p)->(%x %x %x %p %p %p %p)\n", This, id, lcid, wFlags, pdp, pvarRes, pei, pspCaller);
|
|
|
|
|
|
|
|
if(pvarRes)
|
|
|
|
V_VT(pvarRes) = VT_EMPTY;
|
|
|
|
|
|
|
|
prop = get_prop(This, id);
|
|
|
|
if(!prop || prop->type == PROP_DELETED) {
|
|
|
|
TRACE("invalid id\n");
|
|
|
|
return DISP_E_MEMBERNOTFOUND;
|
|
|
|
}
|
|
|
|
|
|
|
|
memset(&jsexcept, 0, sizeof(jsexcept));
|
|
|
|
|
|
|
|
switch(wFlags) {
|
2010-10-19 23:14:16 +02:00
|
|
|
case DISPATCH_METHOD|DISPATCH_PROPERTYGET:
|
|
|
|
wFlags = DISPATCH_METHOD;
|
2011-10-08 21:10:15 +02:00
|
|
|
/* fall through */
|
2008-09-09 01:20:26 +02:00
|
|
|
case DISPATCH_METHOD:
|
|
|
|
case DISPATCH_CONSTRUCT:
|
2009-09-23 16:10:06 +02:00
|
|
|
hres = invoke_prop_func(This, This, prop, wFlags, pdp, pvarRes, &jsexcept, pspCaller);
|
2008-09-09 01:20:26 +02:00
|
|
|
break;
|
|
|
|
case DISPATCH_PROPERTYGET:
|
2009-09-23 16:10:36 +02:00
|
|
|
hres = prop_get(This, prop, pdp, pvarRes, &jsexcept, pspCaller);
|
2008-09-09 01:20:26 +02:00
|
|
|
break;
|
2010-02-05 23:15:46 +01:00
|
|
|
case DISPATCH_PROPERTYPUT: {
|
|
|
|
DWORD i;
|
|
|
|
|
|
|
|
for(i=0; i < pdp->cNamedArgs; i++) {
|
|
|
|
if(pdp->rgdispidNamedArgs[i] == DISPID_PROPERTYPUT)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(i == pdp->cNamedArgs) {
|
|
|
|
TRACE("no value to set\n");
|
|
|
|
return DISP_E_PARAMNOTOPTIONAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
hres = prop_put(This, prop, pdp->rgvarg+i, &jsexcept, pspCaller);
|
2008-09-09 01:20:26 +02:00
|
|
|
break;
|
2010-02-05 23:15:46 +01:00
|
|
|
}
|
2008-09-09 01:20:26 +02:00
|
|
|
default:
|
|
|
|
FIXME("Unimplemented flags %x\n", wFlags);
|
|
|
|
return E_INVALIDARG;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(pei)
|
|
|
|
*pei = jsexcept.ei;
|
|
|
|
|
|
|
|
return hres;
|
2008-09-01 01:23:38 +02:00
|
|
|
}
|
|
|
|
|
2008-09-30 17:48:36 +02:00
|
|
|
static HRESULT delete_prop(dispex_prop_t *prop)
|
|
|
|
{
|
2011-09-02 12:24:25 +02:00
|
|
|
if(prop->type == PROP_VARIANT) {
|
|
|
|
VariantClear(&prop->u.var);
|
|
|
|
prop->type = PROP_DELETED;
|
|
|
|
}
|
2008-09-30 17:48:36 +02:00
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
2008-09-01 01:23:38 +02:00
|
|
|
static HRESULT WINAPI DispatchEx_DeleteMemberByName(IDispatchEx *iface, BSTR bstrName, DWORD grfdex)
|
|
|
|
{
|
2011-01-16 21:27:20 +01:00
|
|
|
jsdisp_t *This = impl_from_IDispatchEx(iface);
|
2008-09-09 01:21:14 +02:00
|
|
|
dispex_prop_t *prop;
|
|
|
|
HRESULT hres;
|
|
|
|
|
|
|
|
TRACE("(%p)->(%s %x)\n", This, debugstr_w(bstrName), grfdex);
|
|
|
|
|
2009-10-19 20:39:56 +02:00
|
|
|
if(grfdex & ~(fdexNameCaseSensitive|fdexNameEnsure|fdexNameImplicit|FDEX_VERSION_MASK))
|
2008-09-09 01:21:14 +02:00
|
|
|
FIXME("Unsupported grfdex %x\n", grfdex);
|
|
|
|
|
2011-09-02 12:24:35 +02:00
|
|
|
hres = find_prop_name(This, string_hash(bstrName), bstrName, &prop);
|
2008-09-09 01:21:14 +02:00
|
|
|
if(FAILED(hres))
|
|
|
|
return hres;
|
|
|
|
if(!prop) {
|
|
|
|
TRACE("not found\n");
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
2008-09-30 17:48:36 +02:00
|
|
|
return delete_prop(prop);
|
2008-09-01 01:23:38 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI DispatchEx_DeleteMemberByDispID(IDispatchEx *iface, DISPID id)
|
|
|
|
{
|
2011-01-16 21:27:20 +01:00
|
|
|
jsdisp_t *This = impl_from_IDispatchEx(iface);
|
2008-09-30 17:48:36 +02:00
|
|
|
dispex_prop_t *prop;
|
|
|
|
|
|
|
|
TRACE("(%p)->(%x)\n", This, id);
|
|
|
|
|
|
|
|
prop = get_prop(This, id);
|
|
|
|
if(!prop) {
|
|
|
|
WARN("invalid id\n");
|
|
|
|
return DISP_E_MEMBERNOTFOUND;
|
|
|
|
}
|
|
|
|
|
|
|
|
return delete_prop(prop);
|
2008-09-01 01:23:38 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI DispatchEx_GetMemberProperties(IDispatchEx *iface, DISPID id, DWORD grfdexFetch, DWORD *pgrfdex)
|
|
|
|
{
|
2011-01-16 21:27:20 +01:00
|
|
|
jsdisp_t *This = impl_from_IDispatchEx(iface);
|
2008-09-01 01:23:38 +02:00
|
|
|
FIXME("(%p)->(%x %x %p)\n", This, id, grfdexFetch, pgrfdex);
|
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI DispatchEx_GetMemberName(IDispatchEx *iface, DISPID id, BSTR *pbstrName)
|
|
|
|
{
|
2011-01-16 21:27:20 +01:00
|
|
|
jsdisp_t *This = impl_from_IDispatchEx(iface);
|
2008-09-09 01:21:38 +02:00
|
|
|
dispex_prop_t *prop;
|
|
|
|
|
|
|
|
TRACE("(%p)->(%x %p)\n", This, id, pbstrName);
|
|
|
|
|
|
|
|
prop = get_prop(This, id);
|
|
|
|
if(!prop || !prop->name || prop->type == PROP_DELETED)
|
|
|
|
return DISP_E_MEMBERNOTFOUND;
|
|
|
|
|
|
|
|
*pbstrName = SysAllocString(prop->name);
|
|
|
|
if(!*pbstrName)
|
|
|
|
return E_OUTOFMEMORY;
|
|
|
|
|
|
|
|
return S_OK;
|
2008-09-01 01:23:38 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI DispatchEx_GetNextDispID(IDispatchEx *iface, DWORD grfdex, DISPID id, DISPID *pid)
|
|
|
|
{
|
2011-01-16 21:27:20 +01:00
|
|
|
jsdisp_t *This = impl_from_IDispatchEx(iface);
|
2008-09-09 01:20:52 +02:00
|
|
|
dispex_prop_t *iter;
|
|
|
|
HRESULT hres;
|
|
|
|
|
|
|
|
TRACE("(%p)->(%x %x %p)\n", This, grfdex, id, pid);
|
|
|
|
|
|
|
|
if(id == DISPID_STARTENUM) {
|
|
|
|
hres = fill_protrefs(This);
|
|
|
|
if(FAILED(hres))
|
|
|
|
return hres;
|
|
|
|
}
|
|
|
|
|
2011-09-02 12:24:25 +02:00
|
|
|
if(id+1>=0 && id+1<This->prop_cnt) {
|
|
|
|
iter = &This->props[id+1];
|
|
|
|
}else {
|
2008-09-09 01:20:52 +02:00
|
|
|
*pid = DISPID_STARTENUM;
|
|
|
|
return S_FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
while(iter < This->props + This->prop_cnt) {
|
2011-09-02 12:24:25 +02:00
|
|
|
if(iter->name && (get_flags(This, iter) & PROPF_ENUM) && iter->type!=PROP_DELETED) {
|
2008-09-09 01:20:52 +02:00
|
|
|
*pid = prop_to_id(This, iter);
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
iter++;
|
|
|
|
}
|
|
|
|
|
|
|
|
*pid = DISPID_STARTENUM;
|
|
|
|
return S_FALSE;
|
2008-09-01 01:23:38 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI DispatchEx_GetNameSpaceParent(IDispatchEx *iface, IUnknown **ppunk)
|
|
|
|
{
|
2011-01-16 21:27:20 +01:00
|
|
|
jsdisp_t *This = impl_from_IDispatchEx(iface);
|
2008-09-01 01:23:38 +02:00
|
|
|
FIXME("(%p)->(%p)\n", This, ppunk);
|
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static IDispatchExVtbl DispatchExVtbl = {
|
|
|
|
DispatchEx_QueryInterface,
|
|
|
|
DispatchEx_AddRef,
|
|
|
|
DispatchEx_Release,
|
|
|
|
DispatchEx_GetTypeInfoCount,
|
|
|
|
DispatchEx_GetTypeInfo,
|
|
|
|
DispatchEx_GetIDsOfNames,
|
|
|
|
DispatchEx_Invoke,
|
|
|
|
DispatchEx_GetDispID,
|
|
|
|
DispatchEx_InvokeEx,
|
|
|
|
DispatchEx_DeleteMemberByName,
|
|
|
|
DispatchEx_DeleteMemberByDispID,
|
|
|
|
DispatchEx_GetMemberProperties,
|
|
|
|
DispatchEx_GetMemberName,
|
|
|
|
DispatchEx_GetNextDispID,
|
|
|
|
DispatchEx_GetNameSpaceParent
|
|
|
|
};
|
|
|
|
|
2011-12-16 11:43:31 +01:00
|
|
|
jsdisp_t *as_jsdisp(IDispatch *disp)
|
|
|
|
{
|
|
|
|
assert(disp->lpVtbl == (IDispatchVtbl*)&DispatchExVtbl);
|
|
|
|
return impl_from_IDispatchEx((IDispatchEx*)disp);
|
|
|
|
}
|
|
|
|
|
2011-12-27 11:16:26 +01:00
|
|
|
jsdisp_t *to_jsdisp(IDispatch *disp)
|
|
|
|
{
|
|
|
|
return disp->lpVtbl == (IDispatchVtbl*)&DispatchExVtbl ? impl_from_IDispatchEx((IDispatchEx*)disp) : NULL;
|
|
|
|
}
|
|
|
|
|
2010-09-06 16:11:49 +02:00
|
|
|
HRESULT init_dispex(jsdisp_t *dispex, script_ctx_t *ctx, const builtin_info_t *builtin_info, jsdisp_t *prototype)
|
2008-09-01 01:23:38 +02:00
|
|
|
{
|
2008-09-08 00:14:38 +02:00
|
|
|
TRACE("%p (%p)\n", dispex, prototype);
|
|
|
|
|
2011-01-16 21:27:20 +01:00
|
|
|
dispex->IDispatchEx_iface.lpVtbl = &DispatchExVtbl;
|
2008-09-01 01:23:38 +02:00
|
|
|
dispex->ref = 1;
|
2008-09-08 00:14:38 +02:00
|
|
|
dispex->builtin_info = builtin_info;
|
|
|
|
|
2011-09-02 12:24:25 +02:00
|
|
|
dispex->props = heap_alloc_zero(sizeof(dispex_prop_t)*(dispex->buf_size=4));
|
2008-09-08 00:14:38 +02:00
|
|
|
if(!dispex->props)
|
|
|
|
return E_OUTOFMEMORY;
|
|
|
|
|
|
|
|
dispex->prototype = prototype;
|
|
|
|
if(prototype)
|
2010-09-07 15:42:34 +02:00
|
|
|
jsdisp_addref(prototype);
|
2008-09-08 00:14:38 +02:00
|
|
|
|
2008-09-10 02:33:15 +02:00
|
|
|
dispex->prop_cnt = 1;
|
2008-09-08 00:14:38 +02:00
|
|
|
if(builtin_info->value_prop.invoke) {
|
|
|
|
dispex->props[0].type = PROP_BUILTIN;
|
|
|
|
dispex->props[0].u.p = &builtin_info->value_prop;
|
|
|
|
}else {
|
|
|
|
dispex->props[0].type = PROP_DELETED;
|
|
|
|
}
|
|
|
|
|
2008-09-01 01:23:38 +02:00
|
|
|
script_addref(ctx);
|
|
|
|
dispex->ctx = ctx;
|
|
|
|
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
2008-09-08 00:14:38 +02:00
|
|
|
static const builtin_info_t dispex_info = {
|
|
|
|
JSCLASS_NONE,
|
|
|
|
{NULL, NULL, 0},
|
|
|
|
0, NULL,
|
|
|
|
NULL,
|
|
|
|
NULL
|
|
|
|
};
|
|
|
|
|
2010-09-06 16:11:49 +02:00
|
|
|
HRESULT create_dispex(script_ctx_t *ctx, const builtin_info_t *builtin_info, jsdisp_t *prototype, jsdisp_t **dispex)
|
2008-09-01 01:23:38 +02:00
|
|
|
{
|
2010-09-06 16:11:49 +02:00
|
|
|
jsdisp_t *ret;
|
2008-09-01 01:23:38 +02:00
|
|
|
HRESULT hres;
|
|
|
|
|
2010-09-06 16:11:49 +02:00
|
|
|
ret = heap_alloc_zero(sizeof(jsdisp_t));
|
2008-09-01 01:23:38 +02:00
|
|
|
if(!ret)
|
|
|
|
return E_OUTOFMEMORY;
|
|
|
|
|
2008-09-08 00:14:38 +02:00
|
|
|
hres = init_dispex(ret, ctx, builtin_info ? builtin_info : &dispex_info, prototype);
|
2008-09-01 01:23:38 +02:00
|
|
|
if(FAILED(hres))
|
|
|
|
return hres;
|
|
|
|
|
|
|
|
*dispex = ret;
|
|
|
|
return S_OK;
|
|
|
|
}
|
2008-09-09 01:20:26 +02:00
|
|
|
|
2010-09-06 16:11:49 +02:00
|
|
|
HRESULT init_dispex_from_constr(jsdisp_t *dispex, script_ctx_t *ctx, const builtin_info_t *builtin_info, jsdisp_t *constr)
|
2008-09-10 02:33:15 +02:00
|
|
|
{
|
2010-09-06 16:11:49 +02:00
|
|
|
jsdisp_t *prot = NULL;
|
2008-09-10 02:33:15 +02:00
|
|
|
dispex_prop_t *prop;
|
|
|
|
HRESULT hres;
|
|
|
|
|
2010-10-09 16:10:56 +02:00
|
|
|
static const WCHAR constructorW[] = {'c','o','n','s','t','r','u','c','t','o','r',0};
|
2008-09-10 02:33:15 +02:00
|
|
|
static const WCHAR prototypeW[] = {'p','r','o','t','o','t','y','p','e',0};
|
|
|
|
|
2011-09-02 12:24:35 +02:00
|
|
|
hres = find_prop_name_prot(constr, string_hash(prototypeW), prototypeW, &prop);
|
2011-09-02 12:24:25 +02:00
|
|
|
if(SUCCEEDED(hres) && prop && prop->type!=PROP_DELETED) {
|
2008-09-10 02:33:15 +02:00
|
|
|
jsexcept_t jsexcept;
|
|
|
|
VARIANT var;
|
|
|
|
|
|
|
|
V_VT(&var) = VT_EMPTY;
|
|
|
|
memset(&jsexcept, 0, sizeof(jsexcept));
|
2009-09-23 16:10:36 +02:00
|
|
|
hres = prop_get(constr, prop, NULL, &var, &jsexcept, NULL/*FIXME*/);
|
2008-09-10 02:33:15 +02:00
|
|
|
if(FAILED(hres)) {
|
|
|
|
ERR("Could not get prototype\n");
|
|
|
|
return hres;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(V_VT(&var) == VT_DISPATCH)
|
|
|
|
prot = iface_to_jsdisp((IUnknown*)V_DISPATCH(&var));
|
|
|
|
VariantClear(&var);
|
|
|
|
}
|
|
|
|
|
|
|
|
hres = init_dispex(dispex, ctx, builtin_info, prot);
|
|
|
|
|
|
|
|
if(prot)
|
2009-09-01 13:26:08 +02:00
|
|
|
jsdisp_release(prot);
|
2010-02-05 23:17:35 +01:00
|
|
|
if(FAILED(hres))
|
|
|
|
return hres;
|
|
|
|
|
|
|
|
hres = ensure_prop_name(dispex, constructorW, FALSE, 0, &prop);
|
|
|
|
if(SUCCEEDED(hres)) {
|
|
|
|
jsexcept_t jsexcept;
|
|
|
|
VARIANT var;
|
|
|
|
|
2010-09-07 15:41:40 +02:00
|
|
|
var_set_jsdisp(&var, constr);
|
2010-02-05 23:17:35 +01:00
|
|
|
memset(&jsexcept, 0, sizeof(jsexcept));
|
|
|
|
hres = prop_put(dispex, prop, &var, &jsexcept, NULL/*FIXME*/);
|
|
|
|
}
|
|
|
|
if(FAILED(hres))
|
|
|
|
jsdisp_release(dispex);
|
|
|
|
|
2008-09-10 02:33:15 +02:00
|
|
|
return hres;
|
|
|
|
}
|
|
|
|
|
2010-09-06 16:11:49 +02:00
|
|
|
jsdisp_t *iface_to_jsdisp(IUnknown *iface)
|
2008-09-09 01:20:26 +02:00
|
|
|
{
|
2010-09-06 16:11:49 +02:00
|
|
|
jsdisp_t *ret;
|
2008-09-09 01:20:26 +02:00
|
|
|
HRESULT hres;
|
|
|
|
|
|
|
|
hres = IUnknown_QueryInterface(iface, &IID_IDispatchJS, (void**)&ret);
|
|
|
|
if(FAILED(hres))
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2010-09-06 16:11:49 +02:00
|
|
|
HRESULT jsdisp_get_id(jsdisp_t *jsdisp, const WCHAR *name, DWORD flags, DISPID *id)
|
2008-09-30 17:47:24 +02:00
|
|
|
{
|
|
|
|
dispex_prop_t *prop;
|
|
|
|
HRESULT hres;
|
|
|
|
|
2010-02-05 23:15:07 +01:00
|
|
|
if(flags & fdexNameEnsure)
|
2010-02-05 23:17:06 +01:00
|
|
|
hres = ensure_prop_name(jsdisp, name, TRUE, PROPF_ENUM, &prop);
|
2010-02-05 23:15:07 +01:00
|
|
|
else
|
2011-09-02 12:24:35 +02:00
|
|
|
hres = find_prop_name_prot(jsdisp, string_hash(name), name, &prop);
|
2008-09-30 17:47:24 +02:00
|
|
|
if(FAILED(hres))
|
|
|
|
return hres;
|
|
|
|
|
2011-09-02 12:24:25 +02:00
|
|
|
if(prop && prop->type!=PROP_DELETED) {
|
2008-09-30 17:47:24 +02:00
|
|
|
*id = prop_to_id(jsdisp, prop);
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
TRACE("not found %s\n", debugstr_w(name));
|
|
|
|
return DISP_E_UNKNOWNNAME;
|
|
|
|
}
|
|
|
|
|
2012-03-12 12:13:10 +01:00
|
|
|
HRESULT jsdisp_call_value(jsdisp_t *jsthis, WORD flags, DISPPARAMS *dp, VARIANT *retv, jsexcept_t *ei)
|
2008-09-10 02:33:15 +02:00
|
|
|
{
|
2009-09-23 16:18:39 +02:00
|
|
|
vdisp_t vdisp;
|
|
|
|
HRESULT hres;
|
|
|
|
|
|
|
|
set_jsdisp(&vdisp, jsthis);
|
2012-03-14 12:32:43 +01:00
|
|
|
hres = jsthis->builtin_info->value_prop.invoke(jsthis->ctx, &vdisp, flags, dp, retv, ei);
|
2009-09-23 16:18:39 +02:00
|
|
|
vdisp_release(&vdisp);
|
|
|
|
return hres;
|
2008-09-10 02:33:15 +02:00
|
|
|
}
|
|
|
|
|
2012-03-08 14:28:33 +01:00
|
|
|
HRESULT jsdisp_call(jsdisp_t *disp, DISPID id, WORD flags, DISPPARAMS *dp, VARIANT *retv, jsexcept_t *ei)
|
2008-09-09 01:20:26 +02:00
|
|
|
{
|
|
|
|
dispex_prop_t *prop;
|
|
|
|
|
|
|
|
memset(ei, 0, sizeof(*ei));
|
|
|
|
if(retv)
|
|
|
|
V_VT(retv) = VT_EMPTY;
|
|
|
|
|
|
|
|
prop = get_prop(disp, id);
|
|
|
|
if(!prop)
|
|
|
|
return DISP_E_MEMBERNOTFOUND;
|
|
|
|
|
2012-03-08 14:28:33 +01:00
|
|
|
return invoke_prop_func(disp, disp, prop, flags, dp, retv, ei, NULL);
|
2008-09-09 01:20:26 +02:00
|
|
|
}
|
|
|
|
|
2010-09-06 16:11:49 +02:00
|
|
|
HRESULT jsdisp_call_name(jsdisp_t *disp, const WCHAR *name, WORD flags, DISPPARAMS *dp, VARIANT *retv,
|
2012-03-12 12:13:25 +01:00
|
|
|
jsexcept_t *ei)
|
2009-08-12 12:48:58 +02:00
|
|
|
{
|
|
|
|
dispex_prop_t *prop;
|
|
|
|
HRESULT hres;
|
|
|
|
|
2011-09-02 12:24:35 +02:00
|
|
|
hres = find_prop_name_prot(disp, string_hash(name), name, &prop);
|
2009-08-12 12:48:58 +02:00
|
|
|
if(FAILED(hres))
|
|
|
|
return hres;
|
|
|
|
|
|
|
|
memset(ei, 0, sizeof(*ei));
|
|
|
|
if(retv)
|
|
|
|
V_VT(retv) = VT_EMPTY;
|
|
|
|
|
2012-03-12 12:13:25 +01:00
|
|
|
return invoke_prop_func(disp, disp, prop, flags, dp, retv, ei, NULL);
|
2009-08-12 12:48:58 +02:00
|
|
|
}
|
|
|
|
|
2012-03-08 14:28:33 +01:00
|
|
|
HRESULT disp_call(script_ctx_t *ctx, IDispatch *disp, DISPID id, WORD flags, DISPPARAMS *dp, VARIANT *retv, jsexcept_t *ei)
|
2008-09-09 01:20:26 +02:00
|
|
|
{
|
2010-09-06 16:11:49 +02:00
|
|
|
jsdisp_t *jsdisp;
|
2008-09-09 01:20:26 +02:00
|
|
|
IDispatchEx *dispex;
|
|
|
|
HRESULT hres;
|
|
|
|
|
|
|
|
jsdisp = iface_to_jsdisp((IUnknown*)disp);
|
|
|
|
if(jsdisp) {
|
2012-03-08 14:28:33 +01:00
|
|
|
hres = jsdisp_call(jsdisp, id, flags, dp, retv, ei);
|
2009-09-01 13:26:08 +02:00
|
|
|
jsdisp_release(jsdisp);
|
2008-09-09 01:20:26 +02:00
|
|
|
return hres;
|
|
|
|
}
|
|
|
|
|
|
|
|
memset(ei, 0, sizeof(*ei));
|
2010-10-19 23:14:16 +02:00
|
|
|
if(retv && arg_cnt(dp))
|
|
|
|
flags |= DISPATCH_PROPERTYGET;
|
2008-09-09 01:20:26 +02:00
|
|
|
|
|
|
|
if(retv)
|
|
|
|
V_VT(retv) = VT_EMPTY;
|
|
|
|
hres = IDispatch_QueryInterface(disp, &IID_IDispatchEx, (void**)&dispex);
|
|
|
|
if(FAILED(hres)) {
|
|
|
|
UINT err = 0;
|
|
|
|
|
2008-09-21 15:47:05 +02:00
|
|
|
if(flags == DISPATCH_CONSTRUCT) {
|
|
|
|
WARN("IDispatch cannot be constructor\n");
|
|
|
|
return DISP_E_MEMBERNOTFOUND;
|
|
|
|
}
|
|
|
|
|
2008-09-09 01:20:26 +02:00
|
|
|
TRACE("using IDispatch\n");
|
2009-09-23 16:10:06 +02:00
|
|
|
return IDispatch_Invoke(disp, id, &IID_NULL, ctx->lcid, flags, dp, retv, &ei->ei, &err);
|
2008-09-09 01:20:26 +02:00
|
|
|
}
|
|
|
|
|
2012-03-08 14:28:16 +01:00
|
|
|
hres = IDispatchEx_InvokeEx(dispex, id, ctx->lcid, flags, dp, retv, &ei->ei, &ctx->jscaller->IServiceProvider_iface);
|
2008-09-09 01:20:26 +02:00
|
|
|
IDispatchEx_Release(dispex);
|
|
|
|
|
|
|
|
return hres;
|
2008-09-09 01:23:21 +02:00
|
|
|
}
|
|
|
|
|
2012-03-12 12:14:10 +01:00
|
|
|
HRESULT jsdisp_propput_name(jsdisp_t *obj, const WCHAR *name, VARIANT *val, jsexcept_t *ei)
|
2008-09-09 01:25:59 +02:00
|
|
|
{
|
|
|
|
dispex_prop_t *prop;
|
|
|
|
HRESULT hres;
|
|
|
|
|
2010-02-05 23:17:06 +01:00
|
|
|
hres = ensure_prop_name(obj, name, FALSE, PROPF_ENUM, &prop);
|
2008-09-09 01:25:59 +02:00
|
|
|
if(FAILED(hres))
|
|
|
|
return hres;
|
|
|
|
|
2012-03-12 12:14:10 +01:00
|
|
|
return prop_put(obj, prop, val, ei, NULL);
|
2008-09-09 01:25:59 +02:00
|
|
|
}
|
|
|
|
|
2010-09-06 16:11:49 +02:00
|
|
|
HRESULT jsdisp_propput_const(jsdisp_t *obj, const WCHAR *name, VARIANT *val)
|
2010-05-26 19:17:21 +02:00
|
|
|
{
|
|
|
|
dispex_prop_t *prop;
|
|
|
|
HRESULT hres;
|
|
|
|
|
|
|
|
hres = ensure_prop_name(obj, name, FALSE, PROPF_ENUM|PROPF_CONST, &prop);
|
|
|
|
if(FAILED(hres))
|
|
|
|
return hres;
|
|
|
|
|
|
|
|
return VariantCopy(&prop->u.var, val);
|
|
|
|
}
|
|
|
|
|
2012-03-12 12:14:25 +01:00
|
|
|
HRESULT jsdisp_propput_idx(jsdisp_t *obj, DWORD idx, VARIANT *val, jsexcept_t *ei)
|
2008-09-10 21:06:43 +02:00
|
|
|
{
|
|
|
|
WCHAR buf[12];
|
|
|
|
|
|
|
|
static const WCHAR formatW[] = {'%','d',0};
|
|
|
|
|
|
|
|
sprintfW(buf, formatW, idx);
|
2012-03-12 12:14:10 +01:00
|
|
|
return jsdisp_propput_name(obj, buf, val, ei);
|
2008-09-10 21:06:43 +02:00
|
|
|
}
|
|
|
|
|
2012-03-08 14:29:01 +01:00
|
|
|
HRESULT disp_propput(script_ctx_t *ctx, IDispatch *disp, DISPID id, VARIANT *val, jsexcept_t *ei)
|
2008-09-09 01:23:21 +02:00
|
|
|
{
|
2010-09-06 16:11:49 +02:00
|
|
|
jsdisp_t *jsdisp;
|
2008-09-09 01:23:21 +02:00
|
|
|
HRESULT hres;
|
|
|
|
|
|
|
|
jsdisp = iface_to_jsdisp((IUnknown*)disp);
|
|
|
|
if(jsdisp) {
|
|
|
|
dispex_prop_t *prop;
|
|
|
|
|
|
|
|
prop = get_prop(jsdisp, id);
|
|
|
|
if(prop)
|
2012-03-08 14:29:01 +01:00
|
|
|
hres = prop_put(jsdisp, prop, val, ei, NULL);
|
2008-09-09 01:23:21 +02:00
|
|
|
else
|
|
|
|
hres = DISP_E_MEMBERNOTFOUND;
|
|
|
|
|
2009-09-01 13:26:08 +02:00
|
|
|
jsdisp_release(jsdisp);
|
2010-02-05 23:15:46 +01:00
|
|
|
}else {
|
|
|
|
DISPID dispid = DISPID_PROPERTYPUT;
|
|
|
|
DISPPARAMS dp = {val, &dispid, 1, 1};
|
|
|
|
IDispatchEx *dispex;
|
|
|
|
|
|
|
|
hres = IDispatch_QueryInterface(disp, &IID_IDispatchEx, (void**)&dispex);
|
|
|
|
if(SUCCEEDED(hres)) {
|
2012-03-08 14:28:16 +01:00
|
|
|
hres = IDispatchEx_InvokeEx(dispex, id, ctx->lcid, DISPATCH_PROPERTYPUT, &dp, NULL, &ei->ei,
|
|
|
|
&ctx->jscaller->IServiceProvider_iface);
|
2010-02-05 23:15:46 +01:00
|
|
|
IDispatchEx_Release(dispex);
|
|
|
|
}else {
|
|
|
|
ULONG err = 0;
|
2008-09-09 01:23:21 +02:00
|
|
|
|
2010-02-05 23:15:46 +01:00
|
|
|
TRACE("using IDispatch\n");
|
|
|
|
hres = IDispatch_Invoke(disp, id, &IID_NULL, ctx->lcid, DISPATCH_PROPERTYPUT, &dp, NULL, &ei->ei, &err);
|
|
|
|
}
|
2008-09-09 01:23:21 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return hres;
|
2008-09-09 01:20:26 +02:00
|
|
|
}
|
2008-09-09 01:21:55 +02:00
|
|
|
|
2012-03-12 12:14:38 +01:00
|
|
|
HRESULT jsdisp_propget_name(jsdisp_t *obj, const WCHAR *name, VARIANT *var, jsexcept_t *ei)
|
2008-09-21 15:36:26 +02:00
|
|
|
{
|
|
|
|
DISPPARAMS dp = {NULL, NULL, 0, 0};
|
|
|
|
dispex_prop_t *prop;
|
|
|
|
HRESULT hres;
|
|
|
|
|
2011-09-02 12:24:35 +02:00
|
|
|
hres = find_prop_name_prot(obj, string_hash(name), name, &prop);
|
2008-09-21 15:36:26 +02:00
|
|
|
if(FAILED(hres))
|
|
|
|
return hres;
|
|
|
|
|
|
|
|
V_VT(var) = VT_EMPTY;
|
2011-09-02 12:24:25 +02:00
|
|
|
if(!prop || prop->type==PROP_DELETED)
|
2008-09-21 15:36:26 +02:00
|
|
|
return S_OK;
|
|
|
|
|
2012-03-12 12:14:38 +01:00
|
|
|
return prop_get(obj, prop, &dp, var, ei, NULL);
|
2008-09-21 15:36:26 +02:00
|
|
|
}
|
|
|
|
|
2012-03-12 12:14:51 +01:00
|
|
|
HRESULT jsdisp_get_idx(jsdisp_t *obj, DWORD idx, VARIANT *var, jsexcept_t *ei)
|
2008-09-21 15:36:26 +02:00
|
|
|
{
|
2010-01-25 03:49:49 +01:00
|
|
|
WCHAR name[12];
|
|
|
|
DISPPARAMS dp = {NULL, NULL, 0, 0};
|
|
|
|
dispex_prop_t *prop;
|
|
|
|
HRESULT hres;
|
2008-09-21 15:36:26 +02:00
|
|
|
|
|
|
|
static const WCHAR formatW[] = {'%','d',0};
|
|
|
|
|
2010-01-25 03:49:49 +01:00
|
|
|
sprintfW(name, formatW, idx);
|
|
|
|
|
2011-09-02 12:24:35 +02:00
|
|
|
hres = find_prop_name_prot(obj, string_hash(name), name, &prop);
|
2010-01-25 03:49:49 +01:00
|
|
|
if(FAILED(hres))
|
|
|
|
return hres;
|
|
|
|
|
|
|
|
V_VT(var) = VT_EMPTY;
|
2011-09-02 12:24:25 +02:00
|
|
|
if(!prop || prop->type==PROP_DELETED)
|
2010-01-25 03:49:49 +01:00
|
|
|
return DISP_E_UNKNOWNNAME;
|
|
|
|
|
2012-03-12 12:14:51 +01:00
|
|
|
return prop_get(obj, prop, &dp, var, ei, NULL);
|
2008-09-21 15:36:26 +02:00
|
|
|
}
|
|
|
|
|
2012-03-12 12:14:10 +01:00
|
|
|
HRESULT jsdisp_propget(jsdisp_t *jsdisp, DISPID id, VARIANT *val, jsexcept_t *ei)
|
2008-10-07 19:01:39 +02:00
|
|
|
{
|
|
|
|
DISPPARAMS dp = {NULL,NULL,0,0};
|
|
|
|
dispex_prop_t *prop;
|
|
|
|
|
|
|
|
prop = get_prop(jsdisp, id);
|
|
|
|
if(!prop)
|
|
|
|
return DISP_E_MEMBERNOTFOUND;
|
|
|
|
|
|
|
|
V_VT(val) = VT_EMPTY;
|
2012-03-12 12:14:10 +01:00
|
|
|
return prop_get(jsdisp, prop, &dp, val, ei, NULL);
|
2008-10-07 19:01:39 +02:00
|
|
|
}
|
|
|
|
|
2012-03-08 14:28:48 +01:00
|
|
|
HRESULT disp_propget(script_ctx_t *ctx, IDispatch *disp, DISPID id, VARIANT *val, jsexcept_t *ei)
|
2008-09-09 01:21:55 +02:00
|
|
|
{
|
|
|
|
DISPPARAMS dp = {NULL,NULL,0,0};
|
|
|
|
IDispatchEx *dispex;
|
2010-09-06 16:11:49 +02:00
|
|
|
jsdisp_t *jsdisp;
|
2008-09-09 01:21:55 +02:00
|
|
|
HRESULT hres;
|
|
|
|
|
|
|
|
jsdisp = iface_to_jsdisp((IUnknown*)disp);
|
|
|
|
if(jsdisp) {
|
2012-03-12 12:14:10 +01:00
|
|
|
hres = jsdisp_propget(jsdisp, id, val, ei);
|
2009-09-01 13:26:08 +02:00
|
|
|
jsdisp_release(jsdisp);
|
2008-09-09 01:21:55 +02:00
|
|
|
return hres;
|
|
|
|
}
|
|
|
|
|
|
|
|
hres = IDispatch_QueryInterface(disp, &IID_IDispatchEx, (void**)&dispex);
|
|
|
|
if(FAILED(hres)) {
|
|
|
|
ULONG err = 0;
|
|
|
|
|
2008-10-07 19:00:49 +02:00
|
|
|
TRACE("using IDispatch\n");
|
2009-09-23 16:10:36 +02:00
|
|
|
return IDispatch_Invoke(disp, id, &IID_NULL, ctx->lcid, INVOKE_PROPERTYGET, &dp, val, &ei->ei, &err);
|
2008-09-09 01:21:55 +02:00
|
|
|
}
|
|
|
|
|
2012-03-08 14:28:16 +01:00
|
|
|
hres = IDispatchEx_InvokeEx(dispex, id, ctx->lcid, INVOKE_PROPERTYGET, &dp, val, &ei->ei,
|
|
|
|
&ctx->jscaller->IServiceProvider_iface);
|
2008-09-09 01:21:55 +02:00
|
|
|
IDispatchEx_Release(dispex);
|
|
|
|
|
|
|
|
return hres;
|
|
|
|
}
|
2009-07-14 02:06:59 +02:00
|
|
|
|
2010-09-06 16:11:49 +02:00
|
|
|
HRESULT jsdisp_delete_idx(jsdisp_t *obj, DWORD idx)
|
2009-07-14 02:06:59 +02:00
|
|
|
{
|
|
|
|
static const WCHAR formatW[] = {'%','d',0};
|
|
|
|
WCHAR buf[12];
|
|
|
|
dispex_prop_t *prop;
|
|
|
|
HRESULT hres;
|
|
|
|
|
|
|
|
sprintfW(buf, formatW, idx);
|
|
|
|
|
2011-09-02 12:24:35 +02:00
|
|
|
hres = find_prop_name(obj, string_hash(buf), buf, &prop);
|
2009-07-14 02:06:59 +02:00
|
|
|
if(FAILED(hres) || !prop)
|
|
|
|
return hres;
|
|
|
|
|
|
|
|
return delete_prop(prop);
|
|
|
|
}
|
2011-09-02 12:24:12 +02:00
|
|
|
|
|
|
|
VARIANT_BOOL jsdisp_is_own_prop(jsdisp_t *obj, BSTR name)
|
|
|
|
{
|
|
|
|
dispex_prop_t *prop;
|
|
|
|
HRESULT hres;
|
|
|
|
|
2011-09-02 12:24:35 +02:00
|
|
|
hres = find_prop_name(obj, string_hash(name), name, &prop);
|
2011-09-02 12:24:12 +02:00
|
|
|
if(FAILED(hres))
|
|
|
|
return VARIANT_FALSE;
|
|
|
|
else if(!prop)
|
|
|
|
return VARIANT_FALSE;
|
|
|
|
|
|
|
|
return prop->type==PROP_VARIANT ? VARIANT_TRUE : VARIANT_FALSE;
|
|
|
|
}
|