From fbb763a53e92a38436acf5f542f213b85491f086 Mon Sep 17 00:00:00 2001 From: Jacek Caban Date: Mon, 19 Oct 2009 20:42:03 +0200 Subject: [PATCH] jscript: Use the value returned from constructor in 'new' expression if the value if an object. --- dlls/jscript/function.c | 11 +++++++++-- dlls/jscript/tests/lang.js | 15 +++++++++++++++ 2 files changed, 24 insertions(+), 2 deletions(-) diff --git a/dlls/jscript/function.c b/dlls/jscript/function.c index 64e645a134..faf2daaad9 100644 --- a/dlls/jscript/function.c +++ b/dlls/jscript/function.c @@ -226,20 +226,27 @@ static HRESULT invoke_constructor(script_ctx_t *ctx, FunctionInstance *function, VARIANT *retv, jsexcept_t *ei, IServiceProvider *caller) { DispatchEx *this_obj; + VARIANT var; HRESULT hres; hres = create_object(ctx, &function->dispex, &this_obj); if(FAILED(hres)) return hres; - hres = invoke_source(ctx, function, (IDispatch*)_IDispatchEx_(this_obj), dp, retv, ei, caller); + hres = invoke_source(ctx, function, (IDispatch*)_IDispatchEx_(this_obj), dp, &var, ei, caller); if(FAILED(hres)) { jsdisp_release(this_obj); return hres; } V_VT(retv) = VT_DISPATCH; - V_DISPATCH(retv) = (IDispatch*)_IDispatchEx_(this_obj); + if(V_VT(&var) == VT_DISPATCH) { + jsdisp_release(this_obj); + V_DISPATCH(retv) = V_DISPATCH(&var); + }else { + VariantClear(&var); + V_DISPATCH(retv) = (IDispatch*)_IDispatchEx_(this_obj); + } return S_OK; } diff --git a/dlls/jscript/tests/lang.js b/dlls/jscript/tests/lang.js index db08b2121c..9bb0944070 100644 --- a/dlls/jscript/tests/lang.js +++ b/dlls/jscript/tests/lang.js @@ -148,6 +148,21 @@ obj2.pvar = 3; testConstr1.prototype.pvar = 1; ok(obj2.pvar === 3, "obj2.pvar is not 3"); +obj1 = new Object(); +function testConstr3() { + return obj1; +} + +obj2 = new testConstr3(); +ok(obj1 === obj2, "obj1 != obj2"); + +function testConstr4() { + return 2; +} + +obj2 = new testConstr3(); +ok(typeof(obj2) === "object", "typeof(obj2) = " + typeof(obj2)); + var obj3 = new Object; ok(typeof(obj3) === "object", "typeof(obj3) is not object");