Commit f8c2b42d authored by Jacek Caban's avatar Jacek Caban Committed by Alexandre Julliard

jscript: Allow 'this' to be host object in builtin functions.

parent 5dcd182e
......@@ -32,20 +32,26 @@ typedef struct {
static const WCHAR toStringW[] = {'t','o','S','t','r','i','n','g',0};
static const WCHAR valueOfW[] = {'v','a','l','u','e','O','f',0};
static inline BoolInstance *bool_this(vdisp_t *jsthis)
{
return is_vclass(jsthis, JSCLASS_BOOLEAN) ? (BoolInstance*)jsthis->u.jsdisp : NULL;
}
/* ECMA-262 3rd Edition 15.6.4.2 */
static HRESULT Bool_toString(script_ctx_t *ctx, DispatchEx *dispex, WORD flags, DISPPARAMS *dp,
static HRESULT Bool_toString(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, DISPPARAMS *dp,
VARIANT *retv, jsexcept_t *ei, IServiceProvider *sp)
{
BoolInstance *bool;
static const WCHAR trueW[] = {'t','r','u','e',0};
static const WCHAR falseW[] = {'f','a','l','s','e',0};
TRACE("\n");
if(!is_class(dispex, JSCLASS_BOOLEAN))
if(!(bool = bool_this(jsthis)))
return throw_type_error(ctx, ei, IDS_NOT_BOOL, NULL);
if(retv) {
BoolInstance *bool = (BoolInstance*)dispex;
BSTR val;
if(bool->val) val = SysAllocString(trueW);
......@@ -62,17 +68,17 @@ static HRESULT Bool_toString(script_ctx_t *ctx, DispatchEx *dispex, WORD flags,
}
/* ECMA-262 3rd Edition 15.6.4.3 */
static HRESULT Bool_valueOf(script_ctx_t *ctx, DispatchEx *dispex, WORD flags, DISPPARAMS *dp,
static HRESULT Bool_valueOf(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, DISPPARAMS *dp,
VARIANT *retv, jsexcept_t *ei, IServiceProvider *sp)
{
BoolInstance *bool;
TRACE("\n");
if(!is_class(dispex, JSCLASS_BOOLEAN))
if(!(bool = bool_this(jsthis)))
return throw_type_error(ctx, ei, IDS_NOT_BOOL, NULL);
if(retv) {
BoolInstance *bool = (BoolInstance*)dispex;
V_VT(retv) = VT_BOOL;
V_BOOL(retv) = bool->val;
}
......@@ -80,7 +86,7 @@ static HRESULT Bool_valueOf(script_ctx_t *ctx, DispatchEx *dispex, WORD flags, D
return S_OK;
}
static HRESULT Bool_value(script_ctx_t *ctx, DispatchEx *dispex, WORD flags, DISPPARAMS *dp,
static HRESULT Bool_value(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, DISPPARAMS *dp,
VARIANT *retv, jsexcept_t *ei, IServiceProvider *sp)
{
TRACE("\n");
......@@ -111,7 +117,7 @@ static const builtin_info_t Bool_info = {
NULL
};
static HRESULT BoolConstr_value(script_ctx_t *ctx, DispatchEx *dispex, WORD flags, DISPPARAMS *dp,
static HRESULT BoolConstr_value(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, DISPPARAMS *dp,
VARIANT *retv, jsexcept_t *ei, IServiceProvider *sp)
{
HRESULT hres;
......
......@@ -245,12 +245,19 @@ static HRESULT invoke_prop_func(DispatchEx *This, DispatchEx *jsthis, dispex_pro
HRESULT hres;
switch(prop->type) {
case PROP_BUILTIN:
case PROP_BUILTIN: {
vdisp_t vthis;
if(flags == DISPATCH_CONSTRUCT && (prop->flags & DISPATCH_METHOD)) {
WARN("%s is not a constructor\n", debugstr_w(prop->name));
return E_INVALIDARG;
}
return prop->u.p->invoke(This->ctx, jsthis, flags, dp, retv, ei, caller);
set_jsdisp(&vthis, jsthis);
hres = prop->u.p->invoke(This->ctx, &vthis, flags, dp, retv, ei, caller);
vdisp_release(&vthis);
return hres;
}
case PROP_PROTREF:
return invoke_prop_func(This->prototype, jsthis, This->prototype->props+prop->u.ref, flags, dp, retv, ei, caller);
case PROP_VARIANT: {
......@@ -304,7 +311,11 @@ static HRESULT prop_get(DispatchEx *This, dispex_prop_t *prop, DISPPARAMS *dp,
hres = VariantCopy(retv, &prop->u.var);
}else {
hres = prop->u.p->invoke(This->ctx, This, DISPATCH_PROPERTYGET, dp, retv, ei, caller);
vdisp_t vthis;
set_jsdisp(&vthis, This);
hres = prop->u.p->invoke(This->ctx, &vthis, DISPATCH_PROPERTYGET, dp, retv, ei, caller);
vdisp_release(&vthis);
}
break;
case PROP_PROTREF:
......@@ -335,8 +346,14 @@ static HRESULT prop_put(DispatchEx *This, dispex_prop_t *prop, DISPPARAMS *dp,
switch(prop->type) {
case PROP_BUILTIN:
if(!(prop->flags & PROPF_METHOD))
return prop->u.p->invoke(This->ctx, This, DISPATCH_PROPERTYPUT, dp, NULL, ei, caller);
if(!(prop->flags & PROPF_METHOD)) {
vdisp_t vthis;
set_jsdisp(&vthis, This);
hres = prop->u.p->invoke(This->ctx, &vthis, DISPATCH_PROPERTYPUT, dp, NULL, ei, caller);
vdisp_release(&vthis);
return hres;
}
case PROP_PROTREF:
prop->type = PROP_VARIANT;
prop->flags = PROPF_ENUM;
......@@ -823,10 +840,16 @@ HRESULT jsdisp_get_id(DispatchEx *jsdisp, const WCHAR *name, DWORD flags, DISPID
return DISP_E_UNKNOWNNAME;
}
HRESULT jsdisp_call_value(DispatchEx *disp, WORD flags, DISPPARAMS *dp, VARIANT *retv,
HRESULT jsdisp_call_value(DispatchEx *jsthis, WORD flags, DISPPARAMS *dp, VARIANT *retv,
jsexcept_t *ei, IServiceProvider *caller)
{
return disp->builtin_info->value_prop.invoke(disp->ctx, disp, flags, dp, retv, ei, caller);
vdisp_t vdisp;
HRESULT hres;
set_jsdisp(&vdisp, jsthis);
hres = jsthis->builtin_info->value_prop.invoke(jsthis->ctx, &vdisp, flags, dp, retv, ei, caller);
vdisp_release(&vdisp);
return hres;
}
HRESULT jsdisp_call(DispatchEx *disp, DISPID id, WORD flags, DISPPARAMS *dp, VARIANT *retv,
......
......@@ -39,10 +39,15 @@ static const WCHAR messageW[] = {'m','e','s','s','a','g','e',0};
static const WCHAR numberW[] = {'n','u','m','b','e','r',0};
static const WCHAR toStringW[] = {'t','o','S','t','r','i','n','g',0};
static HRESULT Error_number(script_ctx_t *ctx, DispatchEx *dispex, WORD flags,
static inline ErrorInstance *error_from_vdisp(vdisp_t *vdisp)
{
return (ErrorInstance*)vdisp->u.jsdisp;
}
static HRESULT Error_number(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags,
DISPPARAMS *dp, VARIANT *retv, jsexcept_t *ei, IServiceProvider *sp)
{
ErrorInstance *This = (ErrorInstance*)dispex;
ErrorInstance *This = error_from_vdisp(jsthis);
TRACE("\n");
......@@ -57,10 +62,10 @@ static HRESULT Error_number(script_ctx_t *ctx, DispatchEx *dispex, WORD flags,
}
}
static HRESULT Error_description(script_ctx_t *ctx, DispatchEx *dispex, WORD flags,
static HRESULT Error_description(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags,
DISPPARAMS *dp, VARIANT *retv, jsexcept_t *ei, IServiceProvider *sp)
{
ErrorInstance *This = (ErrorInstance*)dispex;
ErrorInstance *This = error_from_vdisp(jsthis);
TRACE("\n");
......@@ -76,10 +81,10 @@ static HRESULT Error_description(script_ctx_t *ctx, DispatchEx *dispex, WORD fla
}
/* ECMA-262 3rd Edition 15.11.4.3 */
static HRESULT Error_message(script_ctx_t *ctx, DispatchEx *dispex, WORD flags,
static HRESULT Error_message(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags,
DISPPARAMS *dp, VARIANT *retv, jsexcept_t *ei, IServiceProvider *sp)
{
ErrorInstance *This = (ErrorInstance*)dispex;
ErrorInstance *This = error_from_vdisp(jsthis);
TRACE("\n");
......@@ -95,7 +100,7 @@ static HRESULT Error_message(script_ctx_t *ctx, DispatchEx *dispex, WORD flags,
}
/* ECMA-262 3rd Edition 15.11.4.4 */
static HRESULT Error_toString(script_ctx_t *ctx, DispatchEx *dispex, WORD flags,
static HRESULT Error_toString(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags,
DISPPARAMS *dp, VARIANT *retv, jsexcept_t *ei, IServiceProvider *sp)
{
static const WCHAR str[] = {'[','o','b','j','e','c','t',' ','E','r','r','o','r',']',0};
......@@ -112,7 +117,7 @@ static HRESULT Error_toString(script_ctx_t *ctx, DispatchEx *dispex, WORD flags,
return S_OK;
}
static HRESULT Error_value(script_ctx_t *ctx, DispatchEx *dispex, WORD flags,
static HRESULT Error_value(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags,
DISPPARAMS *dp, VARIANT *retv, jsexcept_t *ei, IServiceProvider *sp)
{
TRACE("\n");
......@@ -278,56 +283,56 @@ static HRESULT error_constr(script_ctx_t *ctx, WORD flags, DISPPARAMS *dp,
}
}
static HRESULT ErrorConstr_value(script_ctx_t *ctx, DispatchEx *dispex, WORD flags,
static HRESULT ErrorConstr_value(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags,
DISPPARAMS *dp, VARIANT *retv, jsexcept_t *ei, IServiceProvider *sp)
{
TRACE("\n");
return error_constr(ctx, flags, dp, retv, ei, ctx->error_constr);
}
static HRESULT EvalErrorConstr_value(script_ctx_t *ctx, DispatchEx *dispex, WORD flags,
static HRESULT EvalErrorConstr_value(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags,
DISPPARAMS *dp, VARIANT *retv, jsexcept_t *ei, IServiceProvider *sp)
{
TRACE("\n");
return error_constr(ctx, flags, dp, retv, ei, ctx->eval_error_constr);
}
static HRESULT RangeErrorConstr_value(script_ctx_t *ctx, DispatchEx *dispex, WORD flags,
static HRESULT RangeErrorConstr_value(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags,
DISPPARAMS *dp, VARIANT *retv, jsexcept_t *ei, IServiceProvider *sp)
{
TRACE("\n");
return error_constr(ctx, flags, dp, retv, ei, ctx->range_error_constr);
}
static HRESULT ReferenceErrorConstr_value(script_ctx_t *ctx, DispatchEx *dispex, WORD flags,
static HRESULT ReferenceErrorConstr_value(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags,
DISPPARAMS *dp, VARIANT *retv, jsexcept_t *ei, IServiceProvider *sp)
{
TRACE("\n");
return error_constr(ctx, flags, dp, retv, ei, ctx->reference_error_constr);
}
static HRESULT RegExpErrorConstr_value(script_ctx_t *ctx, DispatchEx *dispex, WORD flags,
static HRESULT RegExpErrorConstr_value(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags,
DISPPARAMS *dp, VARIANT *retv, jsexcept_t *ei, IServiceProvider *sp)
{
TRACE("\n");
return error_constr(ctx, flags, dp, retv, ei, ctx->regexp_error_constr);
}
static HRESULT SyntaxErrorConstr_value(script_ctx_t *ctx, DispatchEx *dispex, WORD flags,
static HRESULT SyntaxErrorConstr_value(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags,
DISPPARAMS *dp, VARIANT *retv, jsexcept_t *ei, IServiceProvider *sp)
{
TRACE("\n");
return error_constr(ctx, flags, dp, retv, ei, ctx->syntax_error_constr);
}
static HRESULT TypeErrorConstr_value(script_ctx_t *ctx, DispatchEx *dispex, WORD flags,
static HRESULT TypeErrorConstr_value(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags,
DISPPARAMS *dp, VARIANT *retv, jsexcept_t *ei, IServiceProvider *sp)
{
TRACE("\n");
return error_constr(ctx, flags, dp, retv, ei, ctx->type_error_constr);
}
static HRESULT URIErrorConstr_value(script_ctx_t *ctx, DispatchEx *dispex, WORD flags,
static HRESULT URIErrorConstr_value(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags,
DISPPARAMS *dp, VARIANT *retv, jsexcept_t *ei, IServiceProvider *sp)
{
TRACE("\n");
......
......@@ -37,6 +37,16 @@ typedef struct {
DWORD length;
} FunctionInstance;
static inline FunctionInstance *function_from_vdisp(vdisp_t *vdisp)
{
return (FunctionInstance*)vdisp->u.jsdisp;
}
static inline FunctionInstance *function_this(vdisp_t *jsthis)
{
return is_vclass(jsthis, JSCLASS_FUNCTION) ? function_from_vdisp(jsthis) : NULL;
}
static const WCHAR prototypeW[] = {'p','r','o','t','o','t', 'y', 'p','e',0};
static const WCHAR lengthW[] = {'l','e','n','g','t','h',0};
......@@ -85,7 +95,7 @@ static HRESULT init_parameters(DispatchEx *var_disp, FunctionInstance *function,
return S_OK;
}
static HRESULT Arguments_value(script_ctx_t *ctx, DispatchEx *dispex, WORD flags, DISPPARAMS *dp,
static HRESULT Arguments_value(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, DISPPARAMS *dp,
VARIANT *retv, jsexcept_t *ei, IServiceProvider *caller)
{
FIXME("\n");
......@@ -249,14 +259,16 @@ static HRESULT invoke_value_proc(script_ctx_t *ctx, FunctionInstance *function,
{
DispatchEx *this_obj = NULL;
IDispatch *this_disp;
vdisp_t vthis;
HRESULT hres;
this_disp = get_this(dp);
if(this_disp)
this_obj = iface_to_jsdisp((IUnknown*)this_disp);
hres = function->value_proc(ctx, this_obj ? this_obj : ctx->script_disp,
flags, dp, retv, ei, caller);
set_jsdisp(&vthis, this_obj ? this_obj : ctx->script_disp);
hres = function->value_proc(ctx, &vthis, flags, dp, retv, ei, caller);
vdisp_release(&vthis);
if(this_obj)
jsdisp_release(this_obj);
......@@ -270,6 +282,7 @@ static HRESULT call_function(script_ctx_t *ctx, FunctionInstance *function, IDis
if(function->value_proc) {
DispatchEx *jsthis = NULL;
vdisp_t vthis;
if(this_obj) {
jsthis = iface_to_jsdisp((IUnknown*)this_obj);
......@@ -277,8 +290,9 @@ static HRESULT call_function(script_ctx_t *ctx, FunctionInstance *function, IDis
FIXME("this_obj is not DispatchEx\n");
}
hres = function->value_proc(ctx, jsthis ? jsthis : ctx->script_disp,
DISPATCH_METHOD, args, retv, ei, caller);
set_jsdisp(&vthis, jsthis ? jsthis : ctx->script_disp);
hres = function->value_proc(ctx, &vthis, DISPATCH_METHOD, args, retv, ei, caller);
vdisp_release(&vthis);
if(jsthis)
jsdisp_release(jsthis);
......@@ -319,10 +333,10 @@ static HRESULT function_to_string(FunctionInstance *function, BSTR *ret)
return S_OK;
}
static HRESULT Function_length(script_ctx_t *ctx, DispatchEx *dispex, WORD flags, DISPPARAMS *dp,
static HRESULT Function_length(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, DISPPARAMS *dp,
VARIANT *retv, jsexcept_t *ei, IServiceProvider *sp)
{
FunctionInstance *This = (FunctionInstance*)dispex;
FunctionInstance *This = function_from_vdisp(jsthis);
TRACE("%p %d\n", This, This->length);
......@@ -339,7 +353,7 @@ static HRESULT Function_length(script_ctx_t *ctx, DispatchEx *dispex, WORD flags
return S_OK;
}
static HRESULT Function_toString(script_ctx_t *ctx, DispatchEx *dispex, WORD flags, DISPPARAMS *dp,
static HRESULT Function_toString(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, DISPPARAMS *dp,
VARIANT *retv, jsexcept_t *ei, IServiceProvider *sp)
{
FunctionInstance *function;
......@@ -348,11 +362,9 @@ static HRESULT Function_toString(script_ctx_t *ctx, DispatchEx *dispex, WORD fla
TRACE("\n");
if(!is_class(dispex, JSCLASS_FUNCTION))
if(!(function = function_this(jsthis)))
return throw_type_error(ctx, ei, IDS_NOT_FUNC, NULL);
function = (FunctionInstance*)dispex;
hres = function_to_string(function, &str);
if(FAILED(hres))
return hres;
......@@ -401,7 +413,7 @@ static HRESULT array_to_args(script_ctx_t *ctx, DispatchEx *arg_array, jsexcept_
return S_OK;
}
static HRESULT Function_apply(script_ctx_t *ctx, DispatchEx *dispex, WORD flags, DISPPARAMS *dp,
static HRESULT Function_apply(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, DISPPARAMS *dp,
VARIANT *retv, jsexcept_t *ei, IServiceProvider *caller)
{
FunctionInstance *function;
......@@ -412,12 +424,11 @@ static HRESULT Function_apply(script_ctx_t *ctx, DispatchEx *dispex, WORD flags,
TRACE("\n");
if(!is_class(dispex, JSCLASS_FUNCTION)) {
if(!(function = function_from_vdisp(jsthis))) {
FIXME("dispex is not a function\n");
return E_FAIL;
}
function = (FunctionInstance*)dispex;
argc = arg_cnt(dp);
if(argc) {
......@@ -457,7 +468,7 @@ static HRESULT Function_apply(script_ctx_t *ctx, DispatchEx *dispex, WORD flags,
return hres;
}
static HRESULT Function_call(script_ctx_t *ctx, DispatchEx *dispex, WORD flags, DISPPARAMS *dp,
static HRESULT Function_call(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, DISPPARAMS *dp,
VARIANT *retv, jsexcept_t *ei, IServiceProvider *caller)
{
FunctionInstance *function;
......@@ -468,14 +479,12 @@ static HRESULT Function_call(script_ctx_t *ctx, DispatchEx *dispex, WORD flags,
TRACE("\n");
if(!is_class(dispex, JSCLASS_FUNCTION)) {
if(!(function = function_from_vdisp(jsthis))) {
FIXME("dispex is not a function\n");
return E_FAIL;
}
function = (FunctionInstance*)dispex;
argc = arg_cnt(dp);
if(argc) {
hres = to_object(ctx, get_arg(dp,0), &this_obj);
if(FAILED(hres))
......@@ -493,19 +502,19 @@ static HRESULT Function_call(script_ctx_t *ctx, DispatchEx *dispex, WORD flags,
return hres;
}
HRESULT Function_value(script_ctx_t *ctx, DispatchEx *dispex, WORD flags, DISPPARAMS *dp,
HRESULT Function_value(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, DISPPARAMS *dp,
VARIANT *retv, jsexcept_t *ei, IServiceProvider *caller)
{
FunctionInstance *function;
TRACE("\n");
if(dispex->builtin_info->class != JSCLASS_FUNCTION) {
if(!is_vclass(jsthis, JSCLASS_FUNCTION)) {
ERR("dispex is not a function\n");
return E_FAIL;
}
function = (FunctionInstance*)dispex;
function = (FunctionInstance*)jsthis->u.jsdisp;
switch(flags) {
case DISPATCH_METHOD:
......@@ -568,14 +577,14 @@ static const builtin_info_t Function_info = {
NULL
};
static HRESULT FunctionConstr_value(script_ctx_t *ctx, DispatchEx *dispex, WORD flags, DISPPARAMS *dp,
static HRESULT FunctionConstr_value(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, DISPPARAMS *dp,
VARIANT *retv, jsexcept_t *ei, IServiceProvider *sp)
{
FIXME("\n");
return E_NOTIMPL;
}
static HRESULT FunctionProt_value(script_ctx_t *ctx, DispatchEx *dispex, WORD flags, DISPPARAMS *dp,
static HRESULT FunctionProt_value(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, DISPPARAMS *dp,
VARIANT *retv, jsexcept_t *ei, IServiceProvider *sp)
{
FIXME("\n");
......
/*
* Copyright 2008 Jacek Caban for CodeWeavers
* Copyright 2008-2009 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
......@@ -86,7 +86,73 @@ typedef enum {
JSCLASS_ARGUMENTS
} jsclass_t;
typedef HRESULT (*builtin_invoke_t)(script_ctx_t*,DispatchEx*,WORD,DISPPARAMS*,VARIANT*,jsexcept_t*,IServiceProvider*);
DispatchEx *iface_to_jsdisp(IUnknown*);
typedef struct {
union {
IDispatch *disp;
IDispatchEx *dispex;
DispatchEx *jsdisp;
} u;
DWORD flags;
} vdisp_t;
#define VDISP_DISPEX 0x0001
#define VDISP_JSDISP 0x0002
static inline void vdisp_release(vdisp_t *vdisp)
{
IDispatch_Release(vdisp->u.disp);
}
static inline BOOL is_jsdisp(vdisp_t *vdisp)
{
return (vdisp->flags & VDISP_JSDISP) != 0;
}
static inline BOOL is_dispex(vdisp_t *vdisp)
{
return (vdisp->flags & VDISP_DISPEX) != 0;
}
static inline void set_jsdisp(vdisp_t *vdisp, DispatchEx *jsdisp)
{
vdisp->u.jsdisp = jsdisp;
vdisp->flags = VDISP_JSDISP | VDISP_DISPEX;
IDispatch_AddRef(vdisp->u.disp);
}
static inline void set_disp(vdisp_t *vdisp, IDispatch *disp)
{
IDispatchEx *dispex;
DispatchEx *jsdisp;
HRESULT hres;
jsdisp = iface_to_jsdisp((IUnknown*)disp);
if(jsdisp) {
vdisp->u.jsdisp = jsdisp;
vdisp->flags = VDISP_JSDISP | VDISP_DISPEX;
return;
}
hres = IDispatch_QueryInterface(disp, &IID_IDispatchEx, (void**)&dispex);
if(SUCCEEDED(hres)) {
vdisp->u.dispex = dispex;
vdisp->flags = VDISP_DISPEX;
return;
}
IDispatch_AddRef(disp);
vdisp->u.disp = disp;
vdisp->flags = 0;
}
static inline DispatchEx *get_jsdisp(vdisp_t *vdisp)
{
return is_jsdisp(vdisp) ? vdisp->u.jsdisp : NULL;
}
typedef HRESULT (*builtin_invoke_t)(script_ctx_t*,vdisp_t*,WORD,DISPPARAMS*,VARIANT*,jsexcept_t*,IServiceProvider*);
typedef struct {
const WCHAR *name;
......@@ -128,7 +194,6 @@ static inline void jsdisp_release(DispatchEx *jsdisp)
HRESULT create_dispex(script_ctx_t*,const builtin_info_t*,DispatchEx*,DispatchEx**);
HRESULT init_dispex(DispatchEx*,script_ctx_t*,const builtin_info_t*,DispatchEx*);
HRESULT init_dispex_from_constr(DispatchEx*,script_ctx_t*,const builtin_info_t*,DispatchEx*);
DispatchEx *iface_to_jsdisp(IUnknown*);
HRESULT disp_call(script_ctx_t*,IDispatch*,DISPID,WORD,DISPPARAMS*,VARIANT*,jsexcept_t*,IServiceProvider*);
HRESULT jsdisp_call_value(DispatchEx*,WORD,DISPPARAMS*,VARIANT*,jsexcept_t*,IServiceProvider*);
......@@ -146,7 +211,7 @@ HRESULT jsdisp_delete_idx(DispatchEx*,DWORD);
HRESULT create_builtin_function(script_ctx_t*,builtin_invoke_t,const WCHAR*,const builtin_info_t*,DWORD,
DispatchEx*,DispatchEx**);
HRESULT Function_value(script_ctx_t*,DispatchEx*,WORD,DISPPARAMS*,VARIANT*,jsexcept_t*,IServiceProvider*);
HRESULT Function_value(script_ctx_t*,vdisp_t*,WORD,DISPPARAMS*,VARIANT*,jsexcept_t*,IServiceProvider*);
HRESULT throw_eval_error(script_ctx_t*,jsexcept_t*,UINT,const WCHAR*);
HRESULT throw_range_error(script_ctx_t*,jsexcept_t*,UINT,const WCHAR*);
......@@ -263,6 +328,11 @@ static inline BOOL is_class(DispatchEx *jsdisp, jsclass_t class)
return jsdisp->builtin_info->class == class;
}
static inline BOOL is_vclass(vdisp_t *vdisp, jsclass_t class)
{
return is_jsdisp(vdisp) && is_class(vdisp->u.jsdisp, class);
}
static inline BOOL is_num_vt(enum VARENUM vt)
{
return vt == VT_I4 || vt == VT_R8;
......
......@@ -73,7 +73,7 @@ static HRESULT math_constant(DOUBLE val, WORD flags, VARIANT *retv)
}
/* ECMA-262 3rd Edition 15.8.1.1 */
static HRESULT Math_E(script_ctx_t *ctx, DispatchEx *dispex, WORD flags, DISPPARAMS *dp,
static HRESULT Math_E(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, DISPPARAMS *dp,
VARIANT *retv, jsexcept_t *ei, IServiceProvider *sp)
{
TRACE("\n");
......@@ -81,7 +81,7 @@ static HRESULT Math_E(script_ctx_t *ctx, DispatchEx *dispex, WORD flags, DISPPAR
}
/* ECMA-262 3rd Edition 15.8.1.4 */
static HRESULT Math_LOG2E(script_ctx_t *ctx, DispatchEx *dispex, WORD flags, DISPPARAMS *dp,
static HRESULT Math_LOG2E(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, DISPPARAMS *dp,
VARIANT *retv, jsexcept_t *ei, IServiceProvider *sp)
{
TRACE("\n");
......@@ -89,21 +89,21 @@ static HRESULT Math_LOG2E(script_ctx_t *ctx, DispatchEx *dispex, WORD flags, DIS
}
/* ECMA-262 3rd Edition 15.8.1.4 */
static HRESULT Math_LOG10E(script_ctx_t *ctx, DispatchEx *dispex, WORD flags, DISPPARAMS *dp,
static HRESULT Math_LOG10E(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, DISPPARAMS *dp,
VARIANT *retv, jsexcept_t *ei, IServiceProvider *sp)
{
TRACE("\n");
return math_constant(M_LOG10E, flags, retv);
}
static HRESULT Math_LN2(script_ctx_t *ctx, DispatchEx *dispex, WORD flags, DISPPARAMS *dp,
static HRESULT Math_LN2(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, DISPPARAMS *dp,
VARIANT *retv, jsexcept_t *ei, IServiceProvider *sp)
{
TRACE("\n");
return math_constant(M_LN2, flags, retv);
}
static HRESULT Math_LN10(script_ctx_t *ctx, DispatchEx *dispex, WORD flags, DISPPARAMS *dp,
static HRESULT Math_LN10(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, DISPPARAMS *dp,
VARIANT *retv, jsexcept_t *ei, IServiceProvider *sp)
{
TRACE("\n");
......@@ -111,21 +111,21 @@ static HRESULT Math_LN10(script_ctx_t *ctx, DispatchEx *dispex, WORD flags, DISP
}
/* ECMA-262 3rd Edition 15.8.1.6 */
static HRESULT Math_PI(script_ctx_t *ctx, DispatchEx *dispex, WORD flags, DISPPARAMS *dp,
static HRESULT Math_PI(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, DISPPARAMS *dp,
VARIANT *retv, jsexcept_t *ei, IServiceProvider *sp)
{
TRACE("\n");
return math_constant(M_PI, flags, retv);
}
static HRESULT Math_SQRT2(script_ctx_t *ctx, DispatchEx *dispex, WORD flags, DISPPARAMS *dp,
static HRESULT Math_SQRT2(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, DISPPARAMS *dp,
VARIANT *retv, jsexcept_t *ei, IServiceProvider *sp)
{
TRACE("\n");
return math_constant(M_SQRT2, flags, retv);
}
static HRESULT Math_SQRT1_2(script_ctx_t *ctx, DispatchEx *dispex, WORD flags, DISPPARAMS *dp,
static HRESULT Math_SQRT1_2(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, DISPPARAMS *dp,
VARIANT *retv, jsexcept_t *ei, IServiceProvider *sp)
{
TRACE("\n");
......@@ -133,7 +133,7 @@ static HRESULT Math_SQRT1_2(script_ctx_t *ctx, DispatchEx *dispex, WORD flags, D
}
/* ECMA-262 3rd Edition 15.8.2.12 */
static HRESULT Math_abs(script_ctx_t *ctx, DispatchEx *dispex, WORD flags, DISPPARAMS *dp,
static HRESULT Math_abs(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, DISPPARAMS *dp,
VARIANT *retv, jsexcept_t *ei, IServiceProvider *sp)
{
VARIANT v;
......@@ -158,7 +158,7 @@ static HRESULT Math_abs(script_ctx_t *ctx, DispatchEx *dispex, WORD flags, DISPP
return S_OK;
}
static HRESULT Math_acos(script_ctx_t *ctx, DispatchEx *dispex, WORD flags, DISPPARAMS *dp,
static HRESULT Math_acos(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, DISPPARAMS *dp,
VARIANT *retv, jsexcept_t *ei, IServiceProvider *sp)
{
VARIANT v;
......@@ -179,7 +179,7 @@ static HRESULT Math_acos(script_ctx_t *ctx, DispatchEx *dispex, WORD flags, DISP
return S_OK;
}
static HRESULT Math_asin(script_ctx_t *ctx, DispatchEx *dispex, WORD flags, DISPPARAMS *dp,
static HRESULT Math_asin(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, DISPPARAMS *dp,
VARIANT *retv, jsexcept_t *ei, IServiceProvider *sp)
{
VARIANT v;
......@@ -200,7 +200,7 @@ static HRESULT Math_asin(script_ctx_t *ctx, DispatchEx *dispex, WORD flags, DISP
return S_OK;
}
static HRESULT Math_atan(script_ctx_t *ctx, DispatchEx *dispex, WORD flags, DISPPARAMS *dp,
static HRESULT Math_atan(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, DISPPARAMS *dp,
VARIANT *retv, jsexcept_t *ei, IServiceProvider *sp)
{
VARIANT v;
......@@ -221,7 +221,7 @@ static HRESULT Math_atan(script_ctx_t *ctx, DispatchEx *dispex, WORD flags, DISP
return S_OK;
}
static HRESULT Math_atan2(script_ctx_t *ctx, DispatchEx *dispex, WORD flags, DISPPARAMS *dp,
static HRESULT Math_atan2(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, DISPPARAMS *dp,
VARIANT *retv, jsexcept_t *ei, IServiceProvider *sp)
{
VARIANT v1, v2;
......@@ -247,7 +247,7 @@ static HRESULT Math_atan2(script_ctx_t *ctx, DispatchEx *dispex, WORD flags, DIS
}
/* ECMA-262 3rd Edition 15.8.2.6 */
static HRESULT Math_ceil(script_ctx_t *ctx, DispatchEx *dispex, WORD flags, DISPPARAMS *dp,
static HRESULT Math_ceil(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, DISPPARAMS *dp,
VARIANT *retv, jsexcept_t *ei, IServiceProvider *sp)
{
VARIANT v;
......@@ -270,7 +270,7 @@ static HRESULT Math_ceil(script_ctx_t *ctx, DispatchEx *dispex, WORD flags, DISP
return S_OK;
}
static HRESULT Math_cos(script_ctx_t *ctx, DispatchEx *dispex, WORD flags, DISPPARAMS *dp,
static HRESULT Math_cos(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, DISPPARAMS *dp,
VARIANT *retv, jsexcept_t *ei, IServiceProvider *sp)
{
VARIANT v;
......@@ -291,7 +291,7 @@ static HRESULT Math_cos(script_ctx_t *ctx, DispatchEx *dispex, WORD flags, DISPP
return S_OK;
}
static HRESULT Math_exp(script_ctx_t *ctx, DispatchEx *dispex, WORD flags, DISPPARAMS *dp,
static HRESULT Math_exp(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, DISPPARAMS *dp,
VARIANT *retv, jsexcept_t *ei, IServiceProvider *sp)
{
VARIANT v;
......@@ -312,7 +312,7 @@ static HRESULT Math_exp(script_ctx_t *ctx, DispatchEx *dispex, WORD flags, DISPP
return S_OK;
}
static HRESULT Math_floor(script_ctx_t *ctx, DispatchEx *dispex, WORD flags, DISPPARAMS *dp,
static HRESULT Math_floor(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, DISPPARAMS *dp,
VARIANT *retv, jsexcept_t *ei, IServiceProvider *sp)
{
VARIANT v;
......@@ -335,7 +335,7 @@ static HRESULT Math_floor(script_ctx_t *ctx, DispatchEx *dispex, WORD flags, DIS
return S_OK;
}
static HRESULT Math_log(script_ctx_t *ctx, DispatchEx *dispex, WORD flags, DISPPARAMS *dp,
static HRESULT Math_log(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, DISPPARAMS *dp,
VARIANT *retv, jsexcept_t *ei, IServiceProvider *sp)
{
VARIANT v;
......@@ -359,7 +359,7 @@ static HRESULT Math_log(script_ctx_t *ctx, DispatchEx *dispex, WORD flags, DISPP
}
/* ECMA-262 3rd Edition 15.8.2.11 */
static HRESULT Math_max(script_ctx_t *ctx, DispatchEx *dispex, WORD flags, DISPPARAMS *dp,
static HRESULT Math_max(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, DISPPARAMS *dp,
VARIANT *retv, jsexcept_t *ei, IServiceProvider *sp)
{
DOUBLE max, d;
......@@ -396,7 +396,7 @@ static HRESULT Math_max(script_ctx_t *ctx, DispatchEx *dispex, WORD flags, DISPP
}
/* ECMA-262 3rd Edition 15.8.2.12 */
static HRESULT Math_min(script_ctx_t *ctx, DispatchEx *dispex, WORD flags, DISPPARAMS *dp,
static HRESULT Math_min(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, DISPPARAMS *dp,
VARIANT *retv, jsexcept_t *ei, IServiceProvider *sp)
{
DOUBLE min, d;
......@@ -433,7 +433,7 @@ static HRESULT Math_min(script_ctx_t *ctx, DispatchEx *dispex, WORD flags, DISPP
}
/* ECMA-262 3rd Edition 15.8.2.13 */
static HRESULT Math_pow(script_ctx_t *ctx, DispatchEx *dispex, WORD flags, DISPPARAMS *dp,
static HRESULT Math_pow(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, DISPPARAMS *dp,
VARIANT *retv, jsexcept_t *ei, IServiceProvider *sp)
{
VARIANT x, y;
......@@ -460,7 +460,7 @@ static HRESULT Math_pow(script_ctx_t *ctx, DispatchEx *dispex, WORD flags, DISPP
}
/* ECMA-262 3rd Edition 15.8.2.14 */
static HRESULT Math_random(script_ctx_t *ctx, DispatchEx *dispex, WORD flags, DISPPARAMS *dp,
static HRESULT Math_random(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, DISPPARAMS *dp,
VARIANT *retv, jsexcept_t *ei, IServiceProvider *sp)
{
UINT r;
......@@ -477,7 +477,7 @@ static HRESULT Math_random(script_ctx_t *ctx, DispatchEx *dispex, WORD flags, DI
}
/* ECMA-262 3rd Edition 15.8.2.15 */
static HRESULT Math_round(script_ctx_t *ctx, DispatchEx *dispex, WORD flags, DISPPARAMS *dp,
static HRESULT Math_round(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, DISPPARAMS *dp,
VARIANT *retv, jsexcept_t *ei, IServiceProvider *sp)
{
VARIANT v;
......@@ -499,7 +499,7 @@ static HRESULT Math_round(script_ctx_t *ctx, DispatchEx *dispex, WORD flags, DIS
return S_OK;
}
static HRESULT Math_sin(script_ctx_t *ctx, DispatchEx *dispex, WORD flags, DISPPARAMS *dp,
static HRESULT Math_sin(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, DISPPARAMS *dp,
VARIANT *retv, jsexcept_t *ei, IServiceProvider *sp)
{
VARIANT v;
......@@ -520,7 +520,7 @@ static HRESULT Math_sin(script_ctx_t *ctx, DispatchEx *dispex, WORD flags, DISPP
return S_OK;
}
static HRESULT Math_sqrt(script_ctx_t *ctx, DispatchEx *dispex, WORD flags, DISPPARAMS *dp,
static HRESULT Math_sqrt(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, DISPPARAMS *dp,
VARIANT *retv, jsexcept_t *ei, IServiceProvider *sp)
{
VARIANT v;
......@@ -541,7 +541,7 @@ static HRESULT Math_sqrt(script_ctx_t *ctx, DispatchEx *dispex, WORD flags, DISP
return S_OK;
}
static HRESULT Math_tan(script_ctx_t *ctx, DispatchEx *dispex, WORD flags, DISPPARAMS *dp,
static HRESULT Math_tan(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, DISPPARAMS *dp,
VARIANT *retv, jsexcept_t *ei, IServiceProvider *sp)
{
VARIANT v;
......
......@@ -41,8 +41,19 @@ static const WCHAR toPrecisionW[] = {'t','o','P','r','e','c','i','s','i','o','n'
static const WCHAR valueOfW[] = {'v','a','l','u','e','O','f',0};
#define NUMBER_TOSTRING_BUF_SIZE 64
static inline NumberInstance *number_from_vdisp(vdisp_t *vdisp)
{
return (NumberInstance*)vdisp->u.jsdisp;
}
static inline NumberInstance *number_this(vdisp_t *jsthis)
{
return is_vclass(jsthis, JSCLASS_NUMBER) ? number_from_vdisp(jsthis) : NULL;
}
/* ECMA-262 3rd Edition 15.7.4.2 */
static HRESULT Number_toString(script_ctx_t *ctx, DispatchEx *dispex, WORD flags, DISPPARAMS *dp,
static HRESULT Number_toString(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, DISPPARAMS *dp,
VARIANT *retv, jsexcept_t *ei, IServiceProvider *sp)
{
NumberInstance *number;
......@@ -53,11 +64,9 @@ static HRESULT Number_toString(script_ctx_t *ctx, DispatchEx *dispex, WORD flags
TRACE("\n");
if(!is_class(dispex, JSCLASS_NUMBER))
if(!(number = number_this(jsthis)))
return throw_type_error(ctx, ei, IDS_NOT_NUM, NULL);
number = (NumberInstance*)dispex;
if(arg_cnt(dp)) {
hres = to_int32(ctx, get_arg(dp, 0), ei, &radix);
if(FAILED(hres))
......@@ -170,53 +179,53 @@ static HRESULT Number_toString(script_ctx_t *ctx, DispatchEx *dispex, WORD flags
return S_OK;
}
static HRESULT Number_toLocaleString(script_ctx_t *ctx, DispatchEx *dispex, WORD flags, DISPPARAMS *dp,
static HRESULT Number_toLocaleString(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, DISPPARAMS *dp,
VARIANT *retv, jsexcept_t *ei, IServiceProvider *sp)
{
FIXME("\n");
return E_NOTIMPL;
}
static HRESULT Number_toFixed(script_ctx_t *ctx, DispatchEx *dispex, WORD flags, DISPPARAMS *dp,
static HRESULT Number_toFixed(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, DISPPARAMS *dp,
VARIANT *retv, jsexcept_t *ei, IServiceProvider *sp)
{
FIXME("\n");
return E_NOTIMPL;
}
static HRESULT Number_toExponential(script_ctx_t *ctx, DispatchEx *dispex, WORD flags, DISPPARAMS *dp,
static HRESULT Number_toExponential(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, DISPPARAMS *dp,
VARIANT *retv, jsexcept_t *ei, IServiceProvider *sp)
{
FIXME("\n");
return E_NOTIMPL;
}
static HRESULT Number_toPrecision(script_ctx_t *ctx, DispatchEx *dispex, WORD flags, DISPPARAMS *dp,
static HRESULT Number_toPrecision(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, DISPPARAMS *dp,
VARIANT *retv, jsexcept_t *ei, IServiceProvider *sp)
{
FIXME("\n");
return E_NOTIMPL;
}
static HRESULT Number_valueOf(script_ctx_t *ctx, DispatchEx *dispex, WORD flags, DISPPARAMS *dp,
static HRESULT Number_valueOf(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, DISPPARAMS *dp,
VARIANT *retv, jsexcept_t *ei, IServiceProvider *sp)
{
NumberInstance *number;
TRACE("\n");
if(!is_class(dispex, JSCLASS_NUMBER))
if(!(number = number_this(jsthis)))
return throw_type_error(ctx, ei, IDS_NOT_NUM, NULL);
if(retv) {
NumberInstance *number = (NumberInstance*)dispex;
if(retv)
*retv = number->num;
}
return S_OK;
}
static HRESULT Number_value(script_ctx_t *ctx, DispatchEx *dispex, WORD flags, DISPPARAMS *dp,
static HRESULT Number_value(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, DISPPARAMS *dp,
VARIANT *retv, jsexcept_t *ei, IServiceProvider *sp)
{
NumberInstance *number = (NumberInstance*)dispex;
NumberInstance *number = number_from_vdisp(jsthis);
switch(flags) {
case INVOKE_FUNC:
......@@ -251,7 +260,7 @@ static const builtin_info_t Number_info = {
NULL
};
static HRESULT NumberConstr_value(script_ctx_t *ctx, DispatchEx *dispex, WORD flags, DISPPARAMS *dp,
static HRESULT NumberConstr_value(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, DISPPARAMS *dp,
VARIANT *retv, jsexcept_t *ei, IServiceProvider *sp)
{
VARIANT num;
......
......@@ -32,9 +32,11 @@ static const WCHAR isPrototypeOfW[] = {'i','s','P','r','o','t','o','t','y','p','
static const WCHAR default_valueW[] = {'[','o','b','j','e','c','t',' ','O','b','j','e','c','t',']',0};
static HRESULT Object_toString(script_ctx_t *ctx, DispatchEx *dispex, WORD flags, DISPPARAMS *dp,
static HRESULT Object_toString(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, DISPPARAMS *dp,
VARIANT *retv, jsexcept_t *ei, IServiceProvider *sp)
{
DispatchEx *jsdisp;
static const WCHAR formatW[] = {'[','o','b','j','e','c','t',' ','%','s',']',0};
static const WCHAR arrayW[] = {'A','r','r','a','y',0};
......@@ -53,71 +55,76 @@ static HRESULT Object_toString(script_ctx_t *ctx, DispatchEx *dispex, WORD flags
TRACE("\n");
if(names[dispex->builtin_info->class] == NULL) {
ERR("dispex->builtin_info->class = %d\n",
dispex->builtin_info->class);
jsdisp = get_jsdisp(jsthis);
if(!jsdisp || names[jsdisp->builtin_info->class] == NULL) {
FIXME("jdisp->builtin_info->class = %d\n", jsdisp->builtin_info->class);
return E_FAIL;
}
if(retv) {
V_VT(retv) = VT_BSTR;
V_BSTR(retv) = SysAllocStringLen(NULL, 9+strlenW(names[dispex->builtin_info->class]));
V_BSTR(retv) = SysAllocStringLen(NULL, 9+strlenW(names[jsdisp->builtin_info->class]));
if(!V_BSTR(retv))
return E_OUTOFMEMORY;
sprintfW(V_BSTR(retv), formatW, names[dispex->builtin_info->class]);
sprintfW(V_BSTR(retv), formatW, names[jsdisp->builtin_info->class]);
}
return S_OK;
}
static HRESULT Object_toLocaleString(script_ctx_t *ctx, DispatchEx *dispex, WORD flags, DISPPARAMS *dp,
static HRESULT Object_toLocaleString(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, DISPPARAMS *dp,
VARIANT *retv, jsexcept_t *ei, IServiceProvider *sp)
{
DISPPARAMS params = {NULL, NULL, 0, 0};
TRACE("\n");
return jsdisp_call_name(dispex, toStringW, DISPATCH_METHOD, &params, retv, ei, sp);
if(!is_jsdisp(jsthis)) {
FIXME("Host object this\n");
return E_FAIL;
}
return jsdisp_call_name(jsthis->u.jsdisp, toStringW, DISPATCH_METHOD, &params, retv, ei, sp);
}
static HRESULT Object_valueOf(script_ctx_t *ctx, DispatchEx *dispex, WORD flags, DISPPARAMS *dp,
static HRESULT Object_valueOf(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, DISPPARAMS *dp,
VARIANT *retv, jsexcept_t *ei, IServiceProvider *sp)
{
TRACE("\n");
if(retv) {
IDispatchEx_AddRef(_IDispatchEx_(dispex));
IDispatch_AddRef(jsthis->u.disp);
V_VT(retv) = VT_DISPATCH;
V_DISPATCH(retv) = (IDispatch*)_IDispatchEx_(dispex);
V_DISPATCH(retv) = jsthis->u.disp;
}
return S_OK;
}
static HRESULT Object_hasOwnProperty(script_ctx_t *ctx, DispatchEx *dispex, WORD flags, DISPPARAMS *dp,
static HRESULT Object_hasOwnProperty(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, DISPPARAMS *dp,
VARIANT *retv, jsexcept_t *ei, IServiceProvider *sp)
{
FIXME("\n");
return E_NOTIMPL;
}
static HRESULT Object_propertyIsEnumerable(script_ctx_t *ctx, DispatchEx *dispex, WORD flags, DISPPARAMS *dp,
static HRESULT Object_propertyIsEnumerable(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, DISPPARAMS *dp,
VARIANT *retv, jsexcept_t *ei, IServiceProvider *sp)
{
FIXME("\n");
return E_NOTIMPL;
}
static HRESULT Object_isPrototypeOf(script_ctx_t *ctx, DispatchEx *dispex, WORD flags, DISPPARAMS *dp,
static HRESULT Object_isPrototypeOf(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, DISPPARAMS *dp,
VARIANT *retv, jsexcept_t *ei, IServiceProvider *sp)
{
FIXME("\n");
return E_NOTIMPL;
}
static HRESULT Object_value(script_ctx_t *ctx, DispatchEx *dispex, WORD flags, DISPPARAMS *dp,
static HRESULT Object_value(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, DISPPARAMS *dp,
VARIANT *retv, jsexcept_t *ei, IServiceProvider *sp)
{
TRACE("\n");
......@@ -162,7 +169,7 @@ static const builtin_info_t Object_info = {
NULL
};
static HRESULT ObjectConstr_value(script_ctx_t *ctx, DispatchEx *dispex, WORD flags, DISPPARAMS *dp,
static HRESULT ObjectConstr_value(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, DISPPARAMS *dp,
VARIANT *retv, jsexcept_t *ei, IServiceProvider *caller)
{
HRESULT hres;
......
......@@ -3294,6 +3294,11 @@ out:
return re;
}
static inline RegExpInstance *regexp_from_vdisp(vdisp_t *vdisp)
{
return (RegExpInstance*)vdisp->u.jsdisp;
}
static HRESULT do_regexp_match_next(script_ctx_t *ctx, RegExpInstance *regexp, const WCHAR *str, DWORD len,
const WCHAR **cp, match_result_t **parens, DWORD *parens_size, DWORD *parens_cnt, match_result_t *ret)
{
......@@ -3425,14 +3430,14 @@ HRESULT regexp_match(script_ctx_t *ctx, DispatchEx *dispex, const WCHAR *str, DW
return S_OK;
}
static HRESULT RegExp_source(script_ctx_t *ctx, DispatchEx *dispex, WORD flags, DISPPARAMS *dp,
static HRESULT RegExp_source(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, DISPPARAMS *dp,
VARIANT *retv, jsexcept_t *ei, IServiceProvider *sp)
{
TRACE("\n");
switch(flags) {
case DISPATCH_PROPERTYGET: {
RegExpInstance *This = (RegExpInstance*)dispex;
RegExpInstance *This = regexp_from_vdisp(jsthis);
V_VT(retv) = VT_BSTR;
V_BSTR(retv) = SysAllocString(This->str);
......@@ -3448,35 +3453,35 @@ static HRESULT RegExp_source(script_ctx_t *ctx, DispatchEx *dispex, WORD flags,
return S_OK;
}
static HRESULT RegExp_global(script_ctx_t *ctx, DispatchEx *dispex, WORD flags, DISPPARAMS *dp,
static HRESULT RegExp_global(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, DISPPARAMS *dp,
VARIANT *retv, jsexcept_t *ei, IServiceProvider *sp)
{
FIXME("\n");
return E_NOTIMPL;
}
static HRESULT RegExp_ignoreCase(script_ctx_t *ctx, DispatchEx *dispex, WORD flags, DISPPARAMS *dp,
static HRESULT RegExp_ignoreCase(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, DISPPARAMS *dp,
VARIANT *retv, jsexcept_t *ei, IServiceProvider *sp)
{
FIXME("\n");
return E_NOTIMPL;
}
static HRESULT RegExp_multiline(script_ctx_t *ctx, DispatchEx *dispex, WORD flags, DISPPARAMS *dp,
static HRESULT RegExp_multiline(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, DISPPARAMS *dp,
VARIANT *retv, jsexcept_t *ei, IServiceProvider *sp)
{
FIXME("\n");
return E_NOTIMPL;
}
static HRESULT RegExp_lastIndex(script_ctx_t *ctx, DispatchEx *dispex, WORD flags, DISPPARAMS *dp,
static HRESULT RegExp_lastIndex(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, DISPPARAMS *dp,
VARIANT *retv, jsexcept_t *ei, IServiceProvider *sp)
{
TRACE("\n");
switch(flags) {
case DISPATCH_PROPERTYGET: {
RegExpInstance *regexp = (RegExpInstance*)dispex;
RegExpInstance *regexp = regexp_from_vdisp(jsthis);
V_VT(retv) = VT_I4;
V_I4(retv) = regexp->last_index;
break;
......@@ -3489,7 +3494,7 @@ static HRESULT RegExp_lastIndex(script_ctx_t *ctx, DispatchEx *dispex, WORD flag
return S_OK;
}
static HRESULT RegExp_toString(script_ctx_t *ctx, DispatchEx *dispex, WORD flags, DISPPARAMS *dp,
static HRESULT RegExp_toString(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, DISPPARAMS *dp,
VARIANT *retv, jsexcept_t *ei, IServiceProvider *sp)
{
FIXME("\n");
......@@ -3558,7 +3563,7 @@ static HRESULT create_match_array(script_ctx_t *ctx, BSTR input, const match_res
return S_OK;
}
static HRESULT run_exec(script_ctx_t *ctx, DispatchEx *dispex, VARIANT *arg, jsexcept_t *ei, BSTR *input,
static HRESULT run_exec(script_ctx_t *ctx, vdisp_t *jsthis, VARIANT *arg, jsexcept_t *ei, BSTR *input,
match_result_t *match, match_result_t **parens, DWORD *parens_cnt, VARIANT_BOOL *ret)
{
RegExpInstance *regexp;
......@@ -3567,12 +3572,12 @@ static HRESULT run_exec(script_ctx_t *ctx, DispatchEx *dispex, VARIANT *arg, jse
BSTR string;
HRESULT hres;
if(!is_class(dispex, JSCLASS_REGEXP)) {
if(!is_vclass(jsthis, JSCLASS_REGEXP)) {
FIXME("Not a RegExp\n");
return E_NOTIMPL;
}
regexp = (RegExpInstance*)dispex;
regexp = regexp_from_vdisp(jsthis);
if(arg) {
hres = to_string(ctx, arg, ei, &string);
......@@ -3609,7 +3614,7 @@ static HRESULT run_exec(script_ctx_t *ctx, DispatchEx *dispex, VARIANT *arg, jse
return S_OK;
}
static HRESULT RegExp_exec(script_ctx_t *ctx, DispatchEx *dispex, WORD flags, DISPPARAMS *dp,
static HRESULT RegExp_exec(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, DISPPARAMS *dp,
VARIANT *retv, jsexcept_t *ei, IServiceProvider *sp)
{
match_result_t *parens = NULL, match;
......@@ -3620,7 +3625,7 @@ static HRESULT RegExp_exec(script_ctx_t *ctx, DispatchEx *dispex, WORD flags, DI
TRACE("\n");
hres = run_exec(ctx, dispex, arg_cnt(dp) ? get_arg(dp,0) : NULL, ei, &string, &match, &parens, &parens_cnt, &b);
hres = run_exec(ctx, jsthis, arg_cnt(dp) ? get_arg(dp,0) : NULL, ei, &string, &match, &parens, &parens_cnt, &b);
if(FAILED(hres))
return hres;
......@@ -3643,7 +3648,7 @@ static HRESULT RegExp_exec(script_ctx_t *ctx, DispatchEx *dispex, WORD flags, DI
return hres;
}
static HRESULT RegExp_test(script_ctx_t *ctx, DispatchEx *dispex, WORD flags, DISPPARAMS *dp,
static HRESULT RegExp_test(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, DISPPARAMS *dp,
VARIANT *retv, jsexcept_t *ei, IServiceProvider *sp)
{
match_result_t match;
......@@ -3652,7 +3657,7 @@ static HRESULT RegExp_test(script_ctx_t *ctx, DispatchEx *dispex, WORD flags, DI
TRACE("\n");
hres = run_exec(ctx, dispex, arg_cnt(dp) ? get_arg(dp,0) : NULL, ei, NULL, &match, NULL, NULL, &b);
hres = run_exec(ctx, jsthis, arg_cnt(dp) ? get_arg(dp,0) : NULL, ei, NULL, &match, NULL, NULL, &b);
if(FAILED(hres))
return hres;
......@@ -3663,7 +3668,7 @@ static HRESULT RegExp_test(script_ctx_t *ctx, DispatchEx *dispex, WORD flags, DI
return S_OK;
}
static HRESULT RegExp_value(script_ctx_t *ctx, DispatchEx *dispex, WORD flags, DISPPARAMS *dp,
static HRESULT RegExp_value(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, DISPPARAMS *dp,
VARIANT *retv, jsexcept_t *ei, IServiceProvider *sp)
{
TRACE("\n");
......@@ -3828,7 +3833,7 @@ static HRESULT regexp_constructor(script_ctx_t *ctx, DISPPARAMS *dp, VARIANT *re
return S_OK;
}
static HRESULT RegExpConstr_value(script_ctx_t *ctx, DispatchEx *dispex, WORD flags, DISPPARAMS *dp,
static HRESULT RegExpConstr_value(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, DISPPARAMS *dp,
VARIANT *retv, jsexcept_t *ei, IServiceProvider *sp)
{
TRACE("\n");
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment