summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorOlivier Goffart <ogoffart@trolltech.com>2009-08-04 11:36:06 (GMT)
committerOlivier Goffart <ogoffart@trolltech.com>2009-08-04 13:35:16 (GMT)
commitcd23e93e30be026a6bd4a9d5e3d3cbec3cf97621 (patch)
treed62bd5eac08af7ff701035a5337686471bc4c13e
parent109b4d19e2c677c3eafaf6b4a9df605cb3aeb481 (diff)
downloadQt-cd23e93e30be026a6bd4a9d5e3d3cbec3cf97621.zip
Qt-cd23e93e30be026a6bd4a9d5e3d3cbec3cf97621.tar.gz
Qt-cd23e93e30be026a6bd4a9d5e3d3cbec3cf97621.tar.bz2
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
-rw-r--r--src/script/api/qscriptcontext.cpp7
1 files 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;
}