summaryrefslogtreecommitdiffstats
path: root/src/script/api/qscriptcontextinfo.cpp
diff options
context:
space:
mode:
authorOlivier Goffart <ogoffart@trolltech.com>2009-08-11 07:35:50 (GMT)
committerOlivier Goffart <ogoffart@trolltech.com>2009-08-11 07:44:24 (GMT)
commit81d8292e486bce768d9af27e3510520a769c4fa8 (patch)
treef2925d15dc89a6bb64b34ecf162d6ac9fa5e312d /src/script/api/qscriptcontextinfo.cpp
parent62281ca6f9e74a5c8b66204d74ceec0215ecab92 (diff)
downloadQt-81d8292e486bce768d9af27e3510520a769c4fa8.zip
Qt-81d8292e486bce768d9af27e3510520a769c4fa8.tar.gz
Qt-81d8292e486bce768d9af27e3510520a769c4fa8.tar.bz2
Fix line number and arguments in QScriptContext::toString
For arguments, we always need to skip the implicit 'this' argument For line number, we walk thought the stack frames from the top to find the one above the requested one, which contains the returnPC we need. Also fixed a crash because QScriptContext::parentContext would have returned a pointer with flags inside. Reviewed-by: Kent Hansen
Diffstat (limited to 'src/script/api/qscriptcontextinfo.cpp')
-rw-r--r--src/script/api/qscriptcontextinfo.cpp20
1 files changed, 18 insertions, 2 deletions
diff --git a/src/script/api/qscriptcontextinfo.cpp b/src/script/api/qscriptcontextinfo.cpp
index 52776e2..20b77f0 100644
--- a/src/script/api/qscriptcontextinfo.cpp
+++ b/src/script/api/qscriptcontextinfo.cpp
@@ -174,8 +174,6 @@ QScriptContextInfoPrivate::QScriptContextInfoPrivate(const QScriptContext *conte
for (size_t i = 0; i < body->parameterCount(); ++i)
parameterNames.append(QScript::qtStringFromJSCUString(params[i].ustring()));
// ### get the function name from the AST
- // ### don't know the PC, since it's not stored in the frame
- // lineNumber = codeBlock->expressionRangeForBytecodeOffset(...);
} else if (callee && callee->isObject(&QScript::QtFunction::info)) {
functionType = QScriptContextInfo::QtFunction;
// ### the slot can be overloaded -- need to get the particular overload from the context
@@ -192,6 +190,24 @@ QScriptContextInfoPrivate::QScriptContextInfoPrivate(const QScriptContext *conte
functionType = QScriptContextInfo::QtPropertyFunction;
functionMetaIndex = static_cast<QScript::QtPropertyFunction*>(callee)->propertyIndex();
}
+
+ // get the lineNumber:
+ QScriptContext *rewindContext = context->engine()->currentContext();
+ if (rewindContext == context) {
+ //ignore native function
+ } else {
+ // rewind the stack from the top in order to find the frame from the caller where the returnPC is stored
+ while (rewindContext && rewindContext->parentContext() != context)
+ rewindContext = rewindContext->parentContext();
+ if (rewindContext) {
+ JSC::Instruction *returnPC = QScriptEnginePrivate::frameForContext(rewindContext)->returnPC();
+ JSC::CodeBlock *codeBlock = frame->codeBlock();
+ if (returnPC && codeBlock) {
+ lineNumber = codeBlock->lineNumberForBytecodeOffset(const_cast<JSC::ExecState *>(frame),
+ returnPC - codeBlock->instructions().begin());
+ }
+ }
+ }
}
/*!