jscript: Added function constructor object.
This commit is contained in:
parent
4778c06903
commit
5e07e0cf53
|
@ -369,7 +369,21 @@ static const builtin_info_t Function_info = {
|
|||
NULL
|
||||
};
|
||||
|
||||
static HRESULT create_function(script_ctx_t *ctx, DWORD flags, DispatchEx *prototype, FunctionInstance **ret)
|
||||
static HRESULT FunctionConstr_value(DispatchEx *dispex, LCID lcid, WORD flags, DISPPARAMS *dp,
|
||||
VARIANT *retv, jsexcept_t *ei, IServiceProvider *sp)
|
||||
{
|
||||
FIXME("\n");
|
||||
return E_NOTIMPL;
|
||||
}
|
||||
|
||||
static HRESULT FunctionProt_value(DispatchEx *dispex, LCID lcid, WORD flags, DISPPARAMS *dp,
|
||||
VARIANT *retv, jsexcept_t *ei, IServiceProvider *sp)
|
||||
{
|
||||
FIXME("\n");
|
||||
return E_NOTIMPL;
|
||||
}
|
||||
|
||||
static HRESULT create_function(script_ctx_t *ctx, DWORD flags, BOOL funcprot, DispatchEx *prototype, FunctionInstance **ret)
|
||||
{
|
||||
FunctionInstance *function;
|
||||
HRESULT hres;
|
||||
|
@ -378,7 +392,10 @@ static HRESULT create_function(script_ctx_t *ctx, DWORD flags, DispatchEx *proto
|
|||
if(!function)
|
||||
return E_OUTOFMEMORY;
|
||||
|
||||
hres = init_dispex(&function->dispex, ctx, &Function_info, NULL);
|
||||
if(funcprot)
|
||||
hres = init_dispex(&function->dispex, ctx, &Function_info, prototype);
|
||||
else
|
||||
hres = init_dispex_from_constr(&function->dispex, ctx, &Function_info, ctx->function_constr);
|
||||
if(FAILED(hres))
|
||||
return hres;
|
||||
|
||||
|
@ -410,7 +427,7 @@ HRESULT create_builtin_function(script_ctx_t *ctx, builtin_invoke_t value_proc,
|
|||
FunctionInstance *function;
|
||||
HRESULT hres;
|
||||
|
||||
hres = create_function(ctx, flags, prototype, &function);
|
||||
hres = create_function(ctx, flags, FALSE, prototype, &function);
|
||||
if(FAILED(hres))
|
||||
return hres;
|
||||
|
||||
|
@ -433,7 +450,7 @@ HRESULT create_source_function(parser_ctx_t *ctx, parameter_t *parameters, sourc
|
|||
if(FAILED(hres))
|
||||
return hres;
|
||||
|
||||
hres = create_function(ctx->script, PROPF_CONSTR, prototype, &function);
|
||||
hres = create_function(ctx->script, PROPF_CONSTR, FALSE, prototype, &function);
|
||||
jsdisp_release(prototype);
|
||||
if(FAILED(hres))
|
||||
return hres;
|
||||
|
@ -456,3 +473,24 @@ HRESULT create_source_function(parser_ctx_t *ctx, parameter_t *parameters, sourc
|
|||
*ret = &function->dispex;
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
HRESULT init_function_constr(script_ctx_t *ctx)
|
||||
{
|
||||
FunctionInstance *prot, *constr;
|
||||
HRESULT hres;
|
||||
|
||||
hres = create_function(ctx, PROPF_CONSTR, TRUE, NULL, &prot);
|
||||
if(FAILED(hres))
|
||||
return hres;
|
||||
|
||||
prot->value_proc = FunctionProt_value;
|
||||
|
||||
hres = create_function(ctx, PROPF_CONSTR, TRUE, &prot->dispex, &constr);
|
||||
jsdisp_release(&prot->dispex);
|
||||
if(FAILED(hres))
|
||||
return hres;
|
||||
|
||||
constr->value_proc = FunctionConstr_value;
|
||||
ctx->function_constr = &constr->dispex;
|
||||
return hres;
|
||||
}
|
||||
|
|
|
@ -106,8 +106,9 @@ static HRESULT JSGlobal_Date(DispatchEx *dispex, LCID lcid, WORD flags, DISPPARA
|
|||
static HRESULT JSGlobal_Function(DispatchEx *dispex, LCID lcid, WORD flags, DISPPARAMS *dp,
|
||||
VARIANT *retv, jsexcept_t *ei, IServiceProvider *sp)
|
||||
{
|
||||
FIXME("\n");
|
||||
return E_NOTIMPL;
|
||||
TRACE("\n");
|
||||
|
||||
return constructor_call(dispex->ctx->function_constr, lcid, flags, dp, retv, ei, sp);
|
||||
}
|
||||
|
||||
static HRESULT JSGlobal_Number(DispatchEx *dispex, LCID lcid, WORD flags, DISPPARAMS *dp,
|
||||
|
@ -332,6 +333,10 @@ static HRESULT init_constructors(script_ctx_t *ctx)
|
|||
{
|
||||
HRESULT hres;
|
||||
|
||||
hres = init_function_constr(ctx);
|
||||
if(FAILED(hres))
|
||||
return hres;
|
||||
|
||||
hres = create_array_constr(ctx, &ctx->array_constr);
|
||||
if(FAILED(hres))
|
||||
return hres;
|
||||
|
|
|
@ -165,6 +165,7 @@ struct _script_ctx_t {
|
|||
|
||||
DispatchEx *script_disp;
|
||||
DispatchEx *global;
|
||||
DispatchEx *function_constr;
|
||||
DispatchEx *array_constr;
|
||||
DispatchEx *bool_constr;
|
||||
DispatchEx *number_constr;
|
||||
|
@ -181,6 +182,7 @@ static inline void script_addref(script_ctx_t *ctx)
|
|||
}
|
||||
|
||||
HRESULT init_global(script_ctx_t*);
|
||||
HRESULT init_function_constr(script_ctx_t*);
|
||||
|
||||
HRESULT create_array_constr(script_ctx_t*,DispatchEx**);
|
||||
HRESULT create_bool_constr(script_ctx_t*,DispatchEx**);
|
||||
|
|
|
@ -79,6 +79,12 @@ ok(Number.prototype !== undefined, "Number.prototype is undefined");
|
|||
ok(RegExp.prototype !== undefined, "RegExp.prototype is undefined");
|
||||
ok(Math !== undefined, "Math is undefined");
|
||||
ok(Math.prototype === undefined, "Math.prototype is not undefined");
|
||||
ok(Function.prototype !== undefined, "Function.prototype is undefined");
|
||||
ok(Function.prototype.prototype === undefined, "Function.prototype is not undefined");
|
||||
|
||||
Function.prototype.test = true;
|
||||
ok(testFunc1.test === true, "testFunc1.test !== true");
|
||||
ok(Function.test === true, "Function.test !== true");
|
||||
|
||||
ok(typeof(0) === "number", "typeof(0) is not number");
|
||||
ok(typeof(1.5) === "number", "typeof(1.5) is not number");
|
||||
|
|
Loading…
Reference in New Issue