jscript: Create arguments object as a seaprated class inheriting from Object.

This commit is contained in:
Jacek Caban 2009-08-29 00:01:57 +02:00 committed by Alexandre Julliard
parent 2a457fb701
commit 662efe835b
5 changed files with 62 additions and 20 deletions

View File

@ -85,22 +85,58 @@ static HRESULT init_parameters(DispatchEx *var_disp, FunctionInstance *function,
return S_OK;
}
static HRESULT init_arguments(DispatchEx *arg_disp, FunctionInstance *function, LCID lcid, DISPPARAMS *dp,
jsexcept_t *ei, IServiceProvider *caller)
HRESULT Arguments_value(DispatchEx *dispex, LCID lcid, WORD flags, DISPPARAMS *dp,
VARIANT *retv, jsexcept_t *ei, IServiceProvider *caller)
{
FIXME("\n");
return E_NOTIMPL;
}
static const builtin_info_t Arguments_info = {
JSCLASS_ARGUMENTS,
{NULL, Arguments_value, 0},
0, NULL,
NULL,
NULL
};
static HRESULT create_arguments(script_ctx_t *ctx, LCID lcid, DISPPARAMS *dp,
jsexcept_t *ei, IServiceProvider *caller, DispatchEx **ret)
{
DispatchEx *args;
VARIANT var;
DWORD i;
HRESULT hres;
for(i=0; i < dp->cArgs-dp->cNamedArgs; i++) {
hres = jsdisp_propput_idx(arg_disp, i, lcid, dp->rgvarg+dp->cArgs-1-i, ei, caller);
if(FAILED(hres))
args = heap_alloc_zero(sizeof(DispatchEx));
if(!args)
return E_OUTOFMEMORY;
hres = init_dispex_from_constr(args, ctx, &Arguments_info, ctx->object_constr);
if(FAILED(hres)) {
heap_free(args);
return hres;
}
for(i=0; i < arg_cnt(dp); i++) {
hres = jsdisp_propput_idx(args, i, lcid, get_arg(dp,i), ei, caller);
if(FAILED(hres))
break;
}
if(SUCCEEDED(hres)) {
V_VT(&var) = VT_I4;
V_I4(&var) = dp->cArgs - dp->cNamedArgs;
return jsdisp_propput_name(arg_disp, lengthW, lcid, &var, ei, caller);
V_I4(&var) = arg_cnt(dp);
hres = jsdisp_propput_name(args, lengthW, lcid, &var, ei, caller);
}
if(FAILED(hres)) {
jsdisp_release(args);
return hres;
}
*ret = args;
return S_OK;
}
static HRESULT create_var_disp(FunctionInstance *function, LCID lcid, DISPPARAMS *dp, jsexcept_t *ei,
@ -115,17 +151,13 @@ static HRESULT create_var_disp(FunctionInstance *function, LCID lcid, DISPPARAMS
if(FAILED(hres))
return hres;
hres = create_dispex(function->dispex.ctx, NULL, NULL, &arg_disp);
if(SUCCEEDED(hres)) {
hres = init_arguments(arg_disp, function, lcid, dp, ei, caller);
hres = create_arguments(function->dispex.ctx, lcid, dp, ei, caller, &arg_disp);
if(SUCCEEDED(hres)) {
VARIANT var;
V_VT(&var) = VT_DISPATCH;
V_DISPATCH(&var) = (IDispatch*)_IDispatchEx_(arg_disp);
hres = jsdisp_propput_name(var_disp, argumentsW, lcid, &var, ei, caller);
}
jsdisp_release(arg_disp);
}

View File

@ -69,6 +69,7 @@ extern HINSTANCE jscript_hinstance;
#define PROPF_ENUM 0x0200
#define PROPF_CONSTR 0x0400
/* NOTE: Keep in sync with names in Object.toString implementation */
typedef enum {
JSCLASS_NONE,
JSCLASS_ARRAY,
@ -81,7 +82,8 @@ typedef enum {
JSCLASS_NUMBER,
JSCLASS_OBJECT,
JSCLASS_REGEXP,
JSCLASS_STRING
JSCLASS_STRING,
JSCLASS_ARGUMENTS
} jsclass_t;
typedef HRESULT (*builtin_invoke_t)(DispatchEx*,LCID,WORD,DISPPARAMS*,VARIANT*,jsexcept_t*,IServiceProvider*);

View File

@ -49,7 +49,7 @@ static HRESULT Object_toString(DispatchEx *dispex, LCID lcid, WORD flags, DISPPA
static const WCHAR stringW[] = {'S','t','r','i','n','g',0};
/* Keep in sync with jsclass_t enum */
static const WCHAR *names[] = {NULL, arrayW, booleanW, dateW, errorW,
functionW, NULL, mathW, numberW, objectW, regexpW, stringW};
functionW, NULL, mathW, numberW, objectW, regexpW, stringW, objectW};
TRACE("\n");

View File

@ -1422,6 +1422,8 @@ testObjectInherit(new Error(), Error, false, true, true);
testObjectInherit(testObjectInherit, Function, false, true, true);
testObjectInherit(Math, Object, true, true, true);
(function() { testObjectInherit(arguments, Object, true, true, true); })();
function testFunctions(obj, arr) {
var l;

View File

@ -811,6 +811,12 @@ ok((1 instanceof Object) === false, "1 is instance of Object");
ok((false instanceof Boolean) === false, "false is instance of Boolean");
ok(("" instanceof Object) === false, "'' is instance of Object");
(function () {
ok((arguments instanceof Object) === true, "argument is not instance of Object");
ok((arguments instanceof Array) === false, "argument is not instance of Array");
ok(arguments.toString() === "[object Object]", "arguments.toString() = " + arguments.toString());
})(1,2);
ok(isNaN(NaN) === true, "isNaN(NaN) !== true");
ok(isNaN(0.5) === false, "isNaN(0.5) !== false");
ok(isNaN(Infinity) === false, "isNaN(Infinity) !== false");