From cf8029717c85967abc787425e65ec8b43f896372 Mon Sep 17 00:00:00 2001 From: Jacek Caban Date: Mon, 16 Jul 2012 15:30:54 +0200 Subject: [PATCH] jscript: Properly set Number.prototyp.constructor. --- dlls/jscript/function.c | 25 +++++++++++++++++++++++++ dlls/jscript/jscript.h | 2 ++ dlls/jscript/number.c | 2 +- dlls/jscript/tests/lang.js | 2 ++ 4 files changed, 30 insertions(+), 1 deletion(-) diff --git a/dlls/jscript/function.c b/dlls/jscript/function.c index 618831b4a97..765efccba6b 100644 --- a/dlls/jscript/function.c +++ b/dlls/jscript/function.c @@ -639,6 +639,31 @@ HRESULT create_builtin_function(script_ctx_t *ctx, builtin_invoke_t value_proc, return S_OK; } +HRESULT create_builtin_constructor(script_ctx_t *ctx, builtin_invoke_t value_proc, const WCHAR *name, + const builtin_info_t *builtin_info, DWORD flags, jsdisp_t *prototype, jsdisp_t **ret) +{ + jsdisp_t *constr; + VARIANT v; + HRESULT hres; + + static const WCHAR constructorW[] = {'c','o','n','s','t','r','u','c','t','o','r',0}; + + hres = create_builtin_function(ctx, value_proc, name, builtin_info, flags, prototype, &constr); + if(FAILED(hres)) + return hres; + + V_VT(&v) = VT_DISPATCH; + V_DISPATCH(&v) = to_disp(constr); + hres = jsdisp_propput_name(prototype, constructorW, &v, NULL); + if(FAILED(hres)) { + jsdisp_release(constr); + return hres; + } + + *ret = constr; + return S_OK; +} + HRESULT create_source_function(script_ctx_t *ctx, bytecode_t *code, function_code_t *func_code, scope_chain_t *scope_chain, jsdisp_t **ret) { diff --git a/dlls/jscript/jscript.h b/dlls/jscript/jscript.h index 11b6ec93ab9..ca91ee69abf 100644 --- a/dlls/jscript/jscript.h +++ b/dlls/jscript/jscript.h @@ -225,6 +225,8 @@ VARIANT_BOOL jsdisp_is_own_prop(jsdisp_t *obj, BSTR name) DECLSPEC_HIDDEN; HRESULT create_builtin_function(script_ctx_t*,builtin_invoke_t,const WCHAR*,const builtin_info_t*,DWORD, jsdisp_t*,jsdisp_t**) DECLSPEC_HIDDEN; +HRESULT create_builtin_constructor(script_ctx_t*,builtin_invoke_t,const WCHAR*,const builtin_info_t*,DWORD, + jsdisp_t*,jsdisp_t**) DECLSPEC_HIDDEN; HRESULT Function_value(script_ctx_t*,vdisp_t*,WORD,unsigned,VARIANT*,VARIANT*,jsexcept_t*) DECLSPEC_HIDDEN; HRESULT Function_invoke(jsdisp_t*,IDispatch*,WORD,unsigned,VARIANT*,VARIANT*,jsexcept_t*); diff --git a/dlls/jscript/number.c b/dlls/jscript/number.c index c62d985f4da..d2de7905276 100644 --- a/dlls/jscript/number.c +++ b/dlls/jscript/number.c @@ -625,7 +625,7 @@ HRESULT create_number_constr(script_ctx_t *ctx, jsdisp_t *object_prototype, jsdi return hres; number->value = 0; - hres = create_builtin_function(ctx, NumberConstr_value, NumberW, NULL, + hres = create_builtin_constructor(ctx, NumberConstr_value, NumberW, NULL, PROPF_CONSTR|1, &number->dispex, ret); jsdisp_release(&number->dispex); diff --git a/dlls/jscript/tests/lang.js b/dlls/jscript/tests/lang.js index 308e0c9d31c..75306f10a94 100644 --- a/dlls/jscript/tests/lang.js +++ b/dlls/jscript/tests/lang.js @@ -91,6 +91,8 @@ ok(Function.prototype.prototype === undefined, "Function.prototype.prototype is ok(Date.prototype !== undefined, "Date.prototype is undefined"); ok(Date.prototype.prototype === undefined, "Date.prototype is not undefined"); +ok(Number.prototype.constructor === Number, "Number.prototype.constructor !== Number"); + Function.prototype.test = true; ok(testFunc1.test === true, "testFunc1.test !== true"); ok(Function.test === true, "Function.test !== true"); -- 2.11.4.GIT