jscript: Store jsdisp_t values as jsval_t instead of VARIANT.

This commit is contained in:
Jacek Caban 2012-09-17 15:17:24 +02:00 committed by Alexandre Julliard
parent 16b2b019b8
commit 80f7f3c246
5 changed files with 42 additions and 49 deletions

View File

@ -36,7 +36,7 @@ static const IID IID_IDispatchJS =
#define GOLDEN_RATIO 0x9E3779B9U #define GOLDEN_RATIO 0x9E3779B9U
typedef enum { typedef enum {
PROP_VARIANT, PROP_JSVAL,
PROP_BUILTIN, PROP_BUILTIN,
PROP_PROTREF, PROP_PROTREF,
PROP_DELETED PROP_DELETED
@ -49,7 +49,7 @@ struct _dispex_prop_t {
DWORD flags; DWORD flags;
union { union {
VARIANT var; jsval_t val;
const builtin_prop_t *p; const builtin_prop_t *p;
DWORD ref; DWORD ref;
} u; } u;
@ -276,15 +276,15 @@ static HRESULT ensure_prop_name(jsdisp_t *This, const WCHAR *name, BOOL search_p
TRACE("creating prop %s\n", debugstr_w(name)); TRACE("creating prop %s\n", debugstr_w(name));
if(prop) { if(prop) {
prop->type = PROP_VARIANT; prop->type = PROP_JSVAL;
prop->flags = create_flags; prop->flags = create_flags;
}else { }else {
prop = alloc_prop(This, name, PROP_VARIANT, create_flags); prop = alloc_prop(This, name, PROP_JSVAL, create_flags);
if(!prop) if(!prop)
return E_OUTOFMEMORY; return E_OUTOFMEMORY;
} }
VariantInit(&prop->u.var); prop->u.val = jsval_undefined();
} }
*ret = prop; *ret = prop;
@ -372,15 +372,15 @@ static HRESULT invoke_prop_func(jsdisp_t *This, IDispatch *jsthis, dispex_prop_t
case PROP_PROTREF: case PROP_PROTREF:
return invoke_prop_func(This->prototype, jsthis, This->prototype->props+prop->u.ref, return invoke_prop_func(This->prototype, jsthis, This->prototype->props+prop->u.ref,
flags, argc, argv, r, ei, caller); flags, argc, argv, r, ei, caller);
case PROP_VARIANT: { case PROP_JSVAL: {
if(V_VT(&prop->u.var) != VT_DISPATCH) { if(!is_object_instance(prop->u.val)) {
FIXME("invoke vt %d\n", V_VT(&prop->u.var)); FIXME("invoke %s\n", debugstr_jsval(prop->u.val));
return E_FAIL; return E_FAIL;
} }
TRACE("call %s %p\n", debugstr_w(prop->name), V_DISPATCH(&prop->u.var)); TRACE("call %s %p\n", debugstr_w(prop->name), get_object(prop->u.val));
return disp_call_value(This->ctx, V_DISPATCH(&prop->u.var), jsthis, flags, argc, argv, r, ei); return disp_call_value(This->ctx, get_object(prop->u.val), jsthis, flags, argc, argv, r, ei);
} }
default: default:
ERR("type %d\n", prop->type); ERR("type %d\n", prop->type);
@ -403,9 +403,11 @@ static HRESULT prop_get(jsdisp_t *This, dispex_prop_t *prop, DISPPARAMS *dp,
if(FAILED(hres)) if(FAILED(hres))
break; break;
prop->type = PROP_VARIANT; prop->type = PROP_JSVAL;
var_set_jsdisp(&prop->u.var, obj); prop->u.val = jsval_obj(obj);
hres = variant_to_jsval(&prop->u.var, r);
jsdisp_addref(obj);
*r = jsval_obj(obj);
}else { }else {
vdisp_t vthis; vdisp_t vthis;
@ -417,8 +419,8 @@ static HRESULT prop_get(jsdisp_t *This, dispex_prop_t *prop, DISPPARAMS *dp,
case PROP_PROTREF: case PROP_PROTREF:
hres = prop_get(This->prototype, This->prototype->props+prop->u.ref, dp, r, ei, caller); hres = prop_get(This->prototype, This->prototype->props+prop->u.ref, dp, r, ei, caller);
break; break;
case PROP_VARIANT: case PROP_JSVAL:
hres = variant_to_jsval(&prop->u.var, r); hres = jsval_copy(prop->u.val, r);
break; break;
default: default:
ERR("type %d\n", prop->type); ERR("type %d\n", prop->type);
@ -453,21 +455,23 @@ static HRESULT prop_put(jsdisp_t *This, dispex_prop_t *prop, jsval_t val,
return hres; return hres;
} }
case PROP_PROTREF: case PROP_PROTREF:
prop->type = PROP_VARIANT; prop->type = PROP_JSVAL;
prop->flags = PROPF_ENUM; prop->flags = PROPF_ENUM;
V_VT(&prop->u.var) = VT_EMPTY; prop->u.val = jsval_undefined();
break; break;
case PROP_VARIANT: case PROP_JSVAL:
VariantClear(&prop->u.var); jsval_release(prop->u.val);
break; break;
default: default:
ERR("type %d\n", prop->type); ERR("type %d\n", prop->type);
return E_FAIL; return E_FAIL;
} }
hres = jsval_to_variant(val, &prop->u.var); hres = jsval_copy(val, &prop->u.val);
if(FAILED(hres)) if(FAILED(hres)) {
prop->u.val = jsval_undefined();
return hres; return hres;
}
if(This->builtin_info->on_put) if(This->builtin_info->on_put)
This->builtin_info->on_put(This, prop->name); This->builtin_info->on_put(This, prop->name);
@ -562,8 +566,8 @@ static ULONG WINAPI DispatchEx_Release(IDispatchEx *iface)
dispex_prop_t *prop; dispex_prop_t *prop;
for(prop = This->props; prop < This->props+This->prop_cnt; prop++) { for(prop = This->props; prop < This->props+This->prop_cnt; prop++) {
if(prop->type == PROP_VARIANT) if(prop->type == PROP_JSVAL)
VariantClear(&prop->u.var); jsval_release(prop->u.val);
heap_free(prop->name); heap_free(prop->name);
} }
heap_free(This->props); heap_free(This->props);
@ -733,8 +737,8 @@ static HRESULT WINAPI DispatchEx_InvokeEx(IDispatchEx *iface, DISPID id, LCID lc
static HRESULT delete_prop(dispex_prop_t *prop) static HRESULT delete_prop(dispex_prop_t *prop)
{ {
if(prop->type == PROP_VARIANT) { if(prop->type == PROP_JSVAL) {
VariantClear(&prop->u.var); jsval_release(prop->u.val);
prop->type = PROP_DELETED; prop->type = PROP_DELETED;
} }
return S_OK; return S_OK;
@ -1252,7 +1256,7 @@ HRESULT jsdisp_propput_name(jsdisp_t *obj, const WCHAR *name, jsval_t val, jsexc
return prop_put(obj, prop, val, ei, NULL); return prop_put(obj, prop, val, ei, NULL);
} }
HRESULT jsdisp_propput_const(jsdisp_t *obj, const WCHAR *name, VARIANT *val) HRESULT jsdisp_propput_const(jsdisp_t *obj, const WCHAR *name, jsval_t val)
{ {
dispex_prop_t *prop; dispex_prop_t *prop;
HRESULT hres; HRESULT hres;
@ -1261,10 +1265,10 @@ HRESULT jsdisp_propput_const(jsdisp_t *obj, const WCHAR *name, VARIANT *val)
if(FAILED(hres)) if(FAILED(hres))
return hres; return hres;
return VariantCopy(&prop->u.var, val); return jsval_copy(val, &prop->u.val);
} }
HRESULT jsdisp_propput_dontenum(jsdisp_t *obj, const WCHAR *name, VARIANT *val) HRESULT jsdisp_propput_dontenum(jsdisp_t *obj, const WCHAR *name, jsval_t val)
{ {
dispex_prop_t *prop; dispex_prop_t *prop;
HRESULT hres; HRESULT hres;
@ -1273,7 +1277,7 @@ HRESULT jsdisp_propput_dontenum(jsdisp_t *obj, const WCHAR *name, VARIANT *val)
if(FAILED(hres)) if(FAILED(hres))
return hres; return hres;
return VariantCopy(&prop->u.var, val); return jsval_copy(val, &prop->u.val);
} }
HRESULT jsdisp_propput_idx(jsdisp_t *obj, DWORD idx, jsval_t val, jsexcept_t *ei) HRESULT jsdisp_propput_idx(jsdisp_t *obj, DWORD idx, jsval_t val, jsexcept_t *ei)
@ -1441,6 +1445,6 @@ HRESULT jsdisp_is_own_prop(jsdisp_t *obj, BSTR name, VARIANT_BOOL *ret)
if(FAILED(hres)) if(FAILED(hres))
return hres; return hres;
*ret = prop && (prop->type == PROP_VARIANT || prop->type == PROP_BUILTIN) ? VARIANT_TRUE : VARIANT_FALSE; *ret = prop && (prop->type == PROP_JSVAL || prop->type == PROP_BUILTIN) ? VARIANT_TRUE : VARIANT_FALSE;
return S_OK; return S_OK;
} }

View File

@ -609,13 +609,8 @@ HRESULT create_builtin_function(script_ctx_t *ctx, builtin_invoke_t value_proc,
if(FAILED(hres)) if(FAILED(hres))
return hres; return hres;
if(builtin_info) { if(builtin_info)
VARIANT var; hres = jsdisp_propput_const(&function->dispex, lengthW, jsval_number(function->length));
num_set_int(&var, function->length);
hres = jsdisp_propput_const(&function->dispex, lengthW, &var);
}
if(SUCCEEDED(hres)) if(SUCCEEDED(hres))
hres = set_prototype(ctx, &function->dispex, prototype); hres = set_prototype(ctx, &function->dispex, prototype);
if(FAILED(hres)) { if(FAILED(hres)) {
@ -632,13 +627,9 @@ HRESULT create_builtin_function(script_ctx_t *ctx, builtin_invoke_t value_proc,
static HRESULT set_constructor_prop(script_ctx_t *ctx, jsdisp_t *constr, jsdisp_t *prot) static HRESULT set_constructor_prop(script_ctx_t *ctx, jsdisp_t *constr, jsdisp_t *prot)
{ {
VARIANT v;
static const WCHAR constructorW[] = {'c','o','n','s','t','r','u','c','t','o','r',0}; static const WCHAR constructorW[] = {'c','o','n','s','t','r','u','c','t','o','r',0};
V_VT(&v) = VT_DISPATCH; return jsdisp_propput_dontenum(prot, constructorW, jsval_obj(constr));
V_DISPATCH(&v) = to_disp(constr);
return jsdisp_propput_dontenum(prot, constructorW, &v);
} }
HRESULT create_builtin_constructor(script_ctx_t *ctx, builtin_invoke_t value_proc, const WCHAR *name, HRESULT create_builtin_constructor(script_ctx_t *ctx, builtin_invoke_t value_proc, const WCHAR *name,

View File

@ -217,8 +217,8 @@ HRESULT disp_propget(script_ctx_t*,IDispatch*,DISPID,jsval_t*,jsexcept_t*) DECLS
HRESULT disp_propput(script_ctx_t*,IDispatch*,DISPID,jsval_t,jsexcept_t*) DECLSPEC_HIDDEN; HRESULT disp_propput(script_ctx_t*,IDispatch*,DISPID,jsval_t,jsexcept_t*) DECLSPEC_HIDDEN;
HRESULT jsdisp_propget(jsdisp_t*,DISPID,jsval_t*,jsexcept_t*) DECLSPEC_HIDDEN; HRESULT jsdisp_propget(jsdisp_t*,DISPID,jsval_t*,jsexcept_t*) DECLSPEC_HIDDEN;
HRESULT jsdisp_propput_name(jsdisp_t*,const WCHAR*,jsval_t,jsexcept_t*) DECLSPEC_HIDDEN; HRESULT jsdisp_propput_name(jsdisp_t*,const WCHAR*,jsval_t,jsexcept_t*) DECLSPEC_HIDDEN;
HRESULT jsdisp_propput_const(jsdisp_t*,const WCHAR*,VARIANT*) DECLSPEC_HIDDEN; HRESULT jsdisp_propput_const(jsdisp_t*,const WCHAR*,jsval_t) DECLSPEC_HIDDEN;
HRESULT jsdisp_propput_dontenum(jsdisp_t*,const WCHAR*,VARIANT*) DECLSPEC_HIDDEN; HRESULT jsdisp_propput_dontenum(jsdisp_t*,const WCHAR*,jsval_t) DECLSPEC_HIDDEN;
HRESULT jsdisp_propput_idx(jsdisp_t*,DWORD,jsval_t,jsexcept_t*) DECLSPEC_HIDDEN; HRESULT jsdisp_propput_idx(jsdisp_t*,DWORD,jsval_t,jsexcept_t*) DECLSPEC_HIDDEN;
HRESULT jsdisp_propget_name(jsdisp_t*,LPCWSTR,jsval_t*,jsexcept_t*) DECLSPEC_HIDDEN; HRESULT jsdisp_propget_name(jsdisp_t*,LPCWSTR,jsval_t*,jsexcept_t*) DECLSPEC_HIDDEN;
HRESULT jsdisp_get_idx(jsdisp_t*,DWORD,jsval_t*,jsexcept_t*) DECLSPEC_HIDDEN; HRESULT jsdisp_get_idx(jsdisp_t*,DWORD,jsval_t*,jsexcept_t*) DECLSPEC_HIDDEN;

View File

@ -260,7 +260,8 @@ HRESULT jsval_copy(jsval_t v, jsval_t *r)
*r = v; *r = v;
return S_OK; return S_OK;
case JSV_OBJECT: case JSV_OBJECT:
IDispatch_AddRef(get_object(v)); if(get_object(v))
IDispatch_AddRef(get_object(v));
*r = v; *r = v;
return S_OK; return S_OK;
case JSV_STRING: { case JSV_STRING: {

View File

@ -532,7 +532,6 @@ HRESULT create_math(script_ctx_t *ctx, jsdisp_t **ret)
{ {
jsdisp_t *math; jsdisp_t *math;
unsigned i; unsigned i;
VARIANT v;
HRESULT hres; HRESULT hres;
struct { struct {
@ -559,10 +558,8 @@ HRESULT create_math(script_ctx_t *ctx, jsdisp_t **ret)
return hres; return hres;
} }
V_VT(&v) = VT_R8;
for(i=0; i < sizeof(constants)/sizeof(*constants); i++) { for(i=0; i < sizeof(constants)/sizeof(*constants); i++) {
V_R8(&v) = constants[i].val; hres = jsdisp_propput_const(math, constants[i].name, jsval_number(constants[i].val));
hres = jsdisp_propput_const(math, constants[i].name, &v);
if(FAILED(hres)) { if(FAILED(hres)) {
jsdisp_release(math); jsdisp_release(math);
return hres; return hres;