diff options
author | Olivier Goffart <ogoffart@trolltech.com> | 2009-08-14 12:33:33 (GMT) |
---|---|---|
committer | Olivier Goffart <ogoffart@trolltech.com> | 2009-08-14 14:44:25 (GMT) |
commit | eaeaad09383871d40002d9e1ded1d56390839e4b (patch) | |
tree | 57954ae472a87b539b86439fccd6f680206c768d /src/script/api | |
parent | e21e9b5a400115291c883b9b85055a8355f3a30b (diff) | |
download | Qt-eaeaad09383871d40002d9e1ded1d56390839e4b.zip Qt-eaeaad09383871d40002d9e1ded1d56390839e4b.tar.gz Qt-eaeaad09383871d40002d9e1ded1d56390839e4b.tar.bz2 |
Polish the QScriptContext::backtrace()
- in QScriptContextInfo, get the filename of specials context
- in QScriptContextInfo, get the right information for the global
context (from the skipped fake frame)
- addapt the test to the current backtrace layout.
Diffstat (limited to 'src/script/api')
-rw-r--r-- | src/script/api/qscriptcontextinfo.cpp | 52 |
1 files changed, 31 insertions, 21 deletions
diff --git a/src/script/api/qscriptcontextinfo.cpp b/src/script/api/qscriptcontextinfo.cpp index f8e4a54..294c48a 100644 --- a/src/script/api/qscriptcontextinfo.cpp +++ b/src/script/api/qscriptcontextinfo.cpp @@ -160,14 +160,42 @@ QScriptContextInfoPrivate::QScriptContextInfoPrivate(const QScriptContext *conte columnNumber = -1; const JSC::ExecState *frame = QScriptEnginePrivate::frameForContext(context); + + // Get the line number: + + //We need to know the context directly up in the backtrace, in order to get the line number, and adjust the global context + QScriptContext *rewindContext = context->engine()->currentContext(); + if (rewindContext != context) { //ignore top context (native function) + // 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::ExecState *aboveFrame = QScriptEnginePrivate::frameForContext(rewindContext); + frame = aboveFrame->callerFrame()->removeHostCallFrameFlag(); //it will be different for the global context. + + JSC::Instruction *returnPC = aboveFrame->returnPC(); + JSC::CodeBlock *codeBlock = frame->codeBlock(); + if (returnPC && codeBlock) { + lineNumber = codeBlock->lineNumberForBytecodeOffset(const_cast<JSC::ExecState *>(frame), + returnPC - codeBlock->instructions().begin()); + } + } + } + + // Get the filename and the scriptId: + JSC::CodeBlock *codeBlock = frame->codeBlock(); + if (codeBlock) { + JSC::SourceProvider *source = codeBlock->source(); + scriptId = source->asID(); + fileName = QScript::qtStringFromJSCUString(source->url()); + } + + // Get the others informations: JSC::JSObject *callee = frame->callee(); if (callee && callee->isObject(&JSC::InternalFunction::info)) functionName = QScript::qtStringFromJSCUString(JSC::asInternalFunction(callee)->name(&frame->globalData())); if (callee && callee->isObject(&JSC::JSFunction::info)) { functionType = QScriptContextInfo::ScriptFunction; - JSC::SourceProvider *source = frame->codeBlock()->source(); - scriptId = source->asID(); - fileName = QScript::qtStringFromJSCUString(source->url()); JSC::FunctionBodyNode *body = JSC::asFunction(callee)->body(); functionStartLineNumber = body->firstLine(); functionEndLineNumber = body->lastLine(); @@ -191,24 +219,6 @@ 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()); - } - } - } } /*! |