Jacek Caban : jscript: Added function constructor object.
Alexandre Julliard
julliard at winehq.org
Fri Sep 19 07:14:55 CDT 2008
Module: wine
Branch: master
Commit: 5e07e0cf53357432002bd0804987cf102f677a72
URL: http://source.winehq.org/git/wine.git/?a=commit;h=5e07e0cf53357432002bd0804987cf102f677a72
Author: Jacek Caban <jacek at codeweavers.com>
Date: Fri Sep 19 00:46:26 2008 +0200
jscript: Added function constructor object.
---
dlls/jscript/function.c | 46 ++++++++++++++++++++++++++++++++++++++++---
dlls/jscript/global.c | 9 ++++++-
dlls/jscript/jscript.h | 2 +
dlls/jscript/tests/lang.js | 6 +++++
4 files changed, 57 insertions(+), 6 deletions(-)
diff --git a/dlls/jscript/function.c b/dlls/jscript/function.c
index 4c07cb3..7d39ad0 100644
--- a/dlls/jscript/function.c
+++ b/dlls/jscript/function.c
@@ -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;
+}
diff --git a/dlls/jscript/global.c b/dlls/jscript/global.c
index 70983fc..4404bff 100644
--- a/dlls/jscript/global.c
+++ b/dlls/jscript/global.c
@@ -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;
diff --git a/dlls/jscript/jscript.h b/dlls/jscript/jscript.h
index 603b279..6c4e272 100644
--- a/dlls/jscript/jscript.h
+++ b/dlls/jscript/jscript.h
@@ -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**);
diff --git a/dlls/jscript/tests/lang.js b/dlls/jscript/tests/lang.js
index 3a24864..83732a2 100644
--- a/dlls/jscript/tests/lang.js
+++ b/dlls/jscript/tests/lang.js
@@ -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");
More information about the wine-cvs
mailing list