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"
|
2019-12-12 13:53:55 +01:00
|
|
|
#include "engine.h"
|
2008-09-01 01:23:38 +02:00
|
|
|
|
|
|
|
#include "wine/debug.h"
|
|
|
|
|
|
|
|
WINE_DEFAULT_DEBUG_CHANNEL(jscript);
|
|
|
|
|
2019-12-12 13:53:56 +01:00
|
|
|
static const GUID GUID_JScriptTypeInfo = {0xc59c6b12,0xf6c1,0x11cf,{0x88,0x35,0x00,0xa0,0xc9,0x11,0xe8,0xb2}};
|
|
|
|
|
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 {
|
2012-09-17 15:17:24 +02:00
|
|
|
PROP_JSVAL,
|
2008-09-08 00:14:38 +02:00
|
|
|
PROP_BUILTIN,
|
|
|
|
PROP_PROTREF,
|
2018-05-14 13:34:26 +02:00
|
|
|
PROP_ACCESSOR,
|
2012-11-30 13:01:51 +01:00
|
|
|
PROP_DELETED,
|
|
|
|
PROP_IDX
|
2008-09-08 00:14:38 +02:00
|
|
|
} 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 {
|
2012-09-17 15:17:24 +02:00
|
|
|
jsval_t val;
|
2008-09-08 00:14:38 +02:00
|
|
|
const builtin_prop_t *p;
|
|
|
|
DWORD ref;
|
2012-11-30 13:01:51 +01:00
|
|
|
unsigned idx;
|
2018-05-14 13:34:26 +02:00
|
|
|
struct {
|
|
|
|
jsdisp_t *getter;
|
|
|
|
jsdisp_t *setter;
|
|
|
|
} accessor;
|
2008-09-08 00:14:38 +02:00
|
|
|
} u;
|
2011-09-02 12:24:25 +02:00
|
|
|
|
|
|
|
int bucket_head;
|
|
|
|
int bucket_next;
|
2008-09-08 00:14:38 +02:00
|
|
|
};
|
|
|
|
|
2021-11-24 15:10:31 +01:00
|
|
|
static void fix_protref_prop(jsdisp_t *jsdisp, dispex_prop_t *prop)
|
|
|
|
{
|
|
|
|
DWORD ref;
|
|
|
|
|
|
|
|
if(prop->type != PROP_PROTREF)
|
|
|
|
return;
|
|
|
|
ref = prop->u.ref;
|
|
|
|
|
|
|
|
while((jsdisp = jsdisp->prototype)) {
|
|
|
|
if(ref >= jsdisp->prop_cnt || jsdisp->props[ref].type == PROP_DELETED)
|
|
|
|
break;
|
|
|
|
if(jsdisp->props[ref].type != PROP_PROTREF)
|
|
|
|
return;
|
|
|
|
ref = jsdisp->props[ref].u.ref;
|
|
|
|
}
|
|
|
|
prop->type = PROP_DELETED;
|
|
|
|
}
|
|
|
|
|
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
|
|
|
{
|
2021-11-25 21:01:28 +01:00
|
|
|
/* don't overlap with DISPID_VALUE */
|
|
|
|
return prop - This->props + 1;
|
2008-09-08 00:14:58 +02:00
|
|
|
}
|
|
|
|
|
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
|
|
|
{
|
2021-11-25 21:01:28 +01:00
|
|
|
DWORD idx = id - 1;
|
|
|
|
|
|
|
|
if(idx >= This->prop_cnt)
|
2008-09-09 01:20:26 +02:00
|
|
|
return NULL;
|
2021-11-25 21:01:28 +01:00
|
|
|
fix_protref_prop(This, &This->props[idx]);
|
2008-09-09 01:20:26 +02:00
|
|
|
|
2021-11-25 21:01:28 +01:00
|
|
|
return This->props[idx].type == PROP_DELETED ? NULL : &This->props[idx];
|
2008-09-09 01:20:26 +02:00
|
|
|
}
|
|
|
|
|
2019-12-12 13:53:55 +01:00
|
|
|
static inline BOOL is_function_prop(dispex_prop_t *prop)
|
|
|
|
{
|
|
|
|
BOOL ret = FALSE;
|
|
|
|
|
|
|
|
if (is_object_instance(prop->u.val))
|
|
|
|
{
|
|
|
|
jsdisp_t *jsdisp = iface_to_jsdisp(get_object(prop->u.val));
|
|
|
|
|
|
|
|
if (jsdisp) ret = is_class(jsdisp, JSCLASS_FUNCTION);
|
|
|
|
jsdisp_release(jsdisp);
|
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
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) {
|
2021-11-24 15:10:36 +01:00
|
|
|
dispex_prop_t *parent = NULL;
|
|
|
|
|
|
|
|
if(prop->u.ref < This->prototype->prop_cnt)
|
|
|
|
parent = &This->prototype->props[prop->u.ref];
|
|
|
|
|
|
|
|
if(!parent || parent->type == PROP_DELETED) {
|
2008-09-09 01:20:52 +02:00
|
|
|
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;
|
|
|
|
|
2019-06-13 14:47:56 +02:00
|
|
|
r = wcscmp(name, This->builtin_info->props[i].name);
|
2018-03-01 19:18:26 +01:00
|
|
|
if(!r) {
|
|
|
|
/* Skip prop if it's available only in higher compatibility mode. */
|
|
|
|
unsigned version = (This->builtin_info->props[i].flags & PROPF_VERSION_MASK)
|
|
|
|
>> PROPF_VERSION_SHIFT;
|
|
|
|
if(version && version > This->ctx->version)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
/* Skip prop if it's available only in HTML mode and we're not running in HTML mode. */
|
|
|
|
if((This->builtin_info->props[i].flags & PROPF_HTML) && !This->ctx->html_mode)
|
|
|
|
return NULL;
|
|
|
|
|
2008-09-08 00:14:58 +02:00
|
|
|
return This->builtin_info->props + i;
|
2018-03-01 19:18:26 +01:00
|
|
|
}
|
2008-09-08 00:14:58 +02:00
|
|
|
|
|
|
|
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++)
|
2019-06-06 09:17:49 +02:00
|
|
|
h = (h>>(sizeof(unsigned)*8-4)) ^ (h<<4) ^ towlower(*name);
|
2011-09-02 12:24:25 +02:00
|
|
|
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++) {
|
2021-11-24 15:10:35 +01:00
|
|
|
This->props[i].bucket_head = ~0;
|
|
|
|
This->props[i].bucket_next = ~0;
|
2008-09-08 00:14:58 +02:00
|
|
|
}
|
|
|
|
|
2021-11-25 21:01:28 +01:00
|
|
|
for(i=0; i<This->prop_cnt; i++) {
|
2011-09-02 12:24:25 +02:00
|
|
|
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;
|
2021-11-24 15:10:35 +01: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;
|
2021-11-24 15:10:35 +01:00
|
|
|
while(pos != ~0) {
|
2019-06-13 14:47:56 +02:00
|
|
|
if(!wcscmp(name, This->props[pos].name)) {
|
2021-11-24 15:10:35 +01:00
|
|
|
if(prev != ~0) {
|
2011-09-02 12:24:25 +02:00
|
|
|
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) {
|
2018-05-03 14:58:44 +02:00
|
|
|
unsigned flags = builtin->flags;
|
|
|
|
if(flags & PROPF_METHOD)
|
2018-05-03 14:58:55 +02:00
|
|
|
flags |= PROPF_WRITABLE | PROPF_CONFIGURABLE;
|
|
|
|
else if(builtin->setter)
|
|
|
|
flags |= PROPF_WRITABLE;
|
2018-05-03 14:59:02 +02:00
|
|
|
flags &= PROPF_ENUMERABLE | PROPF_WRITABLE | PROPF_CONFIGURABLE;
|
2018-05-03 14:58:44 +02:00
|
|
|
prop = alloc_prop(This, name, PROP_BUILTIN, flags);
|
2008-09-08 00:14:58 +02:00
|
|
|
if(!prop)
|
|
|
|
return E_OUTOFMEMORY;
|
|
|
|
|
|
|
|
prop->u.p = builtin;
|
|
|
|
*ret = prop;
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
2012-11-30 13:01:51 +01:00
|
|
|
if(This->builtin_info->idx_length) {
|
|
|
|
const WCHAR *ptr;
|
|
|
|
unsigned idx = 0;
|
|
|
|
|
2019-11-08 21:26:08 +01:00
|
|
|
for(ptr = name; is_digit(*ptr) && idx < 0x10000; ptr++)
|
2012-11-30 13:01:51 +01:00
|
|
|
idx = idx*10 + (*ptr-'0');
|
|
|
|
if(!*ptr && idx < This->builtin_info->idx_length(This)) {
|
2018-05-03 14:58:55 +02:00
|
|
|
prop = alloc_prop(This, name, PROP_IDX, This->builtin_info->idx_put ? PROPF_WRITABLE : 0);
|
2012-11-30 13:01:51 +01:00
|
|
|
if(!prop)
|
|
|
|
return E_OUTOFMEMORY;
|
|
|
|
|
|
|
|
prop->u.idx = idx;
|
|
|
|
*ret = prop;
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-09-08 00:14:58 +02:00
|
|
|
*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) {
|
2021-11-24 15:10:31 +01:00
|
|
|
fix_protref_prop(This, 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;
|
2021-11-24 15:10:31 +01:00
|
|
|
if(prop && prop->type != PROP_DELETED) {
|
2011-09-02 12:24:25 +02:00
|
|
|
if(del) {
|
|
|
|
del->type = PROP_PROTREF;
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2018-05-15 13:26:52 +02:00
|
|
|
static HRESULT ensure_prop_name(jsdisp_t *This, const WCHAR *name, DWORD create_flags, dispex_prop_t **ret)
|
2010-02-05 23:15:07 +01:00
|
|
|
{
|
|
|
|
dispex_prop_t *prop;
|
|
|
|
HRESULT hres;
|
|
|
|
|
2018-05-15 13:26:52 +02:00
|
|
|
hres = find_prop_name_prot(This, string_hash(name), name, &prop);
|
2012-09-17 15:21:16 +02:00
|
|
|
if(SUCCEEDED(hres) && (!prop || prop->type == PROP_DELETED)) {
|
2022-02-11 08:41:11 +01:00
|
|
|
TRACE("creating prop %s flags %lx\n", debugstr_w(name), create_flags);
|
2008-09-08 00:14:58 +02:00
|
|
|
|
2011-09-02 12:24:25 +02:00
|
|
|
if(prop) {
|
2012-09-17 15:17:24 +02:00
|
|
|
prop->type = PROP_JSVAL;
|
2011-09-02 12:24:25 +02:00
|
|
|
prop->flags = create_flags;
|
2012-09-17 15:21:16 +02:00
|
|
|
prop->u.val = jsval_undefined();
|
2011-09-02 12:24:25 +02:00
|
|
|
}else {
|
2012-09-17 15:17:24 +02:00
|
|
|
prop = alloc_prop(This, name, PROP_JSVAL, create_flags);
|
2011-09-02 12:24:25 +02:00
|
|
|
if(!prop)
|
|
|
|
return E_OUTOFMEMORY;
|
|
|
|
}
|
|
|
|
|
2012-09-17 15:17:24 +02:00
|
|
|
prop->u.val = jsval_undefined();
|
2008-09-08 00:14:58 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
*ret = prop;
|
2010-02-05 23:15:07 +01:00
|
|
|
return hres;
|
2008-09-08 00:14:58 +02:00
|
|
|
}
|
|
|
|
|
2012-06-21 10:48:10 +02:00
|
|
|
static IDispatch *get_this(DISPPARAMS *dp)
|
|
|
|
{
|
|
|
|
DWORD i;
|
|
|
|
|
|
|
|
for(i=0; i < dp->cNamedArgs; i++) {
|
|
|
|
if(dp->rgdispidNamedArgs[i] == DISPID_THIS) {
|
|
|
|
if(V_VT(dp->rgvarg+i) == VT_DISPATCH)
|
|
|
|
return V_DISPATCH(dp->rgvarg+i);
|
|
|
|
|
|
|
|
WARN("This is not VT_DISPATCH\n");
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
TRACE("no this passed\n");
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2012-09-17 15:16:42 +02:00
|
|
|
static HRESULT convert_params(const DISPPARAMS *dp, jsval_t *buf, unsigned *argc, jsval_t **ret)
|
2012-05-01 15:05:07 +02:00
|
|
|
{
|
2012-09-17 15:16:42 +02:00
|
|
|
jsval_t *argv;
|
2012-06-25 14:08:38 +02:00
|
|
|
unsigned cnt;
|
2012-05-01 15:05:07 +02:00
|
|
|
unsigned i;
|
2012-09-17 15:16:42 +02:00
|
|
|
HRESULT hres;
|
2012-05-01 15:05:07 +02:00
|
|
|
|
2012-06-25 14:08:38 +02:00
|
|
|
cnt = dp->cArgs - dp->cNamedArgs;
|
2012-05-01 15:05:07 +02:00
|
|
|
|
2012-06-25 14:08:38 +02:00
|
|
|
if(cnt > 6) {
|
2012-09-17 15:16:42 +02:00
|
|
|
argv = heap_alloc(cnt * sizeof(*argv));
|
2012-06-25 14:08:38 +02:00
|
|
|
if(!argv)
|
2012-05-01 15:05:07 +02:00
|
|
|
return E_OUTOFMEMORY;
|
|
|
|
}else {
|
2012-06-25 14:08:38 +02:00
|
|
|
argv = buf;
|
2012-05-01 15:05:07 +02:00
|
|
|
}
|
|
|
|
|
2012-06-25 14:08:38 +02:00
|
|
|
for(i = 0; i < cnt; i++) {
|
2012-09-17 15:16:42 +02:00
|
|
|
hres = variant_to_jsval(dp->rgvarg+dp->cArgs-i-1, argv+i);
|
|
|
|
if(FAILED(hres)) {
|
|
|
|
while(i--)
|
|
|
|
jsval_release(argv[i]);
|
|
|
|
if(argv != buf)
|
|
|
|
heap_free(argv);
|
|
|
|
return hres;
|
2012-05-01 15:05:07 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-06-25 14:08:38 +02:00
|
|
|
*argc = cnt;
|
|
|
|
*ret = argv;
|
2012-05-01 15:05:07 +02:00
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
2018-04-20 18:33:09 +02:00
|
|
|
static HRESULT prop_get(jsdisp_t *This, dispex_prop_t *prop, jsval_t *r)
|
2008-09-09 01:20:26 +02:00
|
|
|
{
|
2018-05-15 13:26:25 +02:00
|
|
|
jsdisp_t *prop_obj = This;
|
2008-09-09 01:20:26 +02:00
|
|
|
HRESULT hres;
|
|
|
|
|
2018-05-15 13:26:25 +02:00
|
|
|
while(prop->type == PROP_PROTREF) {
|
|
|
|
prop_obj = prop_obj->prototype;
|
|
|
|
prop = prop_obj->props + prop->u.ref;
|
|
|
|
}
|
|
|
|
|
2008-09-09 01:20:26 +02:00
|
|
|
switch(prop->type) {
|
|
|
|
case PROP_BUILTIN:
|
2015-02-05 14:49:01 +01:00
|
|
|
if(prop->u.p->getter) {
|
2015-02-06 12:09:40 +01:00
|
|
|
hres = prop->u.p->getter(This->ctx, This, r);
|
2015-02-05 14:49:01 +01:00
|
|
|
}else {
|
2010-09-06 16:11:49 +02:00
|
|
|
jsdisp_t *obj;
|
2015-02-05 14:49:01 +01:00
|
|
|
|
|
|
|
assert(prop->u.p->invoke != NULL);
|
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;
|
|
|
|
|
2012-09-17 15:17:24 +02:00
|
|
|
prop->type = PROP_JSVAL;
|
|
|
|
prop->u.val = jsval_obj(obj);
|
|
|
|
|
|
|
|
jsdisp_addref(obj);
|
|
|
|
*r = jsval_obj(obj);
|
2008-09-09 01:20:26 +02:00
|
|
|
}
|
|
|
|
break;
|
2012-09-17 15:17:24 +02:00
|
|
|
case PROP_JSVAL:
|
|
|
|
hres = jsval_copy(prop->u.val, r);
|
2008-09-09 01:20:26 +02:00
|
|
|
break;
|
2018-05-14 13:34:26 +02:00
|
|
|
case PROP_ACCESSOR:
|
2018-05-15 13:26:25 +02:00
|
|
|
if(prop->u.accessor.getter) {
|
|
|
|
hres = jsdisp_call_value(prop->u.accessor.getter, to_disp(This),
|
|
|
|
DISPATCH_METHOD, 0, NULL, r);
|
|
|
|
}else {
|
|
|
|
*r = jsval_undefined();
|
|
|
|
hres = S_OK;
|
|
|
|
}
|
2018-05-14 13:34:26 +02:00
|
|
|
break;
|
2012-11-30 13:01:51 +01:00
|
|
|
case PROP_IDX:
|
2018-05-15 13:26:25 +02:00
|
|
|
hres = prop_obj->builtin_info->idx_get(prop_obj, prop->u.idx, r);
|
2012-11-30 13:01:51 +01:00
|
|
|
break;
|
2008-09-09 01:20:26 +02:00
|
|
|
default:
|
|
|
|
ERR("type %d\n", prop->type);
|
|
|
|
return E_FAIL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(FAILED(hres)) {
|
2022-02-11 08:41:11 +01:00
|
|
|
TRACE("fail %08lx\n", hres);
|
2008-09-09 01:20:26 +02:00
|
|
|
return hres;
|
|
|
|
}
|
|
|
|
|
2021-03-10 15:00:04 +01:00
|
|
|
TRACE("%p.%s ret %s\n", This, debugstr_w(prop->name), debugstr_jsval(*r));
|
2008-09-09 01:20:26 +02:00
|
|
|
return hres;
|
|
|
|
}
|
|
|
|
|
2018-04-20 18:33:16 +02:00
|
|
|
static HRESULT prop_put(jsdisp_t *This, dispex_prop_t *prop, jsval_t val)
|
2008-09-09 01:20:26 +02:00
|
|
|
{
|
|
|
|
HRESULT hres;
|
|
|
|
|
2018-05-15 13:26:52 +02:00
|
|
|
if(prop->type == PROP_PROTREF) {
|
|
|
|
dispex_prop_t *prop_iter = prop;
|
|
|
|
jsdisp_t *prototype_iter = This;
|
|
|
|
|
|
|
|
do {
|
|
|
|
prototype_iter = prototype_iter->prototype;
|
|
|
|
prop_iter = prototype_iter->props + prop_iter->u.ref;
|
|
|
|
} while(prop_iter->type == PROP_PROTREF);
|
|
|
|
|
2021-11-02 19:07:11 +01:00
|
|
|
if(prop_iter->type == PROP_ACCESSOR ||
|
|
|
|
(prop_iter->type == PROP_BUILTIN && prop_iter->u.p->setter))
|
2018-05-15 13:26:52 +02:00
|
|
|
prop = prop_iter;
|
|
|
|
}
|
2010-05-26 19:17:21 +02:00
|
|
|
|
2008-09-09 01:20:26 +02:00
|
|
|
switch(prop->type) {
|
|
|
|
case PROP_BUILTIN:
|
2018-05-15 13:26:38 +02:00
|
|
|
if(!prop->u.p->setter) {
|
|
|
|
TRACE("getter with no setter\n");
|
|
|
|
return S_OK;
|
2015-02-05 14:49:01 +01:00
|
|
|
}
|
2018-05-15 13:26:38 +02:00
|
|
|
return prop->u.p->setter(This->ctx, This, val);
|
2008-09-09 01:20:26 +02:00
|
|
|
case PROP_PROTREF:
|
2018-05-15 13:26:38 +02:00
|
|
|
case PROP_DELETED:
|
2021-04-01 18:18:40 +02:00
|
|
|
if(!This->extensible)
|
|
|
|
return S_OK;
|
2012-09-17 15:17:24 +02:00
|
|
|
prop->type = PROP_JSVAL;
|
2018-05-03 14:59:02 +02:00
|
|
|
prop->flags = PROPF_ENUMERABLE | PROPF_CONFIGURABLE | PROPF_WRITABLE;
|
2012-09-17 15:17:24 +02:00
|
|
|
prop->u.val = jsval_undefined();
|
2008-09-09 01:20:26 +02:00
|
|
|
break;
|
2012-09-17 15:17:24 +02:00
|
|
|
case PROP_JSVAL:
|
2018-05-15 13:26:38 +02:00
|
|
|
if(!(prop->flags & PROPF_WRITABLE))
|
|
|
|
return S_OK;
|
|
|
|
|
2012-09-17 15:17:24 +02:00
|
|
|
jsval_release(prop->u.val);
|
2008-09-09 01:20:26 +02:00
|
|
|
break;
|
2018-05-15 13:26:38 +02:00
|
|
|
case PROP_ACCESSOR:
|
2018-05-15 13:26:52 +02:00
|
|
|
if(!prop->u.accessor.setter) {
|
|
|
|
TRACE("no setter\n");
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
return jsdisp_call_value(prop->u.accessor.setter, to_disp(This), DISPATCH_METHOD, 1, &val, NULL);
|
2012-11-30 13:01:51 +01:00
|
|
|
case PROP_IDX:
|
2018-05-15 13:26:38 +02:00
|
|
|
if(!This->builtin_info->idx_put) {
|
|
|
|
TRACE("no put_idx\n");
|
|
|
|
return S_OK;
|
|
|
|
}
|
2012-11-30 13:01:51 +01:00
|
|
|
return This->builtin_info->idx_put(This, prop->u.idx, val);
|
2008-09-09 01:20:26 +02:00
|
|
|
default:
|
|
|
|
ERR("type %d\n", prop->type);
|
|
|
|
return E_FAIL;
|
|
|
|
}
|
|
|
|
|
2021-03-10 15:00:04 +01:00
|
|
|
TRACE("%p.%s = %s\n", This, debugstr_w(prop->name), debugstr_jsval(val));
|
2012-10-11 12:16:01 +02:00
|
|
|
|
2012-09-17 15:17:24 +02:00
|
|
|
hres = jsval_copy(val, &prop->u.val);
|
2016-07-28 18:45:13 +02:00
|
|
|
if(FAILED(hres))
|
2008-09-09 01:20:26 +02:00
|
|
|
return hres;
|
|
|
|
|
|
|
|
if(This->builtin_info->on_put)
|
|
|
|
This->builtin_info->on_put(This, prop->name);
|
|
|
|
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
2021-03-31 20:05:26 +02:00
|
|
|
static HRESULT invoke_prop_func(jsdisp_t *This, IDispatch *jsthis, dispex_prop_t *prop, WORD flags,
|
|
|
|
unsigned argc, jsval_t *argv, jsval_t *r, IServiceProvider *caller)
|
|
|
|
{
|
|
|
|
HRESULT hres;
|
|
|
|
|
|
|
|
switch(prop->type) {
|
|
|
|
case PROP_BUILTIN: {
|
2021-11-25 21:01:28 +01:00
|
|
|
vdisp_t vthis;
|
|
|
|
|
2021-03-31 20:05:26 +02:00
|
|
|
if(flags == DISPATCH_CONSTRUCT && (prop->flags & PROPF_METHOD)) {
|
|
|
|
WARN("%s is not a constructor\n", debugstr_w(prop->name));
|
|
|
|
return E_INVALIDARG;
|
|
|
|
}
|
|
|
|
|
2021-11-25 21:01:28 +01:00
|
|
|
if(This->builtin_info->class != JSCLASS_FUNCTION && prop->u.p->invoke != JSGlobal_eval)
|
|
|
|
flags &= ~DISPATCH_JSCRIPT_INTERNAL_MASK;
|
|
|
|
if(jsthis)
|
|
|
|
set_disp(&vthis, jsthis);
|
|
|
|
else
|
|
|
|
set_jsdisp(&vthis, This);
|
|
|
|
hres = prop->u.p->invoke(This->ctx, &vthis, flags, argc, argv, r);
|
|
|
|
vdisp_release(&vthis);
|
2021-03-31 20:05:26 +02:00
|
|
|
|
|
|
|
return hres;
|
|
|
|
}
|
|
|
|
case PROP_PROTREF:
|
|
|
|
return invoke_prop_func(This->prototype, jsthis ? jsthis : (IDispatch *)&This->IDispatchEx_iface,
|
|
|
|
This->prototype->props+prop->u.ref, flags, argc, argv, r, caller);
|
|
|
|
case PROP_JSVAL: {
|
|
|
|
if(!is_object_instance(prop->u.val) || !get_object(prop->u.val)) {
|
|
|
|
FIXME("invoke %s\n", debugstr_jsval(prop->u.val));
|
|
|
|
return E_FAIL;
|
|
|
|
}
|
|
|
|
|
|
|
|
TRACE("call %s %p\n", debugstr_w(prop->name), get_object(prop->u.val));
|
|
|
|
|
|
|
|
return disp_call_value(This->ctx, get_object(prop->u.val),
|
|
|
|
jsthis ? jsthis : (IDispatch*)&This->IDispatchEx_iface,
|
|
|
|
flags, argc, argv, r);
|
|
|
|
}
|
|
|
|
case PROP_ACCESSOR:
|
|
|
|
case PROP_IDX: {
|
|
|
|
jsval_t val;
|
|
|
|
|
|
|
|
hres = prop_get(This, prop, &val);
|
|
|
|
if(FAILED(hres))
|
|
|
|
return hres;
|
|
|
|
|
|
|
|
if(is_object_instance(val) && get_object(val)) {
|
|
|
|
hres = disp_call_value(This->ctx, get_object(val),
|
|
|
|
jsthis ? jsthis : (IDispatch*)&This->IDispatchEx_iface,
|
|
|
|
flags, argc, argv, r);
|
|
|
|
}else {
|
|
|
|
FIXME("invoke %s\n", debugstr_jsval(val));
|
|
|
|
hres = E_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
|
|
|
jsval_release(val);
|
|
|
|
return hres;
|
|
|
|
}
|
|
|
|
case PROP_DELETED:
|
|
|
|
assert(0);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return E_FAIL;
|
|
|
|
}
|
|
|
|
|
2015-02-06 12:09:47 +01:00
|
|
|
HRESULT builtin_set_const(script_ctx_t *ctx, jsdisp_t *jsthis, jsval_t value)
|
2015-02-05 14:49:01 +01:00
|
|
|
{
|
|
|
|
TRACE("%p %s\n", jsthis, debugstr_jsval(value));
|
|
|
|
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++) {
|
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;
|
|
|
|
}
|
|
|
|
|
2019-12-12 13:53:55 +01:00
|
|
|
struct typeinfo_func {
|
|
|
|
dispex_prop_t *prop;
|
|
|
|
function_code_t *code;
|
|
|
|
};
|
|
|
|
|
2019-12-09 18:12:41 +01:00
|
|
|
typedef struct {
|
|
|
|
ITypeInfo ITypeInfo_iface;
|
2019-12-12 13:54:00 +01:00
|
|
|
ITypeComp ITypeComp_iface;
|
2019-12-09 18:12:41 +01:00
|
|
|
LONG ref;
|
2019-12-12 13:53:55 +01:00
|
|
|
|
|
|
|
UINT num_funcs;
|
|
|
|
UINT num_vars;
|
|
|
|
struct typeinfo_func *funcs;
|
|
|
|
dispex_prop_t **vars;
|
|
|
|
|
|
|
|
jsdisp_t *jsdisp;
|
2019-12-09 18:12:41 +01:00
|
|
|
} ScriptTypeInfo;
|
|
|
|
|
2019-12-13 13:59:45 +01:00
|
|
|
static struct typeinfo_func *get_func_from_memid(const ScriptTypeInfo *typeinfo, MEMBERID memid)
|
|
|
|
{
|
|
|
|
UINT a = 0, b = typeinfo->num_funcs;
|
|
|
|
|
|
|
|
while (a < b)
|
|
|
|
{
|
|
|
|
UINT i = (a + b - 1) / 2;
|
|
|
|
MEMBERID func_memid = prop_to_id(typeinfo->jsdisp, typeinfo->funcs[i].prop);
|
|
|
|
|
|
|
|
if (memid == func_memid)
|
|
|
|
return &typeinfo->funcs[i];
|
|
|
|
else if (memid < func_memid)
|
|
|
|
b = i;
|
|
|
|
else
|
|
|
|
a = i + 1;
|
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static dispex_prop_t *get_var_from_memid(const ScriptTypeInfo *typeinfo, MEMBERID memid)
|
|
|
|
{
|
|
|
|
UINT a = 0, b = typeinfo->num_vars;
|
|
|
|
|
|
|
|
while (a < b)
|
|
|
|
{
|
|
|
|
UINT i = (a + b - 1) / 2;
|
|
|
|
MEMBERID var_memid = prop_to_id(typeinfo->jsdisp, typeinfo->vars[i]);
|
|
|
|
|
|
|
|
if (memid == var_memid)
|
|
|
|
return typeinfo->vars[i];
|
|
|
|
else if (memid < var_memid)
|
|
|
|
b = i;
|
|
|
|
else
|
|
|
|
a = i + 1;
|
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2019-12-09 18:12:41 +01:00
|
|
|
static inline ScriptTypeInfo *ScriptTypeInfo_from_ITypeInfo(ITypeInfo *iface)
|
|
|
|
{
|
|
|
|
return CONTAINING_RECORD(iface, ScriptTypeInfo, ITypeInfo_iface);
|
|
|
|
}
|
|
|
|
|
2019-12-12 13:54:00 +01:00
|
|
|
static inline ScriptTypeInfo *ScriptTypeInfo_from_ITypeComp(ITypeComp *iface)
|
|
|
|
{
|
|
|
|
return CONTAINING_RECORD(iface, ScriptTypeInfo, ITypeComp_iface);
|
|
|
|
}
|
|
|
|
|
2019-12-09 18:12:41 +01:00
|
|
|
static HRESULT WINAPI ScriptTypeInfo_QueryInterface(ITypeInfo *iface, REFIID riid, void **ppv)
|
|
|
|
{
|
|
|
|
ScriptTypeInfo *This = ScriptTypeInfo_from_ITypeInfo(iface);
|
|
|
|
|
|
|
|
if (IsEqualGUID(&IID_IUnknown, riid) || IsEqualGUID(&IID_ITypeInfo, riid))
|
|
|
|
*ppv = &This->ITypeInfo_iface;
|
2019-12-12 13:54:00 +01:00
|
|
|
else if (IsEqualGUID(&IID_ITypeComp, riid))
|
|
|
|
*ppv = &This->ITypeComp_iface;
|
2019-12-09 18:12:41 +01:00
|
|
|
else
|
|
|
|
{
|
|
|
|
WARN("(%p)->(%s %p)\n", This, debugstr_guid(riid), ppv);
|
|
|
|
*ppv = NULL;
|
|
|
|
return E_NOINTERFACE;
|
|
|
|
}
|
|
|
|
|
|
|
|
TRACE("(%p)->(%s %p)\n", This, debugstr_guid(riid), ppv);
|
|
|
|
IUnknown_AddRef((IUnknown*)*ppv);
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
static ULONG WINAPI ScriptTypeInfo_AddRef(ITypeInfo *iface)
|
|
|
|
{
|
|
|
|
ScriptTypeInfo *This = ScriptTypeInfo_from_ITypeInfo(iface);
|
|
|
|
LONG ref = InterlockedIncrement(&This->ref);
|
|
|
|
|
2022-02-11 08:41:11 +01:00
|
|
|
TRACE("(%p) ref=%ld\n", This, ref);
|
2019-12-09 18:12:41 +01:00
|
|
|
|
|
|
|
return ref;
|
|
|
|
}
|
|
|
|
|
|
|
|
static ULONG WINAPI ScriptTypeInfo_Release(ITypeInfo *iface)
|
|
|
|
{
|
|
|
|
ScriptTypeInfo *This = ScriptTypeInfo_from_ITypeInfo(iface);
|
|
|
|
LONG ref = InterlockedDecrement(&This->ref);
|
2019-12-12 13:53:55 +01:00
|
|
|
UINT i;
|
2019-12-09 18:12:41 +01:00
|
|
|
|
2022-02-11 08:41:11 +01:00
|
|
|
TRACE("(%p) ref=%ld\n", This, ref);
|
2019-12-09 18:12:41 +01:00
|
|
|
|
|
|
|
if (!ref)
|
|
|
|
{
|
2019-12-12 13:53:55 +01:00
|
|
|
for (i = This->num_funcs; i--;)
|
|
|
|
release_bytecode(This->funcs[i].code->bytecode);
|
|
|
|
IDispatchEx_Release(&This->jsdisp->IDispatchEx_iface);
|
|
|
|
heap_free(This->funcs);
|
|
|
|
heap_free(This->vars);
|
2019-12-09 18:12:41 +01:00
|
|
|
heap_free(This);
|
|
|
|
}
|
|
|
|
return ref;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI ScriptTypeInfo_GetTypeAttr(ITypeInfo *iface, TYPEATTR **ppTypeAttr)
|
|
|
|
{
|
|
|
|
ScriptTypeInfo *This = ScriptTypeInfo_from_ITypeInfo(iface);
|
2019-12-12 13:53:56 +01:00
|
|
|
TYPEATTR *attr;
|
|
|
|
|
|
|
|
TRACE("(%p)->(%p)\n", This, ppTypeAttr);
|
|
|
|
|
|
|
|
if (!ppTypeAttr) return E_INVALIDARG;
|
|
|
|
|
|
|
|
attr = heap_alloc_zero(sizeof(*attr));
|
|
|
|
if (!attr) return E_OUTOFMEMORY;
|
|
|
|
|
|
|
|
attr->guid = GUID_JScriptTypeInfo;
|
|
|
|
attr->lcid = LOCALE_USER_DEFAULT;
|
|
|
|
attr->memidConstructor = MEMBERID_NIL;
|
|
|
|
attr->memidDestructor = MEMBERID_NIL;
|
|
|
|
attr->cbSizeInstance = 4;
|
|
|
|
attr->typekind = TKIND_DISPATCH;
|
|
|
|
attr->cFuncs = This->num_funcs;
|
|
|
|
attr->cVars = This->num_vars;
|
|
|
|
attr->cImplTypes = 1;
|
|
|
|
attr->cbSizeVft = sizeof(IDispatchVtbl);
|
|
|
|
attr->cbAlignment = 4;
|
|
|
|
attr->wTypeFlags = TYPEFLAG_FDISPATCHABLE;
|
|
|
|
attr->wMajorVerNum = JSCRIPT_MAJOR_VERSION;
|
|
|
|
attr->wMinorVerNum = JSCRIPT_MINOR_VERSION;
|
|
|
|
|
|
|
|
*ppTypeAttr = attr;
|
|
|
|
return S_OK;
|
2019-12-09 18:12:41 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI ScriptTypeInfo_GetTypeComp(ITypeInfo *iface, ITypeComp **ppTComp)
|
|
|
|
{
|
|
|
|
ScriptTypeInfo *This = ScriptTypeInfo_from_ITypeInfo(iface);
|
|
|
|
|
2019-12-12 13:54:00 +01:00
|
|
|
TRACE("(%p)->(%p)\n", This, ppTComp);
|
2019-12-09 18:12:41 +01:00
|
|
|
|
2019-12-12 13:54:00 +01:00
|
|
|
if (!ppTComp) return E_INVALIDARG;
|
|
|
|
|
|
|
|
*ppTComp = &This->ITypeComp_iface;
|
|
|
|
ITypeInfo_AddRef(iface);
|
|
|
|
return S_OK;
|
2019-12-09 18:12:41 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI ScriptTypeInfo_GetFuncDesc(ITypeInfo *iface, UINT index, FUNCDESC **ppFuncDesc)
|
|
|
|
{
|
|
|
|
ScriptTypeInfo *This = ScriptTypeInfo_from_ITypeInfo(iface);
|
2019-12-12 13:53:57 +01:00
|
|
|
struct typeinfo_func *func;
|
|
|
|
FUNCDESC *desc;
|
|
|
|
unsigned i;
|
2019-12-09 18:12:41 +01:00
|
|
|
|
2019-12-12 13:53:57 +01:00
|
|
|
TRACE("(%p)->(%u %p)\n", This, index, ppFuncDesc);
|
2019-12-09 18:12:41 +01:00
|
|
|
|
2019-12-12 13:53:57 +01:00
|
|
|
if (!ppFuncDesc) return E_INVALIDARG;
|
|
|
|
if (index >= This->num_funcs) return TYPE_E_ELEMENTNOTFOUND;
|
|
|
|
func = &This->funcs[index];
|
|
|
|
|
|
|
|
/* Store the parameter array after the FUNCDESC structure */
|
|
|
|
desc = heap_alloc_zero(sizeof(*desc) + sizeof(ELEMDESC) * func->code->param_cnt);
|
|
|
|
if (!desc) return E_OUTOFMEMORY;
|
|
|
|
|
|
|
|
desc->memid = prop_to_id(This->jsdisp, func->prop);
|
|
|
|
desc->funckind = FUNC_DISPATCH;
|
|
|
|
desc->invkind = INVOKE_FUNC;
|
|
|
|
desc->callconv = CC_STDCALL;
|
|
|
|
desc->cParams = func->code->param_cnt;
|
|
|
|
desc->elemdescFunc.tdesc.vt = VT_VARIANT;
|
|
|
|
|
|
|
|
if (func->code->param_cnt) desc->lprgelemdescParam = (ELEMDESC*)(desc + 1);
|
|
|
|
for (i = 0; i < func->code->param_cnt; i++)
|
|
|
|
desc->lprgelemdescParam[i].tdesc.vt = VT_VARIANT;
|
|
|
|
|
|
|
|
*ppFuncDesc = desc;
|
|
|
|
return S_OK;
|
2019-12-09 18:12:41 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI ScriptTypeInfo_GetVarDesc(ITypeInfo *iface, UINT index, VARDESC **ppVarDesc)
|
|
|
|
{
|
|
|
|
ScriptTypeInfo *This = ScriptTypeInfo_from_ITypeInfo(iface);
|
2019-12-12 13:53:58 +01:00
|
|
|
VARDESC *desc;
|
2019-12-09 18:12:41 +01:00
|
|
|
|
2019-12-12 13:53:58 +01:00
|
|
|
TRACE("(%p)->(%u %p)\n", This, index, ppVarDesc);
|
2019-12-09 18:12:41 +01:00
|
|
|
|
2019-12-12 13:53:58 +01:00
|
|
|
if (!ppVarDesc) return E_INVALIDARG;
|
|
|
|
if (index >= This->num_vars) return TYPE_E_ELEMENTNOTFOUND;
|
|
|
|
|
|
|
|
desc = heap_alloc_zero(sizeof(*desc));
|
|
|
|
if (!desc) return E_OUTOFMEMORY;
|
|
|
|
|
|
|
|
desc->memid = prop_to_id(This->jsdisp, This->vars[index]);
|
|
|
|
desc->varkind = VAR_DISPATCH;
|
|
|
|
desc->elemdescVar.tdesc.vt = VT_VARIANT;
|
|
|
|
|
|
|
|
*ppVarDesc = desc;
|
|
|
|
return S_OK;
|
2019-12-09 18:12:41 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI ScriptTypeInfo_GetNames(ITypeInfo *iface, MEMBERID memid, BSTR *rgBstrNames,
|
|
|
|
UINT cMaxNames, UINT *pcNames)
|
|
|
|
{
|
|
|
|
ScriptTypeInfo *This = ScriptTypeInfo_from_ITypeInfo(iface);
|
2019-12-13 13:59:45 +01:00
|
|
|
struct typeinfo_func *func;
|
|
|
|
ITypeInfo *disp_typeinfo;
|
|
|
|
dispex_prop_t *var;
|
|
|
|
HRESULT hr;
|
|
|
|
UINT i = 0;
|
2019-12-09 18:12:41 +01:00
|
|
|
|
2022-02-11 08:41:11 +01:00
|
|
|
TRACE("(%p)->(%ld %p %u %p)\n", This, memid, rgBstrNames, cMaxNames, pcNames);
|
2019-12-09 18:12:41 +01:00
|
|
|
|
2019-12-13 13:59:45 +01:00
|
|
|
if (!rgBstrNames || !pcNames) return E_INVALIDARG;
|
|
|
|
if (memid <= 0) return TYPE_E_ELEMENTNOTFOUND;
|
|
|
|
|
|
|
|
func = get_func_from_memid(This, memid);
|
|
|
|
if (!func)
|
|
|
|
{
|
|
|
|
var = get_var_from_memid(This, memid);
|
|
|
|
if (!var)
|
|
|
|
{
|
|
|
|
hr = get_dispatch_typeinfo(&disp_typeinfo);
|
|
|
|
if (FAILED(hr)) return hr;
|
|
|
|
|
|
|
|
return ITypeInfo_GetNames(disp_typeinfo, memid, rgBstrNames, cMaxNames, pcNames);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
*pcNames = 0;
|
|
|
|
if (!cMaxNames) return S_OK;
|
|
|
|
|
|
|
|
rgBstrNames[0] = SysAllocString(func ? func->prop->name : var->name);
|
|
|
|
if (!rgBstrNames[0]) return E_OUTOFMEMORY;
|
|
|
|
i++;
|
|
|
|
|
|
|
|
if (func)
|
|
|
|
{
|
|
|
|
unsigned num = min(cMaxNames, func->code->param_cnt + 1);
|
|
|
|
|
|
|
|
for (; i < num; i++)
|
|
|
|
{
|
|
|
|
if (!(rgBstrNames[i] = SysAllocString(func->code->params[i - 1])))
|
|
|
|
{
|
|
|
|
do SysFreeString(rgBstrNames[--i]); while (i);
|
|
|
|
return E_OUTOFMEMORY;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
*pcNames = i;
|
|
|
|
return S_OK;
|
2019-12-09 18:12:41 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI ScriptTypeInfo_GetRefTypeOfImplType(ITypeInfo *iface, UINT index, HREFTYPE *pRefType)
|
|
|
|
{
|
|
|
|
ScriptTypeInfo *This = ScriptTypeInfo_from_ITypeInfo(iface);
|
|
|
|
|
2019-12-13 13:59:46 +01:00
|
|
|
TRACE("(%p)->(%u %p)\n", This, index, pRefType);
|
2019-12-09 18:12:41 +01:00
|
|
|
|
2019-12-13 13:59:46 +01:00
|
|
|
/* We only inherit from IDispatch */
|
|
|
|
if (!pRefType) return E_INVALIDARG;
|
|
|
|
if (index != 0) return TYPE_E_ELEMENTNOTFOUND;
|
|
|
|
|
|
|
|
*pRefType = 1;
|
|
|
|
return S_OK;
|
2019-12-09 18:12:41 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI ScriptTypeInfo_GetImplTypeFlags(ITypeInfo *iface, UINT index, INT *pImplTypeFlags)
|
|
|
|
{
|
|
|
|
ScriptTypeInfo *This = ScriptTypeInfo_from_ITypeInfo(iface);
|
|
|
|
|
2019-12-13 13:59:48 +01:00
|
|
|
TRACE("(%p)->(%u %p)\n", This, index, pImplTypeFlags);
|
2019-12-09 18:12:41 +01:00
|
|
|
|
2019-12-13 13:59:48 +01:00
|
|
|
if (!pImplTypeFlags) return E_INVALIDARG;
|
|
|
|
if (index != 0) return TYPE_E_ELEMENTNOTFOUND;
|
|
|
|
|
|
|
|
*pImplTypeFlags = 0;
|
|
|
|
return S_OK;
|
2019-12-09 18:12:41 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI ScriptTypeInfo_GetIDsOfNames(ITypeInfo *iface, LPOLESTR *rgszNames, UINT cNames,
|
|
|
|
MEMBERID *pMemId)
|
|
|
|
{
|
|
|
|
ScriptTypeInfo *This = ScriptTypeInfo_from_ITypeInfo(iface);
|
2019-12-12 13:53:59 +01:00
|
|
|
ITypeInfo *disp_typeinfo;
|
|
|
|
const WCHAR *name;
|
|
|
|
HRESULT hr = S_OK;
|
|
|
|
int i, j, arg;
|
2019-12-09 18:12:41 +01:00
|
|
|
|
2019-12-12 13:53:59 +01:00
|
|
|
TRACE("(%p)->(%p %u %p)\n", This, rgszNames, cNames, pMemId);
|
2019-12-09 18:12:41 +01:00
|
|
|
|
2019-12-12 13:53:59 +01:00
|
|
|
if (!rgszNames || !cNames || !pMemId) return E_INVALIDARG;
|
|
|
|
|
|
|
|
for (i = 0; i < cNames; i++) pMemId[i] = MEMBERID_NIL;
|
|
|
|
name = rgszNames[0];
|
|
|
|
|
|
|
|
for (i = 0; i < This->num_funcs; i++)
|
|
|
|
{
|
|
|
|
struct typeinfo_func *func = &This->funcs[i];
|
|
|
|
|
|
|
|
if (wcsicmp(name, func->prop->name)) continue;
|
|
|
|
pMemId[0] = prop_to_id(This->jsdisp, func->prop);
|
|
|
|
|
|
|
|
for (j = 1; j < cNames; j++)
|
|
|
|
{
|
|
|
|
name = rgszNames[j];
|
|
|
|
for (arg = func->code->param_cnt; --arg >= 0;)
|
|
|
|
if (!wcsicmp(name, func->code->params[arg]))
|
|
|
|
break;
|
|
|
|
if (arg >= 0)
|
|
|
|
pMemId[j] = arg;
|
|
|
|
else
|
|
|
|
hr = DISP_E_UNKNOWNNAME;
|
|
|
|
}
|
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (i = 0; i < This->num_vars; i++)
|
|
|
|
{
|
|
|
|
dispex_prop_t *var = This->vars[i];
|
|
|
|
|
|
|
|
if (wcsicmp(name, var->name)) continue;
|
|
|
|
pMemId[0] = prop_to_id(This->jsdisp, var);
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Look into the inherited IDispatch */
|
|
|
|
hr = get_dispatch_typeinfo(&disp_typeinfo);
|
|
|
|
if (FAILED(hr)) return hr;
|
|
|
|
|
|
|
|
return ITypeInfo_GetIDsOfNames(disp_typeinfo, rgszNames, cNames, pMemId);
|
2019-12-09 18:12:41 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI ScriptTypeInfo_Invoke(ITypeInfo *iface, PVOID pvInstance, MEMBERID memid, WORD wFlags,
|
|
|
|
DISPPARAMS *pDispParams, VARIANT *pVarResult, EXCEPINFO *pExcepInfo, UINT *puArgErr)
|
|
|
|
{
|
|
|
|
ScriptTypeInfo *This = ScriptTypeInfo_from_ITypeInfo(iface);
|
2019-12-13 13:59:49 +01:00
|
|
|
ITypeInfo *disp_typeinfo;
|
|
|
|
IDispatch *disp;
|
|
|
|
HRESULT hr;
|
2019-12-09 18:12:41 +01:00
|
|
|
|
2022-02-11 08:41:11 +01:00
|
|
|
TRACE("(%p)->(%p %ld %d %p %p %p %p)\n", This, pvInstance, memid, wFlags,
|
2019-12-09 18:12:41 +01:00
|
|
|
pDispParams, pVarResult, pExcepInfo, puArgErr);
|
|
|
|
|
2019-12-13 13:59:49 +01:00
|
|
|
if (!pvInstance) return E_INVALIDARG;
|
|
|
|
if (memid <= 0) return TYPE_E_ELEMENTNOTFOUND;
|
|
|
|
|
|
|
|
if (!get_func_from_memid(This, memid) && !get_var_from_memid(This, memid))
|
|
|
|
{
|
|
|
|
hr = get_dispatch_typeinfo(&disp_typeinfo);
|
|
|
|
if (FAILED(hr)) return hr;
|
|
|
|
|
|
|
|
return ITypeInfo_Invoke(disp_typeinfo, pvInstance, memid, wFlags, pDispParams,
|
|
|
|
pVarResult, pExcepInfo, puArgErr);
|
|
|
|
}
|
|
|
|
|
|
|
|
hr = IUnknown_QueryInterface((IUnknown*)pvInstance, &IID_IDispatch, (void**)&disp);
|
|
|
|
if (FAILED(hr)) return hr;
|
|
|
|
|
|
|
|
hr = IDispatch_Invoke(disp, memid, &IID_NULL, LOCALE_USER_DEFAULT, wFlags,
|
|
|
|
pDispParams, pVarResult, pExcepInfo, puArgErr);
|
|
|
|
IDispatch_Release(disp);
|
|
|
|
|
|
|
|
return hr;
|
2019-12-09 18:12:41 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI ScriptTypeInfo_GetDocumentation(ITypeInfo *iface, MEMBERID memid, BSTR *pBstrName,
|
|
|
|
BSTR *pBstrDocString, DWORD *pdwHelpContext, BSTR *pBstrHelpFile)
|
|
|
|
{
|
|
|
|
ScriptTypeInfo *This = ScriptTypeInfo_from_ITypeInfo(iface);
|
2019-12-13 13:59:50 +01:00
|
|
|
struct typeinfo_func *func;
|
|
|
|
ITypeInfo *disp_typeinfo;
|
|
|
|
dispex_prop_t *var;
|
|
|
|
HRESULT hr;
|
2019-12-09 18:12:41 +01:00
|
|
|
|
2022-02-11 08:41:11 +01:00
|
|
|
TRACE("(%p)->(%ld %p %p %p %p)\n", This, memid, pBstrName, pBstrDocString, pdwHelpContext, pBstrHelpFile);
|
2019-12-13 13:59:50 +01:00
|
|
|
|
|
|
|
if (pBstrDocString) *pBstrDocString = NULL;
|
|
|
|
if (pdwHelpContext) *pdwHelpContext = 0;
|
|
|
|
if (pBstrHelpFile) *pBstrHelpFile = NULL;
|
|
|
|
|
|
|
|
if (memid == MEMBERID_NIL)
|
|
|
|
{
|
|
|
|
if (pBstrName && !(*pBstrName = SysAllocString(L"JScriptTypeInfo")))
|
|
|
|
return E_OUTOFMEMORY;
|
|
|
|
if (pBstrDocString &&
|
|
|
|
!(*pBstrDocString = SysAllocString(L"JScript Type Info")))
|
|
|
|
{
|
|
|
|
if (pBstrName) SysFreeString(*pBstrName);
|
|
|
|
return E_OUTOFMEMORY;
|
|
|
|
}
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
if (memid <= 0) return TYPE_E_ELEMENTNOTFOUND;
|
2019-12-09 18:12:41 +01:00
|
|
|
|
2019-12-13 13:59:50 +01:00
|
|
|
func = get_func_from_memid(This, memid);
|
|
|
|
if (!func)
|
|
|
|
{
|
|
|
|
var = get_var_from_memid(This, memid);
|
|
|
|
if (!var)
|
|
|
|
{
|
|
|
|
hr = get_dispatch_typeinfo(&disp_typeinfo);
|
|
|
|
if (FAILED(hr)) return hr;
|
|
|
|
|
|
|
|
return ITypeInfo_GetDocumentation(disp_typeinfo, memid, pBstrName, pBstrDocString,
|
|
|
|
pdwHelpContext, pBstrHelpFile);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (pBstrName)
|
|
|
|
{
|
|
|
|
*pBstrName = SysAllocString(func ? func->prop->name : var->name);
|
|
|
|
|
|
|
|
if (!*pBstrName)
|
|
|
|
return E_OUTOFMEMORY;
|
|
|
|
}
|
|
|
|
return S_OK;
|
2019-12-09 18:12:41 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI ScriptTypeInfo_GetDllEntry(ITypeInfo *iface, MEMBERID memid, INVOKEKIND invKind,
|
|
|
|
BSTR *pBstrDllName, BSTR *pBstrName, WORD *pwOrdinal)
|
|
|
|
{
|
|
|
|
ScriptTypeInfo *This = ScriptTypeInfo_from_ITypeInfo(iface);
|
2019-12-13 13:59:51 +01:00
|
|
|
ITypeInfo *disp_typeinfo;
|
|
|
|
HRESULT hr;
|
2019-12-09 18:12:41 +01:00
|
|
|
|
2022-02-11 08:41:11 +01:00
|
|
|
TRACE("(%p)->(%ld %d %p %p %p)\n", This, memid, invKind, pBstrDllName, pBstrName, pwOrdinal);
|
2019-12-09 18:12:41 +01:00
|
|
|
|
2019-12-13 13:59:51 +01:00
|
|
|
if (pBstrDllName) *pBstrDllName = NULL;
|
|
|
|
if (pBstrName) *pBstrName = NULL;
|
|
|
|
if (pwOrdinal) *pwOrdinal = 0;
|
|
|
|
|
|
|
|
if (!get_func_from_memid(This, memid) && !get_var_from_memid(This, memid))
|
|
|
|
{
|
|
|
|
hr = get_dispatch_typeinfo(&disp_typeinfo);
|
|
|
|
if (FAILED(hr)) return hr;
|
|
|
|
|
|
|
|
return ITypeInfo_GetDllEntry(disp_typeinfo, memid, invKind, pBstrDllName, pBstrName, pwOrdinal);
|
|
|
|
}
|
|
|
|
return TYPE_E_BADMODULEKIND;
|
2019-12-09 18:12:41 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI ScriptTypeInfo_GetRefTypeInfo(ITypeInfo *iface, HREFTYPE hRefType, ITypeInfo **ppTInfo)
|
|
|
|
{
|
|
|
|
ScriptTypeInfo *This = ScriptTypeInfo_from_ITypeInfo(iface);
|
2019-12-13 13:59:47 +01:00
|
|
|
HRESULT hr;
|
2019-12-09 18:12:41 +01:00
|
|
|
|
2022-02-11 08:41:11 +01:00
|
|
|
TRACE("(%p)->(%lx %p)\n", This, hRefType, ppTInfo);
|
2019-12-09 18:12:41 +01:00
|
|
|
|
2019-12-13 13:59:47 +01:00
|
|
|
if (!ppTInfo || (INT)hRefType < 0) return E_INVALIDARG;
|
|
|
|
|
|
|
|
if (hRefType & ~3) return E_FAIL;
|
|
|
|
if (hRefType & 1)
|
|
|
|
{
|
|
|
|
hr = get_dispatch_typeinfo(ppTInfo);
|
|
|
|
if (FAILED(hr)) return hr;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
*ppTInfo = iface;
|
|
|
|
|
|
|
|
ITypeInfo_AddRef(*ppTInfo);
|
|
|
|
return S_OK;
|
2019-12-09 18:12:41 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI ScriptTypeInfo_AddressOfMember(ITypeInfo *iface, MEMBERID memid, INVOKEKIND invKind, PVOID *ppv)
|
|
|
|
{
|
|
|
|
ScriptTypeInfo *This = ScriptTypeInfo_from_ITypeInfo(iface);
|
2019-12-13 13:59:52 +01:00
|
|
|
ITypeInfo *disp_typeinfo;
|
|
|
|
HRESULT hr;
|
|
|
|
|
2022-02-11 08:41:11 +01:00
|
|
|
TRACE("(%p)->(%ld %d %p)\n", This, memid, invKind, ppv);
|
2019-12-09 18:12:41 +01:00
|
|
|
|
2019-12-13 13:59:52 +01:00
|
|
|
if (!ppv) return E_INVALIDARG;
|
|
|
|
*ppv = NULL;
|
|
|
|
|
|
|
|
if (!get_func_from_memid(This, memid) && !get_var_from_memid(This, memid))
|
|
|
|
{
|
|
|
|
hr = get_dispatch_typeinfo(&disp_typeinfo);
|
|
|
|
if (FAILED(hr)) return hr;
|
2019-12-09 18:12:41 +01:00
|
|
|
|
2019-12-13 13:59:52 +01:00
|
|
|
return ITypeInfo_AddressOfMember(disp_typeinfo, memid, invKind, ppv);
|
|
|
|
}
|
|
|
|
return TYPE_E_BADMODULEKIND;
|
2019-12-09 18:12:41 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI ScriptTypeInfo_CreateInstance(ITypeInfo *iface, IUnknown *pUnkOuter, REFIID riid, PVOID *ppvObj)
|
|
|
|
{
|
|
|
|
ScriptTypeInfo *This = ScriptTypeInfo_from_ITypeInfo(iface);
|
|
|
|
|
2019-12-13 13:59:53 +01:00
|
|
|
TRACE("(%p)->(%p %s %p)\n", This, pUnkOuter, debugstr_guid(riid), ppvObj);
|
2019-12-09 18:12:41 +01:00
|
|
|
|
2019-12-13 13:59:53 +01:00
|
|
|
if (!ppvObj) return E_INVALIDARG;
|
|
|
|
|
|
|
|
*ppvObj = NULL;
|
|
|
|
return TYPE_E_BADMODULEKIND;
|
2019-12-09 18:12:41 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI ScriptTypeInfo_GetMops(ITypeInfo *iface, MEMBERID memid, BSTR *pBstrMops)
|
|
|
|
{
|
|
|
|
ScriptTypeInfo *This = ScriptTypeInfo_from_ITypeInfo(iface);
|
2019-12-13 13:59:54 +01:00
|
|
|
ITypeInfo *disp_typeinfo;
|
|
|
|
HRESULT hr;
|
2019-12-09 18:12:41 +01:00
|
|
|
|
2022-02-11 08:41:11 +01:00
|
|
|
TRACE("(%p)->(%ld %p)\n", This, memid, pBstrMops);
|
2019-12-09 18:12:41 +01:00
|
|
|
|
2019-12-13 13:59:54 +01:00
|
|
|
if (!pBstrMops) return E_INVALIDARG;
|
|
|
|
|
|
|
|
if (!get_func_from_memid(This, memid) && !get_var_from_memid(This, memid))
|
|
|
|
{
|
|
|
|
hr = get_dispatch_typeinfo(&disp_typeinfo);
|
|
|
|
if (FAILED(hr)) return hr;
|
|
|
|
|
|
|
|
return ITypeInfo_GetMops(disp_typeinfo, memid, pBstrMops);
|
|
|
|
}
|
|
|
|
|
|
|
|
*pBstrMops = NULL;
|
|
|
|
return S_OK;
|
2019-12-09 18:12:41 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI ScriptTypeInfo_GetContainingTypeLib(ITypeInfo *iface, ITypeLib **ppTLib, UINT *pIndex)
|
|
|
|
{
|
|
|
|
ScriptTypeInfo *This = ScriptTypeInfo_from_ITypeInfo(iface);
|
|
|
|
|
|
|
|
FIXME("(%p)->(%p %p)\n", This, ppTLib, pIndex);
|
|
|
|
|
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void WINAPI ScriptTypeInfo_ReleaseTypeAttr(ITypeInfo *iface, TYPEATTR *pTypeAttr)
|
|
|
|
{
|
|
|
|
ScriptTypeInfo *This = ScriptTypeInfo_from_ITypeInfo(iface);
|
|
|
|
|
2019-12-12 13:53:56 +01:00
|
|
|
TRACE("(%p)->(%p)\n", This, pTypeAttr);
|
|
|
|
|
|
|
|
heap_free(pTypeAttr);
|
2019-12-09 18:12:41 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static void WINAPI ScriptTypeInfo_ReleaseFuncDesc(ITypeInfo *iface, FUNCDESC *pFuncDesc)
|
|
|
|
{
|
|
|
|
ScriptTypeInfo *This = ScriptTypeInfo_from_ITypeInfo(iface);
|
|
|
|
|
2019-12-12 13:53:57 +01:00
|
|
|
TRACE("(%p)->(%p)\n", This, pFuncDesc);
|
|
|
|
|
|
|
|
heap_free(pFuncDesc);
|
2019-12-09 18:12:41 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static void WINAPI ScriptTypeInfo_ReleaseVarDesc(ITypeInfo *iface, VARDESC *pVarDesc)
|
|
|
|
{
|
|
|
|
ScriptTypeInfo *This = ScriptTypeInfo_from_ITypeInfo(iface);
|
|
|
|
|
2019-12-12 13:53:58 +01:00
|
|
|
TRACE("(%p)->(%p)\n", This, pVarDesc);
|
|
|
|
|
|
|
|
heap_free(pVarDesc);
|
2019-12-09 18:12:41 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static const ITypeInfoVtbl ScriptTypeInfoVtbl = {
|
|
|
|
ScriptTypeInfo_QueryInterface,
|
|
|
|
ScriptTypeInfo_AddRef,
|
|
|
|
ScriptTypeInfo_Release,
|
|
|
|
ScriptTypeInfo_GetTypeAttr,
|
|
|
|
ScriptTypeInfo_GetTypeComp,
|
|
|
|
ScriptTypeInfo_GetFuncDesc,
|
|
|
|
ScriptTypeInfo_GetVarDesc,
|
|
|
|
ScriptTypeInfo_GetNames,
|
|
|
|
ScriptTypeInfo_GetRefTypeOfImplType,
|
|
|
|
ScriptTypeInfo_GetImplTypeFlags,
|
|
|
|
ScriptTypeInfo_GetIDsOfNames,
|
|
|
|
ScriptTypeInfo_Invoke,
|
|
|
|
ScriptTypeInfo_GetDocumentation,
|
|
|
|
ScriptTypeInfo_GetDllEntry,
|
|
|
|
ScriptTypeInfo_GetRefTypeInfo,
|
|
|
|
ScriptTypeInfo_AddressOfMember,
|
|
|
|
ScriptTypeInfo_CreateInstance,
|
|
|
|
ScriptTypeInfo_GetMops,
|
|
|
|
ScriptTypeInfo_GetContainingTypeLib,
|
|
|
|
ScriptTypeInfo_ReleaseTypeAttr,
|
|
|
|
ScriptTypeInfo_ReleaseFuncDesc,
|
|
|
|
ScriptTypeInfo_ReleaseVarDesc
|
|
|
|
};
|
|
|
|
|
2019-12-12 13:54:00 +01:00
|
|
|
static HRESULT WINAPI ScriptTypeComp_QueryInterface(ITypeComp *iface, REFIID riid, void **ppv)
|
|
|
|
{
|
|
|
|
ScriptTypeInfo *This = ScriptTypeInfo_from_ITypeComp(iface);
|
|
|
|
return ITypeInfo_QueryInterface(&This->ITypeInfo_iface, riid, ppv);
|
|
|
|
}
|
|
|
|
|
|
|
|
static ULONG WINAPI ScriptTypeComp_AddRef(ITypeComp *iface)
|
|
|
|
{
|
|
|
|
ScriptTypeInfo *This = ScriptTypeInfo_from_ITypeComp(iface);
|
|
|
|
return ITypeInfo_AddRef(&This->ITypeInfo_iface);
|
|
|
|
}
|
|
|
|
|
|
|
|
static ULONG WINAPI ScriptTypeComp_Release(ITypeComp *iface)
|
|
|
|
{
|
|
|
|
ScriptTypeInfo *This = ScriptTypeInfo_from_ITypeComp(iface);
|
|
|
|
return ITypeInfo_Release(&This->ITypeInfo_iface);
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI ScriptTypeComp_Bind(ITypeComp *iface, LPOLESTR szName, ULONG lHashVal, WORD wFlags,
|
|
|
|
ITypeInfo **ppTInfo, DESCKIND *pDescKind, BINDPTR *pBindPtr)
|
|
|
|
{
|
|
|
|
ScriptTypeInfo *This = ScriptTypeInfo_from_ITypeComp(iface);
|
2019-12-12 13:54:01 +01:00
|
|
|
UINT flags = wFlags ? wFlags : ~0;
|
|
|
|
ITypeInfo *disp_typeinfo;
|
|
|
|
ITypeComp *disp_typecomp;
|
|
|
|
HRESULT hr;
|
|
|
|
UINT i;
|
2019-12-12 13:54:00 +01:00
|
|
|
|
2022-02-11 08:41:11 +01:00
|
|
|
TRACE("(%p)->(%s %08lx %d %p %p %p)\n", This, debugstr_w(szName), lHashVal,
|
2019-12-12 13:54:00 +01:00
|
|
|
wFlags, ppTInfo, pDescKind, pBindPtr);
|
|
|
|
|
2019-12-12 13:54:01 +01:00
|
|
|
if (!szName || !ppTInfo || !pDescKind || !pBindPtr)
|
|
|
|
return E_INVALIDARG;
|
|
|
|
|
|
|
|
for (i = 0; i < This->num_funcs; i++)
|
|
|
|
{
|
|
|
|
if (wcsicmp(szName, This->funcs[i].prop->name)) continue;
|
|
|
|
if (!(flags & INVOKE_FUNC)) return TYPE_E_TYPEMISMATCH;
|
|
|
|
|
|
|
|
hr = ITypeInfo_GetFuncDesc(&This->ITypeInfo_iface, i, &pBindPtr->lpfuncdesc);
|
|
|
|
if (FAILED(hr)) return hr;
|
|
|
|
|
|
|
|
*pDescKind = DESCKIND_FUNCDESC;
|
|
|
|
*ppTInfo = &This->ITypeInfo_iface;
|
|
|
|
ITypeInfo_AddRef(*ppTInfo);
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (i = 0; i < This->num_vars; i++)
|
|
|
|
{
|
|
|
|
if (wcsicmp(szName, This->vars[i]->name)) continue;
|
|
|
|
if (!(flags & INVOKE_PROPERTYGET)) return TYPE_E_TYPEMISMATCH;
|
|
|
|
|
|
|
|
hr = ITypeInfo_GetVarDesc(&This->ITypeInfo_iface, i, &pBindPtr->lpvardesc);
|
|
|
|
if (FAILED(hr)) return hr;
|
|
|
|
|
|
|
|
*pDescKind = DESCKIND_VARDESC;
|
|
|
|
*ppTInfo = &This->ITypeInfo_iface;
|
|
|
|
ITypeInfo_AddRef(*ppTInfo);
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Look into the inherited IDispatch */
|
|
|
|
hr = get_dispatch_typeinfo(&disp_typeinfo);
|
|
|
|
if (FAILED(hr)) return hr;
|
|
|
|
|
|
|
|
hr = ITypeInfo_GetTypeComp(disp_typeinfo, &disp_typecomp);
|
|
|
|
if (FAILED(hr)) return hr;
|
|
|
|
|
|
|
|
hr = ITypeComp_Bind(disp_typecomp, szName, lHashVal, wFlags, ppTInfo, pDescKind, pBindPtr);
|
|
|
|
ITypeComp_Release(disp_typecomp);
|
|
|
|
return hr;
|
2019-12-12 13:54:00 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI ScriptTypeComp_BindType(ITypeComp *iface, LPOLESTR szName, ULONG lHashVal,
|
|
|
|
ITypeInfo **ppTInfo, ITypeComp **ppTComp)
|
|
|
|
{
|
|
|
|
ScriptTypeInfo *This = ScriptTypeInfo_from_ITypeComp(iface);
|
2019-12-12 13:54:02 +01:00
|
|
|
ITypeInfo *disp_typeinfo;
|
|
|
|
ITypeComp *disp_typecomp;
|
|
|
|
HRESULT hr;
|
2019-12-12 13:54:00 +01:00
|
|
|
|
2022-02-11 08:41:11 +01:00
|
|
|
TRACE("(%p)->(%s %08lx %p %p)\n", This, debugstr_w(szName), lHashVal, ppTInfo, ppTComp);
|
2019-12-12 13:54:00 +01:00
|
|
|
|
2019-12-12 13:54:02 +01:00
|
|
|
if (!szName || !ppTInfo || !ppTComp)
|
|
|
|
return E_INVALIDARG;
|
|
|
|
|
|
|
|
/* Look into the inherited IDispatch */
|
|
|
|
hr = get_dispatch_typeinfo(&disp_typeinfo);
|
|
|
|
if (FAILED(hr)) return hr;
|
|
|
|
|
|
|
|
hr = ITypeInfo_GetTypeComp(disp_typeinfo, &disp_typecomp);
|
|
|
|
if (FAILED(hr)) return hr;
|
|
|
|
|
|
|
|
hr = ITypeComp_BindType(disp_typecomp, szName, lHashVal, ppTInfo, ppTComp);
|
|
|
|
ITypeComp_Release(disp_typecomp);
|
|
|
|
return hr;
|
2019-12-12 13:54:00 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static const ITypeCompVtbl ScriptTypeCompVtbl = {
|
|
|
|
ScriptTypeComp_QueryInterface,
|
|
|
|
ScriptTypeComp_AddRef,
|
|
|
|
ScriptTypeComp_Release,
|
|
|
|
ScriptTypeComp_Bind,
|
|
|
|
ScriptTypeComp_BindType
|
|
|
|
};
|
|
|
|
|
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-01 01:23:38 +02:00
|
|
|
}else {
|
|
|
|
WARN("(%p)->(%s %p)\n", This, debugstr_guid(riid), ppv);
|
|
|
|
*ppv = NULL;
|
|
|
|
return E_NOINTERFACE;
|
|
|
|
}
|
|
|
|
|
2012-10-26 13:28:17 +02:00
|
|
|
jsdisp_addref(This);
|
2008-09-01 01:23:38 +02:00
|
|
|
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);
|
2012-10-26 13:28:17 +02:00
|
|
|
jsdisp_addref(This);
|
|
|
|
return This->ref;
|
2008-09-01 01:23:38 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static ULONG WINAPI DispatchEx_Release(IDispatchEx *iface)
|
|
|
|
{
|
2011-01-16 21:27:20 +01:00
|
|
|
jsdisp_t *This = impl_from_IDispatchEx(iface);
|
2012-10-26 13:28:17 +02:00
|
|
|
ULONG ref = --This->ref;
|
2022-02-11 08:41:11 +01:00
|
|
|
TRACE("(%p) ref=%ld\n", This, ref);
|
2012-10-26 13:28:17 +02:00
|
|
|
if(!ref)
|
|
|
|
jsdisp_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);
|
2019-12-12 13:53:55 +01:00
|
|
|
dispex_prop_t *prop, *cur, *end, **typevar;
|
|
|
|
UINT num_funcs = 0, num_vars = 0;
|
|
|
|
struct typeinfo_func *typefunc;
|
|
|
|
function_code_t *func_code;
|
2019-12-09 18:12:41 +01:00
|
|
|
ScriptTypeInfo *typeinfo;
|
2019-12-12 13:53:55 +01:00
|
|
|
unsigned pos;
|
2019-12-09 18:12:41 +01:00
|
|
|
|
2022-02-11 08:41:11 +01:00
|
|
|
TRACE("(%p)->(%u %lu %p)\n", This, iTInfo, lcid, ppTInfo);
|
2019-12-09 18:12:41 +01:00
|
|
|
|
|
|
|
if (iTInfo != 0) return DISP_E_BADINDEX;
|
|
|
|
|
2019-12-12 13:53:55 +01:00
|
|
|
for (prop = This->props, end = prop + This->prop_cnt; prop != end; prop++)
|
|
|
|
{
|
2021-11-25 21:01:28 +01:00
|
|
|
if (prop->type != PROP_JSVAL || !(prop->flags & PROPF_ENUMERABLE))
|
2019-12-12 13:53:55 +01:00
|
|
|
continue;
|
|
|
|
|
|
|
|
/* If two identifiers differ only by case, the TypeInfo fails */
|
|
|
|
pos = This->props[get_props_idx(This, prop->hash)].bucket_head;
|
2021-11-24 15:10:35 +01:00
|
|
|
while (pos != ~0)
|
2019-12-12 13:53:55 +01:00
|
|
|
{
|
|
|
|
cur = This->props + pos;
|
|
|
|
|
|
|
|
if (prop->hash == cur->hash && prop != cur &&
|
|
|
|
cur->type == PROP_JSVAL && (cur->flags & PROPF_ENUMERABLE) &&
|
|
|
|
!wcsicmp(prop->name, cur->name))
|
|
|
|
{
|
|
|
|
return TYPE_E_AMBIGUOUSNAME;
|
|
|
|
}
|
|
|
|
pos = cur->bucket_next;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (is_function_prop(prop))
|
|
|
|
{
|
|
|
|
if (Function_get_code(as_jsdisp(get_object(prop->u.val))))
|
|
|
|
num_funcs++;
|
|
|
|
}
|
|
|
|
else num_vars++;
|
|
|
|
}
|
|
|
|
|
2019-12-09 18:12:41 +01:00
|
|
|
if (!(typeinfo = heap_alloc(sizeof(*typeinfo))))
|
|
|
|
return E_OUTOFMEMORY;
|
|
|
|
|
|
|
|
typeinfo->ITypeInfo_iface.lpVtbl = &ScriptTypeInfoVtbl;
|
2019-12-12 13:54:00 +01:00
|
|
|
typeinfo->ITypeComp_iface.lpVtbl = &ScriptTypeCompVtbl;
|
2019-12-09 18:12:41 +01:00
|
|
|
typeinfo->ref = 1;
|
2019-12-12 13:53:55 +01:00
|
|
|
typeinfo->num_vars = num_vars;
|
|
|
|
typeinfo->num_funcs = num_funcs;
|
|
|
|
typeinfo->jsdisp = This;
|
|
|
|
|
|
|
|
typeinfo->funcs = heap_alloc(sizeof(*typeinfo->funcs) * num_funcs);
|
|
|
|
if (!typeinfo->funcs)
|
|
|
|
{
|
|
|
|
heap_free(typeinfo);
|
|
|
|
return E_OUTOFMEMORY;
|
|
|
|
}
|
|
|
|
|
|
|
|
typeinfo->vars = heap_alloc(sizeof(*typeinfo->vars) * num_vars);
|
|
|
|
if (!typeinfo->vars)
|
|
|
|
{
|
|
|
|
heap_free(typeinfo->funcs);
|
|
|
|
heap_free(typeinfo);
|
|
|
|
return E_OUTOFMEMORY;
|
|
|
|
}
|
|
|
|
|
|
|
|
typefunc = typeinfo->funcs;
|
|
|
|
typevar = typeinfo->vars;
|
|
|
|
for (prop = This->props; prop != end; prop++)
|
|
|
|
{
|
2021-11-25 21:01:28 +01:00
|
|
|
if (prop->type != PROP_JSVAL || !(prop->flags & PROPF_ENUMERABLE))
|
2019-12-12 13:53:55 +01:00
|
|
|
continue;
|
|
|
|
|
|
|
|
if (is_function_prop(prop))
|
|
|
|
{
|
|
|
|
func_code = Function_get_code(as_jsdisp(get_object(prop->u.val)));
|
|
|
|
if (!func_code) continue;
|
|
|
|
|
|
|
|
typefunc->prop = prop;
|
|
|
|
typefunc->code = func_code;
|
|
|
|
typefunc++;
|
|
|
|
|
|
|
|
/* The function may be deleted, so keep a ref */
|
|
|
|
bytecode_addref(func_code->bytecode);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
*typevar++ = prop;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Keep a ref to the props and their names */
|
|
|
|
IDispatchEx_AddRef(&This->IDispatchEx_iface);
|
2019-12-09 18:12:41 +01:00
|
|
|
|
|
|
|
*ppTInfo = &typeinfo->ITypeInfo_iface;
|
|
|
|
return S_OK;
|
2008-09-01 01:23:38 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
2022-02-11 08:41:11 +01:00
|
|
|
TRACE("(%p)->(%s %p %u %lu %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
|
|
|
|
2021-08-04 17:51:46 +02:00
|
|
|
if(cNames == 0)
|
|
|
|
return S_OK;
|
|
|
|
|
|
|
|
hres = jsdisp_get_id(This, rgszNames[0], 0, rgDispId);
|
|
|
|
if(FAILED(hres))
|
|
|
|
return hres;
|
|
|
|
|
|
|
|
/* DISPIDs for parameters don't seem to be supported */
|
|
|
|
if(cNames > 1) {
|
|
|
|
for(i = 1; i < cNames; i++)
|
|
|
|
rgDispId[i] = DISPID_UNKNOWN;
|
|
|
|
hres = DISP_E_UNKNOWNNAME;
|
2008-09-01 01:24:23 +02:00
|
|
|
}
|
|
|
|
|
2021-08-04 17:51:46 +02:00
|
|
|
return hres;
|
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
|
|
|
|
2022-02-11 08:41:11 +01:00
|
|
|
TRACE("(%p)->(%ld %s %ld %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
|
|
|
|
2022-02-11 08:41:11 +01:00
|
|
|
TRACE("(%p)->(%s %lx %p)\n", This, debugstr_w(bstrName), grfdex, pid);
|
2008-09-08 00:14:58 +02:00
|
|
|
|
2009-10-19 20:39:56 +02:00
|
|
|
if(grfdex & ~(fdexNameCaseSensitive|fdexNameEnsure|fdexNameImplicit|FDEX_VERSION_MASK)) {
|
2022-02-11 08:41:11 +01:00
|
|
|
FIXME("Unsupported grfdex %lx\n", grfdex);
|
2008-09-08 00:14:58 +02:00
|
|
|
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;
|
2020-01-30 15:50:15 +01:00
|
|
|
jsexcept_t ei;
|
2008-09-09 01:20:26 +02:00
|
|
|
HRESULT hres;
|
|
|
|
|
2022-02-11 08:41:11 +01:00
|
|
|
TRACE("(%p)->(%lx %lx %x %p %p %p %p)\n", This, id, lcid, wFlags, pdp, pvarRes, pei, pspCaller);
|
2008-09-09 01:20:26 +02:00
|
|
|
|
|
|
|
if(pvarRes)
|
|
|
|
V_VT(pvarRes) = VT_EMPTY;
|
|
|
|
|
|
|
|
prop = get_prop(This, id);
|
2021-11-25 21:01:28 +01:00
|
|
|
if(!prop && id != DISPID_VALUE) {
|
2008-09-09 01:20:26 +02:00
|
|
|
TRACE("invalid id\n");
|
|
|
|
return DISP_E_MEMBERNOTFOUND;
|
|
|
|
}
|
|
|
|
|
2020-01-30 15:50:15 +01:00
|
|
|
enter_script(This->ctx, &ei);
|
2008-09-09 01:20:26 +02:00
|
|
|
|
|
|
|
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:
|
2012-06-21 10:48:36 +02:00
|
|
|
case DISPATCH_CONSTRUCT: {
|
2012-09-17 15:16:42 +02:00
|
|
|
jsval_t *argv, buf[6], r;
|
2012-06-25 14:08:38 +02:00
|
|
|
unsigned argc;
|
2012-06-21 10:48:36 +02:00
|
|
|
|
2012-06-25 14:08:38 +02:00
|
|
|
hres = convert_params(pdp, buf, &argc, &argv);
|
2012-06-21 10:48:36 +02:00
|
|
|
if(FAILED(hres))
|
2020-01-30 15:50:15 +01:00
|
|
|
break;
|
2012-06-21 10:48:36 +02:00
|
|
|
|
2021-11-25 21:01:28 +01:00
|
|
|
if(prop)
|
|
|
|
hres = invoke_prop_func(This, get_this(pdp), prop, wFlags, argc, argv, pvarRes ? &r : NULL, pspCaller);
|
|
|
|
else
|
|
|
|
hres = jsdisp_call_value(This, get_this(pdp), wFlags, argc, argv, pvarRes ? &r : NULL);
|
|
|
|
|
2012-06-25 14:08:38 +02:00
|
|
|
if(argv != buf)
|
|
|
|
heap_free(argv);
|
2012-09-17 15:16:20 +02:00
|
|
|
if(SUCCEEDED(hres) && pvarRes) {
|
|
|
|
hres = jsval_to_variant(r, pvarRes);
|
|
|
|
jsval_release(r);
|
|
|
|
}
|
2008-09-09 01:20:26 +02:00
|
|
|
break;
|
2012-06-21 10:48:36 +02:00
|
|
|
}
|
2012-09-17 15:16:42 +02:00
|
|
|
case DISPATCH_PROPERTYGET: {
|
|
|
|
jsval_t r;
|
|
|
|
|
2021-11-24 15:10:34 +01:00
|
|
|
if(prop)
|
|
|
|
hres = prop_get(This, prop, &r);
|
|
|
|
else {
|
|
|
|
hres = to_primitive(This->ctx, jsval_obj(This), &r, NO_HINT);
|
|
|
|
if(hres == JS_E_TO_PRIMITIVE)
|
|
|
|
hres = DISP_E_MEMBERNOTFOUND;
|
|
|
|
}
|
|
|
|
|
2012-09-17 15:16:42 +02:00
|
|
|
if(SUCCEEDED(hres)) {
|
|
|
|
hres = jsval_to_variant(r, pvarRes);
|
|
|
|
jsval_release(r);
|
|
|
|
}
|
2008-09-09 01:20:26 +02:00
|
|
|
break;
|
2012-09-17 15:16:42 +02:00
|
|
|
}
|
2010-02-05 23:15:46 +01:00
|
|
|
case DISPATCH_PROPERTYPUT: {
|
2012-09-17 15:16:42 +02:00
|
|
|
jsval_t val;
|
2010-02-05 23:15:46 +01:00
|
|
|
DWORD i;
|
|
|
|
|
2021-11-24 15:10:34 +01:00
|
|
|
if(!prop) {
|
|
|
|
hres = DISP_E_MEMBERNOTFOUND;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2010-02-05 23:15:46 +01:00
|
|
|
for(i=0; i < pdp->cNamedArgs; i++) {
|
|
|
|
if(pdp->rgdispidNamedArgs[i] == DISPID_PROPERTYPUT)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(i == pdp->cNamedArgs) {
|
|
|
|
TRACE("no value to set\n");
|
2020-01-30 15:50:15 +01:00
|
|
|
hres = DISP_E_PARAMNOTOPTIONAL;
|
|
|
|
break;
|
2010-02-05 23:15:46 +01:00
|
|
|
}
|
|
|
|
|
2012-09-17 15:16:42 +02:00
|
|
|
hres = variant_to_jsval(pdp->rgvarg+i, &val);
|
|
|
|
if(FAILED(hres))
|
2020-01-30 15:50:15 +01:00
|
|
|
break;
|
2012-09-17 15:16:42 +02:00
|
|
|
|
2018-04-20 18:33:16 +02:00
|
|
|
hres = prop_put(This, prop, val);
|
2012-09-17 15:16:42 +02:00
|
|
|
jsval_release(val);
|
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);
|
2020-01-30 15:50:15 +01:00
|
|
|
hres = E_INVALIDARG;
|
|
|
|
break;
|
2008-09-09 01:20:26 +02:00
|
|
|
}
|
|
|
|
|
2020-01-30 15:50:15 +01:00
|
|
|
return leave_script(This->ctx, hres);
|
2008-09-01 01:23:38 +02:00
|
|
|
}
|
|
|
|
|
2012-11-30 13:02:32 +01:00
|
|
|
static HRESULT delete_prop(dispex_prop_t *prop, BOOL *ret)
|
2008-09-30 17:48:36 +02:00
|
|
|
{
|
2021-11-24 15:10:30 +01:00
|
|
|
if(prop->type == PROP_PROTREF) {
|
|
|
|
*ret = TRUE;
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
2018-05-03 14:58:44 +02:00
|
|
|
if(!(prop->flags & PROPF_CONFIGURABLE)) {
|
2012-11-30 13:02:32 +01:00
|
|
|
*ret = FALSE;
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
2021-11-24 15:10:33 +01:00
|
|
|
*ret = TRUE;
|
2012-11-30 13:02:32 +01:00
|
|
|
|
2021-11-24 15:10:33 +01:00
|
|
|
if(prop->type == PROP_JSVAL)
|
2012-09-17 15:17:24 +02:00
|
|
|
jsval_release(prop->u.val);
|
2021-11-24 15:10:33 +01:00
|
|
|
if(prop->type == PROP_ACCESSOR) {
|
|
|
|
if(prop->u.accessor.getter)
|
|
|
|
jsdisp_release(prop->u.accessor.getter);
|
|
|
|
if(prop->u.accessor.setter)
|
|
|
|
jsdisp_release(prop->u.accessor.setter);
|
2011-09-02 12:24:25 +02:00
|
|
|
}
|
2021-11-24 15:10:33 +01:00
|
|
|
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;
|
2012-11-30 13:02:32 +01:00
|
|
|
BOOL b;
|
2008-09-09 01:21:14 +02:00
|
|
|
HRESULT hres;
|
|
|
|
|
2022-02-11 08:41:11 +01:00
|
|
|
TRACE("(%p)->(%s %lx)\n", This, debugstr_w(bstrName), grfdex);
|
2008-09-09 01:21:14 +02:00
|
|
|
|
2009-10-19 20:39:56 +02:00
|
|
|
if(grfdex & ~(fdexNameCaseSensitive|fdexNameEnsure|fdexNameImplicit|FDEX_VERSION_MASK))
|
2022-02-11 08:41:11 +01:00
|
|
|
FIXME("Unsupported grfdex %lx\n", grfdex);
|
2008-09-09 01:21:14 +02:00
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2012-11-30 13:02:32 +01:00
|
|
|
return delete_prop(prop, &b);
|
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;
|
2012-11-30 13:02:32 +01:00
|
|
|
BOOL b;
|
2008-09-30 17:48:36 +02:00
|
|
|
|
2022-02-11 08:41:11 +01:00
|
|
|
TRACE("(%p)->(%lx)\n", This, id);
|
2008-09-30 17:48:36 +02:00
|
|
|
|
|
|
|
prop = get_prop(This, id);
|
|
|
|
if(!prop) {
|
|
|
|
WARN("invalid id\n");
|
|
|
|
return DISP_E_MEMBERNOTFOUND;
|
|
|
|
}
|
|
|
|
|
2012-11-30 13:02:32 +01:00
|
|
|
return delete_prop(prop, &b);
|
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);
|
2022-02-11 08:41:11 +01:00
|
|
|
FIXME("(%p)->(%lx %lx %p)\n", This, id, grfdexFetch, pgrfdex);
|
2008-09-01 01:23:38 +02:00
|
|
|
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;
|
|
|
|
|
2022-02-11 08:41:11 +01:00
|
|
|
TRACE("(%p)->(%lx %p)\n", This, id, pbstrName);
|
2008-09-09 01:21:38 +02:00
|
|
|
|
|
|
|
prop = get_prop(This, id);
|
2021-11-25 21:01:28 +01:00
|
|
|
if(!prop)
|
2008-09-09 01:21:38 +02:00
|
|
|
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);
|
2021-11-25 21:01:28 +01:00
|
|
|
HRESULT hres = S_FALSE;
|
2008-09-09 01:20:52 +02:00
|
|
|
|
2022-02-11 08:41:11 +01:00
|
|
|
TRACE("(%p)->(%lx %lx %p)\n", This, grfdex, id, pid);
|
2008-09-09 01:20:52 +02:00
|
|
|
|
2021-11-25 21:01:28 +01:00
|
|
|
if(id != DISPID_VALUE)
|
|
|
|
hres = jsdisp_next_prop(This, id, JSDISP_ENUM_ALL, pid);
|
2019-08-21 12:31:08 +02:00
|
|
|
if(hres == S_FALSE)
|
2008-09-09 01:20:52 +02:00
|
|
|
*pid = DISPID_STARTENUM;
|
2019-08-21 12:31:08 +02:00
|
|
|
return hres;
|
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
|
|
|
{
|
2021-11-24 15:10:35 +01:00
|
|
|
unsigned i;
|
|
|
|
|
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;
|
2021-04-01 18:18:40 +02:00
|
|
|
dispex->extensible = TRUE;
|
2021-11-25 21:01:28 +01:00
|
|
|
dispex->prop_cnt = 0;
|
2008-09-08 00:14:38 +02:00
|
|
|
|
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;
|
|
|
|
|
2021-11-24 15:10:35 +01:00
|
|
|
for(i = 0; i < dispex->buf_size; i++) {
|
|
|
|
dispex->props[i].bucket_head = ~0;
|
|
|
|
dispex->props[i].bucket_next = ~0;
|
|
|
|
}
|
|
|
|
|
2008-09-08 00:14:38 +02:00
|
|
|
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-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,
|
2021-11-25 21:01:37 +01:00
|
|
|
NULL,
|
2008-09-08 00:14:38 +02:00
|
|
|
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);
|
2012-10-31 10:21:09 +01:00
|
|
|
if(FAILED(hres)) {
|
|
|
|
heap_free(ret);
|
2008-09-01 01:23:38 +02:00
|
|
|
return hres;
|
2012-10-31 10:21:09 +01:00
|
|
|
}
|
2008-09-01 01:23:38 +02:00
|
|
|
|
|
|
|
*dispex = ret;
|
|
|
|
return S_OK;
|
|
|
|
}
|
2008-09-09 01:20:26 +02:00
|
|
|
|
2012-10-26 13:28:17 +02:00
|
|
|
void jsdisp_free(jsdisp_t *obj)
|
|
|
|
{
|
|
|
|
dispex_prop_t *prop;
|
|
|
|
|
|
|
|
TRACE("(%p)\n", obj);
|
|
|
|
|
|
|
|
for(prop = obj->props; prop < obj->props+obj->prop_cnt; prop++) {
|
2018-05-14 13:34:26 +02:00
|
|
|
switch(prop->type) {
|
|
|
|
case PROP_JSVAL:
|
2012-10-26 13:28:17 +02:00
|
|
|
jsval_release(prop->u.val);
|
2018-05-14 13:34:26 +02:00
|
|
|
break;
|
|
|
|
case PROP_ACCESSOR:
|
|
|
|
if(prop->u.accessor.getter)
|
|
|
|
jsdisp_release(prop->u.accessor.getter);
|
|
|
|
if(prop->u.accessor.setter)
|
|
|
|
jsdisp_release(prop->u.accessor.setter);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
};
|
2012-10-26 13:28:17 +02:00
|
|
|
heap_free(prop->name);
|
|
|
|
}
|
|
|
|
heap_free(obj->props);
|
|
|
|
script_release(obj->ctx);
|
|
|
|
if(obj->prototype)
|
|
|
|
jsdisp_release(obj->prototype);
|
|
|
|
|
|
|
|
if(obj->builtin_info->destructor)
|
|
|
|
obj->builtin_info->destructor(obj);
|
|
|
|
else
|
|
|
|
heap_free(obj);
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef TRACE_REFCNT
|
|
|
|
|
|
|
|
jsdisp_t *jsdisp_addref(jsdisp_t *jsdisp)
|
|
|
|
{
|
|
|
|
ULONG ref = ++jsdisp->ref;
|
|
|
|
TRACE("(%p) ref=%d\n", jsdisp, ref);
|
|
|
|
return jsdisp;
|
|
|
|
}
|
|
|
|
|
|
|
|
void jsdisp_release(jsdisp_t *jsdisp)
|
|
|
|
{
|
|
|
|
ULONG ref = --jsdisp->ref;
|
|
|
|
|
|
|
|
TRACE("(%p) ref=%d\n", jsdisp, ref);
|
|
|
|
|
|
|
|
if(!ref)
|
|
|
|
jsdisp_free(jsdisp);
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
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;
|
|
|
|
|
2020-11-24 00:49:04 +01:00
|
|
|
hres = find_prop_name_prot(constr, string_hash(L"prototype"), L"prototype", &prop);
|
2011-09-02 12:24:25 +02:00
|
|
|
if(SUCCEEDED(hres) && prop && prop->type!=PROP_DELETED) {
|
2012-09-17 15:16:42 +02:00
|
|
|
jsval_t val;
|
2008-09-10 02:33:15 +02:00
|
|
|
|
2018-04-20 18:33:09 +02:00
|
|
|
hres = prop_get(constr, prop, &val);
|
2008-09-10 02:33:15 +02:00
|
|
|
if(FAILED(hres)) {
|
|
|
|
ERR("Could not get prototype\n");
|
|
|
|
return hres;
|
|
|
|
}
|
|
|
|
|
2021-03-05 17:59:41 +01:00
|
|
|
if(is_object_instance(val) && get_object(val))
|
2016-07-20 13:40:41 +02:00
|
|
|
prot = iface_to_jsdisp(get_object(val));
|
2021-03-11 17:01:09 +01:00
|
|
|
else
|
2021-09-06 19:01:59 +02:00
|
|
|
prot = jsdisp_addref(ctx->object_prototype);
|
2021-03-11 17:01:09 +01:00
|
|
|
|
2012-09-17 15:16:42 +02:00
|
|
|
jsval_release(val);
|
2008-09-10 02:33:15 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
hres = init_dispex(dispex, ctx, builtin_info, prot);
|
|
|
|
|
|
|
|
if(prot)
|
2009-09-01 13:26:08 +02:00
|
|
|
jsdisp_release(prot);
|
2008-09-10 02:33:15 +02:00
|
|
|
return hres;
|
|
|
|
}
|
|
|
|
|
2016-07-20 13:40:41 +02:00
|
|
|
jsdisp_t *iface_to_jsdisp(IDispatch *iface)
|
2008-09-09 01:20:26 +02:00
|
|
|
{
|
2016-07-20 13:41:23 +02:00
|
|
|
return iface->lpVtbl == (const IDispatchVtbl*)&DispatchExVtbl
|
|
|
|
? jsdisp_addref( impl_from_IDispatchEx((IDispatchEx*)iface))
|
|
|
|
: NULL;
|
2008-09-09 01:20:26 +02:00
|
|
|
}
|
|
|
|
|
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;
|
|
|
|
|
2021-04-01 18:18:40 +02:00
|
|
|
if(jsdisp->extensible && (flags & fdexNameEnsure))
|
2018-05-15 13:26:52 +02:00
|
|
|
hres = ensure_prop_name(jsdisp, name, PROPF_ENUMERABLE | PROPF_CONFIGURABLE | PROPF_WRITABLE,
|
2018-05-03 14:58:55 +02:00
|
|
|
&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));
|
2019-11-06 16:27:59 +01:00
|
|
|
*id = DISPID_UNKNOWN;
|
2008-09-30 17:47:24 +02:00
|
|
|
return DISP_E_UNKNOWNNAME;
|
|
|
|
}
|
|
|
|
|
2012-09-18 19:01:49 +02:00
|
|
|
HRESULT jsdisp_call_value(jsdisp_t *jsfunc, IDispatch *jsthis, WORD flags, unsigned argc, jsval_t *argv, jsval_t *r)
|
2008-09-10 02:33:15 +02:00
|
|
|
{
|
2009-09-23 16:18:39 +02:00
|
|
|
HRESULT hres;
|
|
|
|
|
2016-03-29 17:49:01 +02:00
|
|
|
assert(!(flags & ~(DISPATCH_METHOD|DISPATCH_CONSTRUCT|DISPATCH_JSCRIPT_INTERNAL_MASK)));
|
2015-02-05 14:49:01 +01:00
|
|
|
|
2012-06-21 10:48:10 +02:00
|
|
|
if(is_class(jsfunc, JSCLASS_FUNCTION)) {
|
2012-09-18 19:01:49 +02:00
|
|
|
hres = Function_invoke(jsfunc, jsthis, flags, argc, argv, r);
|
2012-06-21 10:48:10 +02:00
|
|
|
}else {
|
|
|
|
vdisp_t vdisp;
|
|
|
|
|
2021-11-25 21:01:37 +01:00
|
|
|
if(!jsfunc->builtin_info->call) {
|
2015-02-05 14:49:01 +01:00
|
|
|
WARN("Not a function\n");
|
2020-01-31 17:23:33 +01:00
|
|
|
return JS_E_FUNCTION_EXPECTED;
|
2015-02-05 14:49:01 +01:00
|
|
|
}
|
|
|
|
|
2012-06-21 10:48:10 +02:00
|
|
|
set_disp(&vdisp, jsthis);
|
2016-03-29 17:49:01 +02:00
|
|
|
flags &= ~DISPATCH_JSCRIPT_INTERNAL_MASK;
|
2021-11-25 21:01:37 +01:00
|
|
|
hres = jsfunc->builtin_info->call(jsfunc->ctx, &vdisp, flags, argc, argv, r);
|
2012-06-21 10:48:10 +02:00
|
|
|
vdisp_release(&vdisp);
|
|
|
|
}
|
2009-09-23 16:18:39 +02:00
|
|
|
return hres;
|
2008-09-10 02:33:15 +02:00
|
|
|
}
|
|
|
|
|
2012-09-18 19:01:49 +02:00
|
|
|
HRESULT jsdisp_call(jsdisp_t *disp, DISPID id, WORD flags, unsigned argc, jsval_t *argv, jsval_t *r)
|
2008-09-09 01:20:26 +02:00
|
|
|
{
|
|
|
|
dispex_prop_t *prop;
|
|
|
|
|
|
|
|
prop = get_prop(disp, id);
|
|
|
|
if(!prop)
|
|
|
|
return DISP_E_MEMBERNOTFOUND;
|
|
|
|
|
2012-09-18 19:01:49 +02:00
|
|
|
return invoke_prop_func(disp, to_disp(disp), prop, flags, argc, argv, r, NULL);
|
2008-09-09 01:20:26 +02:00
|
|
|
}
|
|
|
|
|
2012-09-18 19:01:49 +02:00
|
|
|
HRESULT jsdisp_call_name(jsdisp_t *disp, const WCHAR *name, WORD flags, unsigned argc, jsval_t *argv, jsval_t *r)
|
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;
|
|
|
|
|
2012-09-18 19:01:49 +02:00
|
|
|
return invoke_prop_func(disp, to_disp(disp), prop, flags, argc, argv, r, NULL);
|
2009-08-12 12:48:58 +02:00
|
|
|
}
|
|
|
|
|
2020-01-30 15:50:06 +01:00
|
|
|
static HRESULT disp_invoke(script_ctx_t *ctx, IDispatch *disp, DISPID id, WORD flags, DISPPARAMS *params, VARIANT *r)
|
2008-09-09 01:20:26 +02:00
|
|
|
{
|
|
|
|
IDispatchEx *dispex;
|
2020-01-30 15:50:06 +01:00
|
|
|
EXCEPINFO ei;
|
|
|
|
HRESULT hres;
|
|
|
|
|
|
|
|
memset(&ei, 0, sizeof(ei));
|
|
|
|
hres = IDispatch_QueryInterface(disp, &IID_IDispatchEx, (void**)&dispex);
|
|
|
|
if(SUCCEEDED(hres)) {
|
|
|
|
hres = IDispatchEx_InvokeEx(dispex, id, ctx->lcid, flags, params, r, &ei, &ctx->jscaller->IServiceProvider_iface);
|
|
|
|
IDispatchEx_Release(dispex);
|
|
|
|
}else {
|
|
|
|
UINT err = 0;
|
|
|
|
|
|
|
|
if(flags == DISPATCH_CONSTRUCT) {
|
|
|
|
WARN("IDispatch cannot be constructor\n");
|
|
|
|
return DISP_E_MEMBERNOTFOUND;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(params->cNamedArgs == 1 && params->rgdispidNamedArgs[0] == DISPID_THIS) {
|
|
|
|
params->cNamedArgs = 0;
|
|
|
|
params->rgdispidNamedArgs = NULL;
|
|
|
|
params->cArgs--;
|
|
|
|
params->rgvarg++;
|
|
|
|
}
|
|
|
|
|
|
|
|
TRACE("using IDispatch\n");
|
|
|
|
hres = IDispatch_Invoke(disp, id, &IID_NULL, ctx->lcid, flags, params, r, &ei, &err);
|
|
|
|
}
|
|
|
|
|
|
|
|
if(hres == DISP_E_EXCEPTION) {
|
2022-02-11 08:41:11 +01:00
|
|
|
TRACE("DISP_E_EXCEPTION: %08lx %s %s\n", ei.scode, debugstr_w(ei.bstrSource), debugstr_w(ei.bstrDescription));
|
2020-02-03 14:47:07 +01:00
|
|
|
reset_ei(ctx->ei);
|
|
|
|
ctx->ei->error = (SUCCEEDED(ei.scode) || ei.scode == DISP_E_EXCEPTION) ? E_FAIL : ei.scode;
|
2020-02-03 14:47:15 +01:00
|
|
|
if(ei.bstrSource)
|
|
|
|
ctx->ei->source = jsstr_alloc_len(ei.bstrSource, SysStringLen(ei.bstrSource));
|
2020-02-03 14:47:25 +01:00
|
|
|
if(ei.bstrDescription)
|
|
|
|
ctx->ei->message = jsstr_alloc_len(ei.bstrDescription, SysStringLen(ei.bstrDescription));
|
2020-01-30 15:50:06 +01:00
|
|
|
SysFreeString(ei.bstrSource);
|
|
|
|
SysFreeString(ei.bstrDescription);
|
|
|
|
SysFreeString(ei.bstrHelpFile);
|
|
|
|
}
|
|
|
|
|
|
|
|
return hres;
|
|
|
|
}
|
|
|
|
|
|
|
|
HRESULT disp_call(script_ctx_t *ctx, IDispatch *disp, DISPID id, WORD flags, unsigned argc, jsval_t *argv, jsval_t *ret)
|
|
|
|
{
|
2012-09-17 15:17:02 +02:00
|
|
|
VARIANT buf[6], retv;
|
2020-01-30 15:50:06 +01:00
|
|
|
jsdisp_t *jsdisp;
|
2012-06-25 14:08:38 +02:00
|
|
|
DISPPARAMS dp;
|
|
|
|
unsigned i;
|
2008-09-09 01:20:26 +02:00
|
|
|
HRESULT hres;
|
|
|
|
|
2016-07-20 13:40:41 +02:00
|
|
|
jsdisp = iface_to_jsdisp(disp);
|
2020-01-30 15:49:53 +01:00
|
|
|
if(jsdisp && jsdisp->ctx == ctx) {
|
2012-04-17 16:25:58 +02:00
|
|
|
if(flags & DISPATCH_PROPERTYPUT) {
|
|
|
|
FIXME("disp_call(propput) on builtin object\n");
|
2021-10-25 15:30:25 +02:00
|
|
|
jsdisp_release(jsdisp);
|
2012-04-17 16:25:58 +02:00
|
|
|
return E_FAIL;
|
|
|
|
}
|
|
|
|
|
2017-12-12 15:27:51 +01:00
|
|
|
if(ctx != jsdisp->ctx)
|
|
|
|
flags &= ~DISPATCH_JSCRIPT_INTERNAL_MASK;
|
2012-09-18 19:01:49 +02:00
|
|
|
hres = jsdisp_call(jsdisp, id, flags, argc, argv, ret);
|
2009-09-01 13:26:08 +02:00
|
|
|
jsdisp_release(jsdisp);
|
2008-09-09 01:20:26 +02:00
|
|
|
return hres;
|
|
|
|
}
|
2021-10-25 15:30:25 +02:00
|
|
|
if(jsdisp)
|
|
|
|
jsdisp_release(jsdisp);
|
2008-09-09 01:20:26 +02:00
|
|
|
|
2016-03-29 17:49:01 +02:00
|
|
|
flags &= ~DISPATCH_JSCRIPT_INTERNAL_MASK;
|
2012-09-17 15:17:02 +02:00
|
|
|
if(ret && argc)
|
2010-10-19 23:14:16 +02:00
|
|
|
flags |= DISPATCH_PROPERTYGET;
|
2008-09-09 01:20:26 +02:00
|
|
|
|
2012-06-25 14:08:38 +02:00
|
|
|
dp.cArgs = argc;
|
|
|
|
|
|
|
|
if(flags & DISPATCH_PROPERTYPUT) {
|
|
|
|
static DISPID propput_dispid = DISPID_PROPERTYPUT;
|
|
|
|
|
|
|
|
dp.cNamedArgs = 1;
|
|
|
|
dp.rgdispidNamedArgs = &propput_dispid;
|
|
|
|
}else {
|
|
|
|
dp.cNamedArgs = 0;
|
|
|
|
dp.rgdispidNamedArgs = NULL;
|
|
|
|
}
|
|
|
|
|
2020-01-30 15:50:06 +01:00
|
|
|
if(dp.cArgs > ARRAY_SIZE(buf)) {
|
2012-06-25 14:08:38 +02:00
|
|
|
dp.rgvarg = heap_alloc(argc*sizeof(VARIANT));
|
|
|
|
if(!dp.rgvarg)
|
|
|
|
return E_OUTOFMEMORY;
|
|
|
|
}else {
|
|
|
|
dp.rgvarg = buf;
|
|
|
|
}
|
|
|
|
|
2012-09-17 15:16:42 +02:00
|
|
|
for(i=0; i<argc; i++) {
|
|
|
|
hres = jsval_to_variant(argv[i], dp.rgvarg+argc-i-1);
|
|
|
|
if(FAILED(hres)) {
|
|
|
|
while(i--)
|
|
|
|
VariantClear(dp.rgvarg+argc-i-1);
|
|
|
|
if(dp.rgvarg != buf)
|
|
|
|
heap_free(dp.rgvarg);
|
|
|
|
return hres;
|
|
|
|
}
|
|
|
|
}
|
2012-06-25 14:08:38 +02:00
|
|
|
|
2012-09-17 15:17:02 +02:00
|
|
|
V_VT(&retv) = VT_EMPTY;
|
2020-01-30 15:50:06 +01:00
|
|
|
hres = disp_invoke(ctx, disp, id, flags, &dp, ret ? &retv : NULL);
|
2008-09-09 01:20:26 +02:00
|
|
|
|
2012-09-17 15:16:42 +02:00
|
|
|
for(i=0; i<argc; i++)
|
|
|
|
VariantClear(dp.rgvarg+argc-i-1);
|
2012-06-25 14:08:38 +02:00
|
|
|
if(dp.rgvarg != buf)
|
|
|
|
heap_free(dp.rgvarg);
|
2008-09-09 01:20:26 +02:00
|
|
|
|
2020-01-30 15:50:06 +01:00
|
|
|
if(SUCCEEDED(hres) && ret)
|
2012-09-17 15:17:02 +02:00
|
|
|
hres = variant_to_jsval(&retv, ret);
|
2020-01-30 15:50:06 +01:00
|
|
|
VariantClear(&retv);
|
2012-09-17 15:17:02 +02:00
|
|
|
return hres;
|
2008-09-09 01:23:21 +02:00
|
|
|
}
|
|
|
|
|
2012-09-17 15:16:42 +02:00
|
|
|
HRESULT disp_call_value(script_ctx_t *ctx, IDispatch *disp, IDispatch *jsthis, WORD flags, unsigned argc, jsval_t *argv,
|
2012-09-18 19:01:49 +02:00
|
|
|
jsval_t *r)
|
2012-06-21 10:48:10 +02:00
|
|
|
{
|
2020-01-30 15:50:06 +01:00
|
|
|
VARIANT buf[6], retv, *args = buf;
|
2012-06-21 10:48:10 +02:00
|
|
|
jsdisp_t *jsdisp;
|
2012-06-25 14:08:38 +02:00
|
|
|
DISPPARAMS dp;
|
|
|
|
unsigned i;
|
2020-01-30 15:50:06 +01:00
|
|
|
HRESULT hres = S_OK;
|
|
|
|
|
|
|
|
static DISPID this_id = DISPID_THIS;
|
2012-06-21 10:48:10 +02:00
|
|
|
|
2016-03-29 17:49:01 +02:00
|
|
|
assert(!(flags & ~(DISPATCH_METHOD|DISPATCH_CONSTRUCT|DISPATCH_JSCRIPT_INTERNAL_MASK)));
|
2015-02-05 14:49:01 +01:00
|
|
|
|
2016-07-20 13:40:41 +02:00
|
|
|
jsdisp = iface_to_jsdisp(disp);
|
2020-01-30 15:49:53 +01:00
|
|
|
if(jsdisp && jsdisp->ctx == ctx) {
|
2012-09-18 19:01:49 +02:00
|
|
|
hres = jsdisp_call_value(jsdisp, jsthis, flags, argc, argv, r);
|
2012-06-21 10:48:10 +02:00
|
|
|
jsdisp_release(jsdisp);
|
|
|
|
return hres;
|
|
|
|
}
|
2021-10-25 15:30:25 +02:00
|
|
|
if(jsdisp)
|
|
|
|
jsdisp_release(jsdisp);
|
2012-06-21 10:48:10 +02:00
|
|
|
|
2016-03-29 17:49:01 +02:00
|
|
|
flags &= ~DISPATCH_JSCRIPT_INTERNAL_MASK;
|
2014-09-16 20:42:33 +02:00
|
|
|
if(r && argc && flags == DISPATCH_METHOD)
|
2012-06-21 10:48:10 +02:00
|
|
|
flags |= DISPATCH_PROPERTYGET;
|
|
|
|
|
|
|
|
if(jsthis) {
|
2020-01-30 15:50:06 +01:00
|
|
|
dp.cArgs = argc + 1;
|
2012-06-25 14:08:38 +02:00
|
|
|
dp.cNamedArgs = 1;
|
|
|
|
dp.rgdispidNamedArgs = &this_id;
|
|
|
|
}else {
|
|
|
|
dp.cArgs = argc;
|
|
|
|
dp.cNamedArgs = 0;
|
|
|
|
dp.rgdispidNamedArgs = NULL;
|
|
|
|
}
|
|
|
|
|
2020-07-23 06:58:37 +02:00
|
|
|
if(dp.cArgs > ARRAY_SIZE(buf) && !(args = heap_alloc(dp.cArgs * sizeof(VARIANT))))
|
2020-01-30 15:50:06 +01:00
|
|
|
return E_OUTOFMEMORY;
|
|
|
|
dp.rgvarg = args;
|
2012-06-21 10:48:10 +02:00
|
|
|
|
2020-07-23 06:58:37 +02:00
|
|
|
if(jsthis) {
|
|
|
|
V_VT(dp.rgvarg) = VT_DISPATCH;
|
|
|
|
V_DISPATCH(dp.rgvarg) = jsthis;
|
|
|
|
}
|
2012-06-21 10:48:10 +02:00
|
|
|
|
2020-01-30 15:50:06 +01:00
|
|
|
for(i=0; SUCCEEDED(hres) && i < argc; i++)
|
|
|
|
hres = jsval_to_variant(argv[i], dp.rgvarg+dp.cArgs-i-1);
|
2012-06-21 10:48:10 +02:00
|
|
|
|
2020-01-30 15:50:06 +01:00
|
|
|
if(SUCCEEDED(hres)) {
|
|
|
|
V_VT(&retv) = VT_EMPTY;
|
|
|
|
hres = disp_invoke(ctx, disp, DISPID_VALUE, flags, &dp, r ? &retv : NULL);
|
2012-06-21 10:48:10 +02:00
|
|
|
}
|
|
|
|
|
2020-07-23 06:58:37 +02:00
|
|
|
for(i = 0; i < argc; i++)
|
2020-01-30 15:50:06 +01:00
|
|
|
VariantClear(dp.rgvarg + dp.cArgs - i - 1);
|
|
|
|
if(args != buf)
|
|
|
|
heap_free(args);
|
2012-06-21 10:48:10 +02:00
|
|
|
|
2021-09-20 16:46:07 +02:00
|
|
|
if(FAILED(hres))
|
|
|
|
return hres;
|
2012-09-17 15:16:20 +02:00
|
|
|
if(!r)
|
|
|
|
return S_OK;
|
|
|
|
|
|
|
|
hres = variant_to_jsval(&retv, r);
|
|
|
|
VariantClear(&retv);
|
|
|
|
return hres;
|
2012-06-21 10:48:10 +02:00
|
|
|
}
|
|
|
|
|
2021-04-02 20:24:18 +02:00
|
|
|
HRESULT jsdisp_propput(jsdisp_t *obj, const WCHAR *name, DWORD flags, BOOL throw, jsval_t val)
|
2008-09-09 01:25:59 +02:00
|
|
|
{
|
|
|
|
dispex_prop_t *prop;
|
|
|
|
HRESULT hres;
|
|
|
|
|
2021-04-01 18:18:40 +02:00
|
|
|
if(obj->extensible)
|
|
|
|
hres = ensure_prop_name(obj, name, flags, &prop);
|
|
|
|
else
|
2021-04-02 20:24:18 +02:00
|
|
|
hres = find_prop_name(obj, string_hash(name), name, &prop);
|
|
|
|
if(FAILED(hres))
|
2008-09-09 01:25:59 +02:00
|
|
|
return hres;
|
2021-04-02 20:24:18 +02:00
|
|
|
if(!prop || (prop->type == PROP_DELETED && !obj->extensible))
|
|
|
|
return throw ? JS_E_INVALID_ACTION : S_OK;
|
2008-09-09 01:25:59 +02:00
|
|
|
|
2018-04-20 18:33:16 +02:00
|
|
|
return prop_put(obj, prop, val);
|
2008-09-09 01:25:59 +02:00
|
|
|
}
|
|
|
|
|
2012-11-30 13:02:32 +01:00
|
|
|
HRESULT jsdisp_propput_name(jsdisp_t *obj, const WCHAR *name, jsval_t val)
|
|
|
|
{
|
2021-04-02 20:24:18 +02:00
|
|
|
return jsdisp_propput(obj, name, PROPF_ENUMERABLE | PROPF_CONFIGURABLE | PROPF_WRITABLE, FALSE, val);
|
2012-11-30 13:02:32 +01:00
|
|
|
}
|
|
|
|
|
2012-09-18 19:01:49 +02:00
|
|
|
HRESULT jsdisp_propput_idx(jsdisp_t *obj, DWORD idx, jsval_t val)
|
2008-09-10 21:06:43 +02:00
|
|
|
{
|
|
|
|
WCHAR buf[12];
|
|
|
|
|
2020-11-24 00:49:04 +01:00
|
|
|
swprintf(buf, ARRAY_SIZE(buf), L"%d", idx);
|
2021-04-02 20:24:18 +02:00
|
|
|
return jsdisp_propput(obj, buf, PROPF_ENUMERABLE | PROPF_CONFIGURABLE | PROPF_WRITABLE, TRUE, val);
|
2008-09-10 21:06:43 +02:00
|
|
|
}
|
|
|
|
|
2012-09-18 19:01:49 +02:00
|
|
|
HRESULT disp_propput(script_ctx_t *ctx, IDispatch *disp, DISPID id, jsval_t val)
|
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;
|
|
|
|
|
2016-07-20 13:40:41 +02:00
|
|
|
jsdisp = iface_to_jsdisp(disp);
|
2020-01-30 15:49:53 +01:00
|
|
|
if(jsdisp && jsdisp->ctx == ctx) {
|
2008-09-09 01:23:21 +02:00
|
|
|
dispex_prop_t *prop;
|
|
|
|
|
|
|
|
prop = get_prop(jsdisp, id);
|
|
|
|
if(prop)
|
2018-04-20 18:33:16 +02:00
|
|
|
hres = prop_put(jsdisp, prop, val);
|
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;
|
2014-11-28 16:18:32 +01:00
|
|
|
DWORD flags = DISPATCH_PROPERTYPUT;
|
2012-09-17 15:17:02 +02:00
|
|
|
VARIANT var;
|
|
|
|
DISPPARAMS dp = {&var, &dispid, 1, 1};
|
2010-02-05 23:15:46 +01:00
|
|
|
|
2021-10-25 15:30:25 +02:00
|
|
|
if(jsdisp)
|
|
|
|
jsdisp_release(jsdisp);
|
2012-09-17 15:17:02 +02:00
|
|
|
hres = jsval_to_variant(val, &var);
|
|
|
|
if(FAILED(hres))
|
|
|
|
return hres;
|
|
|
|
|
2014-11-28 16:18:32 +01:00
|
|
|
if(V_VT(&var) == VT_DISPATCH)
|
|
|
|
flags |= DISPATCH_PROPERTYPUTREF;
|
|
|
|
|
2020-01-30 15:50:06 +01:00
|
|
|
hres = disp_invoke(ctx, disp, id, flags, &dp, NULL);
|
2012-09-17 15:17:02 +02:00
|
|
|
VariantClear(&var);
|
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
|
|
|
|
2021-04-01 18:18:31 +02:00
|
|
|
HRESULT disp_propput_name(script_ctx_t *ctx, IDispatch *disp, const WCHAR *name, jsval_t val)
|
|
|
|
{
|
|
|
|
jsdisp_t *jsdisp;
|
|
|
|
HRESULT hres;
|
|
|
|
|
|
|
|
jsdisp = iface_to_jsdisp(disp);
|
|
|
|
if(!jsdisp || jsdisp->ctx != ctx) {
|
|
|
|
IDispatchEx *dispex;
|
|
|
|
BSTR str;
|
|
|
|
DISPID id;
|
|
|
|
|
2021-10-25 15:30:25 +02:00
|
|
|
if(jsdisp)
|
|
|
|
jsdisp_release(jsdisp);
|
2021-04-01 18:18:31 +02:00
|
|
|
if(!(str = SysAllocString(name)))
|
|
|
|
return E_OUTOFMEMORY;
|
|
|
|
|
|
|
|
hres = IDispatch_QueryInterface(disp, &IID_IDispatchEx, (void**)&dispex);
|
|
|
|
if(SUCCEEDED(hres)) {
|
|
|
|
hres = IDispatchEx_GetDispID(dispex, str, make_grfdex(ctx, fdexNameEnsure|fdexNameCaseSensitive), &id);
|
|
|
|
IDispatchEx_Release(dispex);
|
|
|
|
}else {
|
|
|
|
TRACE("using IDispatch\n");
|
|
|
|
hres = IDispatch_GetIDsOfNames(disp, &IID_NULL, &str, 1, 0, &id);
|
|
|
|
}
|
|
|
|
SysFreeString(str);
|
|
|
|
if(FAILED(hres))
|
|
|
|
return hres;
|
|
|
|
|
|
|
|
return disp_propput(ctx, disp, id, val);
|
|
|
|
}
|
|
|
|
|
2021-10-25 15:30:25 +02:00
|
|
|
hres = jsdisp_propput_name(jsdisp, name, val);
|
|
|
|
jsdisp_release(jsdisp);
|
|
|
|
return hres;
|
2021-04-01 18:18:31 +02:00
|
|
|
}
|
|
|
|
|
2012-09-18 19:01:49 +02:00
|
|
|
HRESULT jsdisp_propget_name(jsdisp_t *obj, const WCHAR *name, jsval_t *val)
|
2008-09-21 15:36:26 +02:00
|
|
|
{
|
|
|
|
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;
|
|
|
|
|
2012-09-17 15:16:42 +02:00
|
|
|
if(!prop || prop->type==PROP_DELETED) {
|
|
|
|
*val = jsval_undefined();
|
2008-09-21 15:36:26 +02:00
|
|
|
return S_OK;
|
2012-09-17 15:16:42 +02:00
|
|
|
}
|
2008-09-21 15:36:26 +02:00
|
|
|
|
2018-04-20 18:33:09 +02:00
|
|
|
return prop_get(obj, prop, val);
|
2008-09-21 15:36:26 +02:00
|
|
|
}
|
|
|
|
|
2012-09-18 19:01:49 +02:00
|
|
|
HRESULT jsdisp_get_idx(jsdisp_t *obj, DWORD idx, jsval_t *r)
|
2008-09-21 15:36:26 +02:00
|
|
|
{
|
2010-01-25 03:49:49 +01:00
|
|
|
WCHAR name[12];
|
|
|
|
dispex_prop_t *prop;
|
|
|
|
HRESULT hres;
|
2008-09-21 15:36:26 +02:00
|
|
|
|
2020-11-24 00:49:04 +01:00
|
|
|
swprintf(name, ARRAY_SIZE(name), L"%d", idx);
|
2010-01-25 03:49:49 +01:00
|
|
|
|
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;
|
|
|
|
|
2012-09-17 15:16:42 +02:00
|
|
|
if(!prop || prop->type==PROP_DELETED) {
|
|
|
|
*r = jsval_undefined();
|
2010-01-25 03:49:49 +01:00
|
|
|
return DISP_E_UNKNOWNNAME;
|
2012-09-17 15:16:42 +02:00
|
|
|
}
|
2010-01-25 03:49:49 +01:00
|
|
|
|
2018-04-20 18:33:09 +02:00
|
|
|
return prop_get(obj, prop, r);
|
2008-09-21 15:36:26 +02:00
|
|
|
}
|
|
|
|
|
2012-09-18 19:01:49 +02:00
|
|
|
HRESULT jsdisp_propget(jsdisp_t *jsdisp, DISPID id, jsval_t *val)
|
2008-10-07 19:01:39 +02:00
|
|
|
{
|
|
|
|
dispex_prop_t *prop;
|
|
|
|
|
|
|
|
prop = get_prop(jsdisp, id);
|
|
|
|
if(!prop)
|
|
|
|
return DISP_E_MEMBERNOTFOUND;
|
|
|
|
|
2018-04-20 18:33:09 +02:00
|
|
|
return prop_get(jsdisp, prop, val);
|
2008-10-07 19:01:39 +02:00
|
|
|
}
|
|
|
|
|
2012-09-18 19:01:49 +02:00
|
|
|
HRESULT disp_propget(script_ctx_t *ctx, IDispatch *disp, DISPID id, jsval_t *val)
|
2008-09-09 01:21:55 +02:00
|
|
|
{
|
|
|
|
DISPPARAMS dp = {NULL,NULL,0,0};
|
2010-09-06 16:11:49 +02:00
|
|
|
jsdisp_t *jsdisp;
|
2012-09-17 15:17:02 +02:00
|
|
|
VARIANT var;
|
2008-09-09 01:21:55 +02:00
|
|
|
HRESULT hres;
|
|
|
|
|
2016-07-20 13:40:41 +02:00
|
|
|
jsdisp = iface_to_jsdisp(disp);
|
2020-01-30 15:49:53 +01:00
|
|
|
if(jsdisp && jsdisp->ctx == ctx) {
|
2012-09-18 19:01:49 +02:00
|
|
|
hres = jsdisp_propget(jsdisp, id, val);
|
2009-09-01 13:26:08 +02:00
|
|
|
jsdisp_release(jsdisp);
|
2008-09-09 01:21:55 +02:00
|
|
|
return hres;
|
|
|
|
}
|
2021-10-25 15:30:25 +02:00
|
|
|
if(jsdisp)
|
|
|
|
jsdisp_release(jsdisp);
|
2008-09-09 01:21:55 +02:00
|
|
|
|
2012-09-17 15:17:02 +02:00
|
|
|
V_VT(&var) = VT_EMPTY;
|
2020-01-30 15:50:06 +01:00
|
|
|
hres = disp_invoke(ctx, disp, id, INVOKE_PROPERTYGET, &dp, &var);
|
2012-05-01 15:04:37 +02:00
|
|
|
if(SUCCEEDED(hres)) {
|
2020-01-30 15:50:06 +01:00
|
|
|
hres = variant_to_jsval(&var, val);
|
|
|
|
VariantClear(&var);
|
2008-09-09 01:21:55 +02:00
|
|
|
}
|
2012-11-09 11:48:34 +01:00
|
|
|
return hres;
|
2008-09-09 01:21:55 +02:00
|
|
|
}
|
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
|
|
|
{
|
|
|
|
WCHAR buf[12];
|
|
|
|
dispex_prop_t *prop;
|
2012-11-30 13:02:32 +01:00
|
|
|
BOOL b;
|
2009-07-14 02:06:59 +02:00
|
|
|
HRESULT hres;
|
|
|
|
|
2020-11-24 00:49:04 +01:00
|
|
|
swprintf(buf, ARRAY_SIZE(buf), L"%d", idx);
|
2009-07-14 02:06:59 +02:00
|
|
|
|
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;
|
|
|
|
|
2021-04-02 20:24:30 +02:00
|
|
|
hres = delete_prop(prop, &b);
|
|
|
|
if(FAILED(hres))
|
|
|
|
return hres;
|
|
|
|
return b ? S_OK : JS_E_INVALID_ACTION;
|
2009-07-14 02:06:59 +02:00
|
|
|
}
|
2011-09-02 12:24:12 +02:00
|
|
|
|
2012-11-30 13:02:05 +01:00
|
|
|
HRESULT disp_delete(IDispatch *disp, DISPID id, BOOL *ret)
|
|
|
|
{
|
|
|
|
IDispatchEx *dispex;
|
|
|
|
jsdisp_t *jsdisp;
|
|
|
|
HRESULT hres;
|
|
|
|
|
2016-07-20 13:40:41 +02:00
|
|
|
jsdisp = iface_to_jsdisp(disp);
|
2012-11-30 13:02:05 +01:00
|
|
|
if(jsdisp) {
|
|
|
|
dispex_prop_t *prop;
|
|
|
|
|
|
|
|
prop = get_prop(jsdisp, id);
|
|
|
|
if(prop)
|
2012-11-30 13:02:32 +01:00
|
|
|
hres = delete_prop(prop, ret);
|
2012-11-30 13:02:05 +01:00
|
|
|
else
|
|
|
|
hres = DISP_E_MEMBERNOTFOUND;
|
|
|
|
|
|
|
|
jsdisp_release(jsdisp);
|
|
|
|
return hres;
|
|
|
|
}
|
|
|
|
|
|
|
|
hres = IDispatch_QueryInterface(disp, &IID_IDispatchEx, (void**)&dispex);
|
|
|
|
if(FAILED(hres)) {
|
|
|
|
*ret = FALSE;
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
hres = IDispatchEx_DeleteMemberByDispID(dispex, id);
|
|
|
|
IDispatchEx_Release(dispex);
|
|
|
|
if(FAILED(hres))
|
|
|
|
return hres;
|
|
|
|
|
2012-12-17 13:36:55 +01:00
|
|
|
*ret = hres == S_OK;
|
2012-11-30 13:02:05 +01:00
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
2021-04-20 19:11:56 +02:00
|
|
|
HRESULT jsdisp_next_prop(jsdisp_t *obj, DISPID id, enum jsdisp_enum_type enum_type, DISPID *ret)
|
2019-08-21 12:31:08 +02:00
|
|
|
{
|
|
|
|
dispex_prop_t *iter;
|
2021-11-25 21:01:28 +01:00
|
|
|
DWORD idx = id;
|
2019-08-21 12:31:08 +02:00
|
|
|
HRESULT hres;
|
|
|
|
|
2021-11-25 21:01:28 +01:00
|
|
|
if(id == DISPID_STARTENUM) {
|
|
|
|
if (enum_type == JSDISP_ENUM_ALL) {
|
|
|
|
hres = fill_protrefs(obj);
|
|
|
|
if(FAILED(hres))
|
|
|
|
return hres;
|
|
|
|
}
|
|
|
|
idx = 0;
|
2019-08-21 12:31:08 +02:00
|
|
|
}
|
|
|
|
|
2021-11-25 21:01:28 +01:00
|
|
|
if(idx >= obj->prop_cnt)
|
2019-08-21 12:31:08 +02:00
|
|
|
return S_FALSE;
|
|
|
|
|
2021-11-25 21:01:28 +01:00
|
|
|
for(iter = &obj->props[idx]; iter < obj->props + obj->prop_cnt; iter++) {
|
|
|
|
if(iter->type == PROP_DELETED)
|
2019-08-21 12:31:08 +02:00
|
|
|
continue;
|
2021-04-20 19:11:56 +02:00
|
|
|
if(enum_type != JSDISP_ENUM_ALL && iter->type == PROP_PROTREF)
|
2019-08-21 12:31:08 +02:00
|
|
|
continue;
|
2021-04-20 19:12:07 +02:00
|
|
|
if(enum_type != JSDISP_ENUM_OWN && !(get_flags(obj, iter) & PROPF_ENUMERABLE))
|
2019-08-21 12:31:08 +02:00
|
|
|
continue;
|
|
|
|
*ret = prop_to_id(obj, iter);
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
return S_FALSE;
|
|
|
|
}
|
|
|
|
|
2012-11-30 13:02:19 +01:00
|
|
|
HRESULT disp_delete_name(script_ctx_t *ctx, IDispatch *disp, jsstr_t *name, BOOL *ret)
|
|
|
|
{
|
|
|
|
IDispatchEx *dispex;
|
|
|
|
jsdisp_t *jsdisp;
|
2013-03-11 16:02:58 +01:00
|
|
|
BSTR bstr;
|
2012-11-30 13:02:19 +01:00
|
|
|
HRESULT hres;
|
|
|
|
|
2016-07-20 13:40:41 +02:00
|
|
|
jsdisp = iface_to_jsdisp(disp);
|
2012-11-30 13:02:19 +01:00
|
|
|
if(jsdisp) {
|
|
|
|
dispex_prop_t *prop;
|
2013-03-26 10:37:31 +01:00
|
|
|
const WCHAR *ptr;
|
|
|
|
|
|
|
|
ptr = jsstr_flatten(name);
|
|
|
|
if(!ptr) {
|
|
|
|
jsdisp_release(jsdisp);
|
|
|
|
return E_OUTOFMEMORY;
|
|
|
|
}
|
2012-11-30 13:02:19 +01:00
|
|
|
|
2013-03-26 10:37:31 +01:00
|
|
|
hres = find_prop_name(jsdisp, string_hash(ptr), ptr, &prop);
|
2012-12-17 13:36:08 +01:00
|
|
|
if(prop) {
|
2012-11-30 13:02:32 +01:00
|
|
|
hres = delete_prop(prop, ret);
|
2012-12-17 13:36:08 +01:00
|
|
|
}else {
|
|
|
|
*ret = TRUE;
|
|
|
|
hres = S_OK;
|
|
|
|
}
|
2012-11-30 13:02:19 +01:00
|
|
|
|
|
|
|
jsdisp_release(jsdisp);
|
|
|
|
return hres;
|
|
|
|
}
|
|
|
|
|
2013-03-11 16:02:58 +01:00
|
|
|
bstr = SysAllocStringLen(NULL, jsstr_length(name));
|
|
|
|
if(!bstr)
|
|
|
|
return E_OUTOFMEMORY;
|
|
|
|
jsstr_flush(name, bstr);
|
|
|
|
|
2012-11-30 13:02:19 +01:00
|
|
|
hres = IDispatch_QueryInterface(disp, &IID_IDispatchEx, (void**)&dispex);
|
|
|
|
if(SUCCEEDED(hres)) {
|
2013-03-11 16:02:58 +01:00
|
|
|
hres = IDispatchEx_DeleteMemberByName(dispex, bstr, make_grfdex(ctx, fdexNameCaseSensitive));
|
|
|
|
if(SUCCEEDED(hres))
|
|
|
|
*ret = hres == S_OK;
|
2012-11-30 13:02:19 +01:00
|
|
|
IDispatchEx_Release(dispex);
|
|
|
|
}else {
|
2012-12-17 13:36:31 +01:00
|
|
|
DISPID id;
|
|
|
|
|
2013-03-11 16:02:58 +01:00
|
|
|
hres = IDispatch_GetIDsOfNames(disp, &IID_NULL, &bstr, 1, 0, &id);
|
2012-12-17 13:36:31 +01:00
|
|
|
if(SUCCEEDED(hres)) {
|
|
|
|
/* Property exists and we can't delete it from pure IDispatch interface, so return false. */
|
|
|
|
*ret = FALSE;
|
|
|
|
}else if(hres == DISP_E_UNKNOWNNAME) {
|
|
|
|
/* Property doesn't exist, so nothing to delete */
|
|
|
|
*ret = TRUE;
|
|
|
|
hres = S_OK;
|
|
|
|
}
|
2012-11-30 13:02:19 +01:00
|
|
|
}
|
|
|
|
|
2013-03-11 16:02:58 +01:00
|
|
|
SysFreeString(bstr);
|
2012-11-30 13:02:19 +01:00
|
|
|
return hres;
|
|
|
|
}
|
|
|
|
|
2018-05-10 19:19:56 +02:00
|
|
|
HRESULT jsdisp_get_own_property(jsdisp_t *obj, const WCHAR *name, BOOL flags_only,
|
|
|
|
property_desc_t *desc)
|
|
|
|
{
|
|
|
|
dispex_prop_t *prop;
|
|
|
|
HRESULT hres;
|
|
|
|
|
|
|
|
hres = find_prop_name(obj, string_hash(name), name, &prop);
|
|
|
|
if(FAILED(hres))
|
|
|
|
return hres;
|
|
|
|
|
|
|
|
if(!prop)
|
|
|
|
return DISP_E_UNKNOWNNAME;
|
|
|
|
|
|
|
|
memset(desc, 0, sizeof(*desc));
|
|
|
|
|
|
|
|
switch(prop->type) {
|
|
|
|
case PROP_BUILTIN:
|
|
|
|
case PROP_JSVAL:
|
2018-05-11 14:43:20 +02:00
|
|
|
desc->mask |= PROPF_WRITABLE;
|
|
|
|
desc->explicit_value = TRUE;
|
2018-05-10 19:19:56 +02:00
|
|
|
if(!flags_only) {
|
|
|
|
hres = prop_get(obj, prop, &desc->value);
|
|
|
|
if(FAILED(hres))
|
|
|
|
return hres;
|
|
|
|
}
|
|
|
|
break;
|
2018-05-15 13:26:10 +02:00
|
|
|
case PROP_ACCESSOR:
|
|
|
|
desc->explicit_getter = desc->explicit_setter = TRUE;
|
|
|
|
if(!flags_only) {
|
|
|
|
desc->getter = prop->u.accessor.getter
|
|
|
|
? jsdisp_addref(prop->u.accessor.getter) : NULL;
|
|
|
|
desc->setter = prop->u.accessor.setter
|
|
|
|
? jsdisp_addref(prop->u.accessor.setter) : NULL;
|
|
|
|
}
|
|
|
|
break;
|
2018-05-10 19:19:56 +02:00
|
|
|
default:
|
|
|
|
return DISP_E_UNKNOWNNAME;
|
|
|
|
}
|
|
|
|
|
|
|
|
desc->flags = prop->flags & (PROPF_ENUMERABLE | PROPF_WRITABLE | PROPF_CONFIGURABLE);
|
2018-05-11 14:43:20 +02:00
|
|
|
desc->mask |= PROPF_ENUMERABLE | PROPF_CONFIGURABLE;
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
HRESULT jsdisp_define_property(jsdisp_t *obj, const WCHAR *name, property_desc_t *desc)
|
|
|
|
{
|
|
|
|
dispex_prop_t *prop;
|
|
|
|
HRESULT hres;
|
|
|
|
|
|
|
|
hres = find_prop_name(obj, string_hash(name), name, &prop);
|
|
|
|
if(FAILED(hres))
|
|
|
|
return hres;
|
|
|
|
|
2021-11-24 15:10:32 +01:00
|
|
|
if((!prop || prop->type == PROP_DELETED || prop->type == PROP_PROTREF) && !obj->extensible)
|
2021-04-01 18:18:58 +02:00
|
|
|
return throw_error(obj->ctx, JS_E_OBJECT_NONEXTENSIBLE, name);
|
|
|
|
|
2018-05-11 14:43:20 +02:00
|
|
|
if(!prop && !(prop = alloc_prop(obj, name, PROP_DELETED, 0)))
|
|
|
|
return E_OUTOFMEMORY;
|
|
|
|
|
|
|
|
if(prop->type == PROP_DELETED || prop->type == PROP_PROTREF) {
|
|
|
|
prop->flags = desc->flags;
|
|
|
|
if(desc->explicit_getter || desc->explicit_setter) {
|
2018-05-14 13:34:26 +02:00
|
|
|
prop->type = PROP_ACCESSOR;
|
|
|
|
prop->u.accessor.getter = desc->getter ? jsdisp_addref(desc->getter) : NULL;
|
|
|
|
prop->u.accessor.setter = desc->setter ? jsdisp_addref(desc->setter) : NULL;
|
|
|
|
TRACE("%s = accessor { get: %p set: %p }\n", debugstr_w(name),
|
|
|
|
prop->u.accessor.getter, prop->u.accessor.setter);
|
2018-05-11 14:43:20 +02:00
|
|
|
}else {
|
|
|
|
prop->type = PROP_JSVAL;
|
|
|
|
if(desc->explicit_value) {
|
|
|
|
hres = jsval_copy(desc->value, &prop->u.val);
|
|
|
|
if(FAILED(hres))
|
|
|
|
return hres;
|
|
|
|
}else {
|
|
|
|
prop->u.val = jsval_undefined();
|
|
|
|
}
|
|
|
|
TRACE("%s = %s\n", debugstr_w(name), debugstr_jsval(prop->u.val));
|
|
|
|
}
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
2022-02-11 08:41:11 +01:00
|
|
|
TRACE("existing prop %s prop flags %lx desc flags %x desc mask %x\n", debugstr_w(name),
|
2018-05-11 14:43:20 +02:00
|
|
|
prop->flags, desc->flags, desc->mask);
|
|
|
|
|
|
|
|
if(!(prop->flags & PROPF_CONFIGURABLE)) {
|
|
|
|
if(((desc->mask & PROPF_CONFIGURABLE) && (desc->flags & PROPF_CONFIGURABLE))
|
|
|
|
|| ((desc->mask & PROPF_ENUMERABLE)
|
|
|
|
&& ((desc->flags & PROPF_ENUMERABLE) != (prop->flags & PROPF_ENUMERABLE))))
|
2020-02-03 14:47:32 +01:00
|
|
|
return throw_error(obj->ctx, JS_E_NONCONFIGURABLE_REDEFINED, name);
|
2018-05-11 14:43:20 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if(desc->explicit_value || (desc->mask & PROPF_WRITABLE)) {
|
2018-05-14 13:34:26 +02:00
|
|
|
if(prop->type == PROP_ACCESSOR) {
|
|
|
|
if(!(prop->flags & PROPF_CONFIGURABLE))
|
2020-02-03 14:47:32 +01:00
|
|
|
return throw_error(obj->ctx, JS_E_NONCONFIGURABLE_REDEFINED, name);
|
2018-05-14 13:34:26 +02:00
|
|
|
if(prop->u.accessor.getter)
|
|
|
|
jsdisp_release(prop->u.accessor.getter);
|
|
|
|
if(prop->u.accessor.setter)
|
|
|
|
jsdisp_release(prop->u.accessor.setter);
|
|
|
|
|
|
|
|
prop->type = PROP_JSVAL;
|
|
|
|
hres = jsval_copy(desc->value, &prop->u.val);
|
|
|
|
if(FAILED(hres)) {
|
|
|
|
prop->u.val = jsval_undefined();
|
|
|
|
return hres;
|
|
|
|
}
|
|
|
|
}else {
|
|
|
|
if(!(prop->flags & PROPF_CONFIGURABLE) && !(prop->flags & PROPF_WRITABLE)) {
|
|
|
|
if((desc->mask & PROPF_WRITABLE) && (desc->flags & PROPF_WRITABLE))
|
2020-02-03 14:47:32 +01:00
|
|
|
return throw_error(obj->ctx, JS_E_NONWRITABLE_MODIFIED, name);
|
2018-05-14 13:34:26 +02:00
|
|
|
if(desc->explicit_value) {
|
|
|
|
if(prop->type == PROP_JSVAL) {
|
|
|
|
BOOL eq;
|
|
|
|
hres = jsval_strict_equal(desc->value, prop->u.val, &eq);
|
|
|
|
if(FAILED(hres))
|
|
|
|
return hres;
|
|
|
|
if(!eq)
|
2020-02-03 14:47:32 +01:00
|
|
|
return throw_error(obj->ctx, JS_E_NONWRITABLE_MODIFIED, name);
|
2018-05-14 13:34:26 +02:00
|
|
|
}else {
|
|
|
|
FIXME("redefinition of property type %d\n", prop->type);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2018-05-11 14:43:20 +02:00
|
|
|
if(desc->explicit_value) {
|
2018-05-14 13:34:26 +02:00
|
|
|
if(prop->type == PROP_JSVAL)
|
|
|
|
jsval_release(prop->u.val);
|
|
|
|
else
|
|
|
|
prop->type = PROP_JSVAL;
|
|
|
|
hres = jsval_copy(desc->value, &prop->u.val);
|
|
|
|
if(FAILED(hres)) {
|
|
|
|
prop->u.val = jsval_undefined();
|
|
|
|
return hres;
|
2018-05-11 14:43:20 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2018-05-14 13:34:26 +02:00
|
|
|
}else if(desc->explicit_getter || desc->explicit_setter) {
|
|
|
|
if(prop->type != PROP_ACCESSOR) {
|
|
|
|
if(!(prop->flags & PROPF_CONFIGURABLE))
|
2020-02-03 14:47:32 +01:00
|
|
|
return throw_error(obj->ctx, JS_E_NONCONFIGURABLE_REDEFINED, name);
|
2018-05-11 14:43:20 +02:00
|
|
|
if(prop->type == PROP_JSVAL)
|
|
|
|
jsval_release(prop->u.val);
|
2018-05-14 13:34:26 +02:00
|
|
|
prop->type = PROP_ACCESSOR;
|
|
|
|
prop->u.accessor.getter = prop->u.accessor.setter = NULL;
|
|
|
|
}else if(!(prop->flags & PROPF_CONFIGURABLE)) {
|
|
|
|
if((desc->explicit_getter && desc->getter != prop->u.accessor.getter)
|
|
|
|
|| (desc->explicit_setter && desc->setter != prop->u.accessor.setter))
|
2020-02-03 14:47:32 +01:00
|
|
|
return throw_error(obj->ctx, JS_E_NONCONFIGURABLE_REDEFINED, name);
|
2018-05-14 13:34:26 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if(desc->explicit_getter) {
|
|
|
|
if(prop->u.accessor.getter) {
|
|
|
|
jsdisp_release(prop->u.accessor.getter);
|
|
|
|
prop->u.accessor.getter = NULL;
|
2018-05-11 14:43:20 +02:00
|
|
|
}
|
2018-05-14 13:34:26 +02:00
|
|
|
if(desc->getter)
|
|
|
|
prop->u.accessor.getter = jsdisp_addref(desc->getter);
|
|
|
|
}
|
|
|
|
if(desc->explicit_setter) {
|
|
|
|
if(prop->u.accessor.setter) {
|
|
|
|
jsdisp_release(prop->u.accessor.setter);
|
|
|
|
prop->u.accessor.setter = NULL;
|
|
|
|
}
|
|
|
|
if(desc->setter)
|
|
|
|
prop->u.accessor.setter = jsdisp_addref(desc->setter);
|
2018-05-11 14:43:20 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
prop->flags = (prop->flags & ~desc->mask) | (desc->flags & desc->mask);
|
2018-05-10 19:19:56 +02:00
|
|
|
return S_OK;
|
|
|
|
}
|
2018-05-11 14:43:28 +02:00
|
|
|
|
|
|
|
HRESULT jsdisp_define_data_property(jsdisp_t *obj, const WCHAR *name, unsigned flags, jsval_t value)
|
|
|
|
{
|
2018-06-04 18:11:08 +02:00
|
|
|
property_desc_t prop_desc = { flags, flags, TRUE };
|
|
|
|
prop_desc.value = value;
|
2018-05-11 14:43:28 +02:00
|
|
|
return jsdisp_define_property(obj, name, &prop_desc);
|
|
|
|
}
|
2020-06-04 17:29:51 +02:00
|
|
|
|
2021-11-02 19:07:11 +01:00
|
|
|
HRESULT jsdisp_change_prototype(jsdisp_t *obj, jsdisp_t *proto)
|
|
|
|
{
|
|
|
|
DWORD i;
|
|
|
|
|
|
|
|
if(obj->prototype == proto)
|
|
|
|
return S_OK;
|
|
|
|
|
|
|
|
if(obj->prototype) {
|
|
|
|
for(i = 0; i < obj->prop_cnt; i++)
|
|
|
|
if(obj->props[i].type == PROP_PROTREF)
|
|
|
|
obj->props[i].type = PROP_DELETED;
|
|
|
|
jsdisp_release(obj->prototype);
|
|
|
|
}
|
|
|
|
|
|
|
|
obj->prototype = proto;
|
|
|
|
if(proto)
|
|
|
|
jsdisp_addref(proto);
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
2021-04-01 18:19:16 +02:00
|
|
|
void jsdisp_freeze(jsdisp_t *obj, BOOL seal)
|
2021-04-01 18:19:09 +02:00
|
|
|
{
|
|
|
|
unsigned int i;
|
|
|
|
|
|
|
|
for(i = 0; i < obj->prop_cnt; i++) {
|
2021-04-01 18:19:16 +02:00
|
|
|
if(!seal && obj->props[i].type == PROP_JSVAL)
|
2021-04-01 18:19:09 +02:00
|
|
|
obj->props[i].flags &= ~PROPF_WRITABLE;
|
|
|
|
obj->props[i].flags &= ~PROPF_CONFIGURABLE;
|
|
|
|
}
|
|
|
|
|
|
|
|
obj->extensible = FALSE;
|
|
|
|
}
|
|
|
|
|
2021-04-02 20:24:37 +02:00
|
|
|
BOOL jsdisp_is_frozen(jsdisp_t *obj, BOOL sealed)
|
|
|
|
{
|
|
|
|
unsigned int i;
|
|
|
|
|
|
|
|
if(obj->extensible)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
for(i = 0; i < obj->prop_cnt; i++) {
|
|
|
|
if(obj->props[i].type == PROP_JSVAL) {
|
|
|
|
if(!sealed && (obj->props[i].flags & PROPF_WRITABLE))
|
|
|
|
return FALSE;
|
|
|
|
}else if(obj->props[i].type != PROP_ACCESSOR)
|
|
|
|
continue;
|
|
|
|
if(obj->props[i].flags & PROPF_CONFIGURABLE)
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2020-06-04 17:29:51 +02:00
|
|
|
HRESULT jsdisp_get_prop_name(jsdisp_t *obj, DISPID id, jsstr_t **r)
|
|
|
|
{
|
|
|
|
dispex_prop_t *prop = get_prop(obj, id);
|
|
|
|
|
2021-11-25 21:01:28 +01:00
|
|
|
if(!prop)
|
2020-06-04 17:29:51 +02:00
|
|
|
return DISP_E_MEMBERNOTFOUND;
|
|
|
|
|
|
|
|
*r = jsstr_alloc(prop->name);
|
|
|
|
return *r ? S_OK : E_OUTOFMEMORY;
|
|
|
|
}
|