From cd23e93e30be026a6bd4a9d5e3d3cbec3cf97621 Mon Sep 17 00:00:00 2001 From: Olivier Goffart Date: Tue, 4 Aug 2009 13:36:06 +0200 Subject: Use a more reliable method to dinstinguish between an op_call and an op_construct The two opcode operand looks like this. -7 -6 -5 -4 -3 -2 -1 op_construct dst(r) func(r) argCount(n) registerOffset(n) proto(r) thisRegister(r) op_call dst(r) func(r) argCount(n) registerOffset(n) as the registerOffset must always be bigger than any register we can use that knoweldge to differenciate the two calls Note that this is only the fallback used for JavaScript function. native function still uses the QScriptActivationObject Reviewed-by: Kent Hansen --- src/script/api/qscriptcontext.cpp | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/script/api/qscriptcontext.cpp b/src/script/api/qscriptcontext.cpp index 99b8989..852ed6b 100644 --- a/src/script/api/qscriptcontext.cpp +++ b/src/script/api/qscriptcontext.cpp @@ -357,8 +357,11 @@ bool QScriptContext::isCalledAsConstructor() const if (returnPC[-JSC::op_construct_length].u.opcode == frame->interpreter()->getOpcode(JSC::op_construct)) { //We are maybe called from the op_construct opcode which has 6 opperands. - //But we need to check we are not called from op_call with 4 opperands (by checking the argc operand) - return returnPC[-4].u.operand == frame->argumentCount(); + //But we need to check we are not called from op_call with 4 opperands + + //we make sure that the returnPC[-1] (thisRegister) is smaller than the returnPC[-3] (registerOffset) + //as if it was an op_call, the returnPC[-1] would be the registerOffset, bigger than returnPC[-3] (funcRegister) + return returnPC[-1].u.operand < returnPC[-3].u.operand; } return false; } -- cgit v0.12