summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/script/api/qscriptcontextinfo.cpp52
-rw-r--r--tests/auto/qscriptcontext/tst_qscriptcontext.cpp7
-rw-r--r--tests/auto/qscriptcontextinfo/tst_qscriptcontextinfo.cpp4
3 files changed, 36 insertions, 27 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());
- }
- }
- }
}
/*!
diff --git a/tests/auto/qscriptcontext/tst_qscriptcontext.cpp b/tests/auto/qscriptcontext/tst_qscriptcontext.cpp
index 36c680d..dfa0b8b 100644
--- a/tests/auto/qscriptcontext/tst_qscriptcontext.cpp
+++ b/tests/auto/qscriptcontext/tst_qscriptcontext.cpp
@@ -557,9 +557,9 @@ void tst_QScriptContext::backtrace()
QString fileName = "testfile";
QStringList expected;
- expected << "<native>(123)@:-1"
- << "foo(hello,[object Object])@testfile:2"
- << "<global>()@testfile:4";
+ expected << "<native> (123) at -1"
+ << "foo ([object Object], [object global]) at testfile:2"
+ << "<global> () at testfile:4";
QScriptValue ret = eng.evaluate(
"function foo() {\n"
@@ -569,7 +569,6 @@ void tst_QScriptContext::backtrace()
QVERIFY(ret.isArray());
QStringList slist = qscriptvalue_cast<QStringList>(ret);
- QEXPECT_FAIL("", "Backtrace is not correct", Continue);
QCOMPARE(slist, expected);
}
diff --git a/tests/auto/qscriptcontextinfo/tst_qscriptcontextinfo.cpp b/tests/auto/qscriptcontextinfo/tst_qscriptcontextinfo.cpp
index 7ca6728..91cd2cb 100644
--- a/tests/auto/qscriptcontextinfo/tst_qscriptcontextinfo.cpp
+++ b/tests/auto/qscriptcontextinfo/tst_qscriptcontextinfo.cpp
@@ -149,10 +149,10 @@ void tst_QScriptContextInfo::nativeFunction()
QScriptContextInfo info = lst.at(1);
QVERIFY(!info.isNull());
QCOMPARE(info.functionType(), QScriptContextInfo::NativeFunction);
- QEXPECT_FAIL("", "Script ID isn't valid for evaluate() call", Abort);
QVERIFY(info.scriptId() != -1);
QCOMPARE(info.fileName(), fileName);
QCOMPARE(info.lineNumber(), lineNumber);
+ QEXPECT_FAIL("", "columnNumber doesn't work", Continue);
QCOMPARE(info.columnNumber(), 1);
QCOMPARE(info.functionName(), QString());
QCOMPARE(info.functionEndLineNumber(), -1);
@@ -200,10 +200,10 @@ void tst_QScriptContextInfo::scriptFunction()
// evaluate()
QScriptContextInfo info = lst.at(2);
QCOMPARE(info.functionType(), QScriptContextInfo::NativeFunction);
- QEXPECT_FAIL("", "Script ID is invalid for evaluate() call", Abort);
QVERIFY(info.scriptId() != -1);
QCOMPARE(info.fileName(), fileName);
QCOMPARE(info.lineNumber(), lineNumber + 3);
+ QEXPECT_FAIL("", "columnNumber doesn't work", Continue);
QCOMPARE(info.columnNumber(), 1);
QCOMPARE(info.functionName(), QString());
QCOMPARE(info.functionEndLineNumber(), -1);