Change ExecutionContext::getFunctionObject() to getFunction()
And return a QV4::Function from now on. This simplifies code in other places and provides all the info required for stack traces and debugging. Change-Id: I512a8ac3932268d8cfc60675e75c4661d1f16fd8 Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
This commit is contained in:
parent
54c79346f1
commit
b4ccdf004a
|
@ -336,18 +336,16 @@ void NativeDebugger::handleBacktrace(QJsonObject *response, const QJsonObject &a
|
||||||
QJsonArray frameArray;
|
QJsonArray frameArray;
|
||||||
QV4::ExecutionContext *executionContext = m_engine->currentContext;
|
QV4::ExecutionContext *executionContext = m_engine->currentContext;
|
||||||
for (int i = 0; i < limit && executionContext; ++i) {
|
for (int i = 0; i < limit && executionContext; ++i) {
|
||||||
QV4::Heap::FunctionObject *heapFunctionObject = executionContext->getFunctionObject();
|
if (QV4::Function *function = executionContext->getFunction()) {
|
||||||
if (heapFunctionObject) {
|
|
||||||
|
|
||||||
QJsonObject frame;
|
QJsonObject frame;
|
||||||
frame[QStringLiteral("language")] = QStringLiteral("js");
|
frame[QStringLiteral("language")] = QStringLiteral("js");
|
||||||
frame[QStringLiteral("context")] = encodeContext(executionContext);
|
frame[QStringLiteral("context")] = encodeContext(executionContext);
|
||||||
|
|
||||||
if (QV4::Function *function = heapFunctionObject->function) {
|
if (QV4::Heap::String *functionName = function->name())
|
||||||
if (QV4::Heap::String *functionName = function->name())
|
frame[QStringLiteral("function")] = functionName->toQString();
|
||||||
frame[QStringLiteral("function")] = functionName->toQString();
|
frame[QStringLiteral("file")] = function->sourceFile();
|
||||||
frame[QStringLiteral("file")] = function->sourceFile();
|
|
||||||
}
|
|
||||||
int line = executionContext->d()->lineNumber;
|
int line = executionContext->d()->lineNumber;
|
||||||
frame[QStringLiteral("line")] = (line < 0 ? -line : line);
|
frame[QStringLiteral("line")] = (line < 0 ? -line : line);
|
||||||
|
|
||||||
|
@ -667,11 +665,9 @@ void NativeDebugger::aboutToThrow()
|
||||||
|
|
||||||
QV4::Function *NativeDebugger::getFunction() const
|
QV4::Function *NativeDebugger::getFunction() const
|
||||||
{
|
{
|
||||||
QV4::Scope scope(m_engine);
|
|
||||||
QV4::ExecutionContext *context = m_engine->currentContext;
|
QV4::ExecutionContext *context = m_engine->currentContext;
|
||||||
QV4::ScopedFunctionObject function(scope, context->getFunctionObject());
|
if (QV4::Function *function = context->getFunction())
|
||||||
if (function)
|
return function;
|
||||||
return function->function();
|
|
||||||
else
|
else
|
||||||
return context->d()->engine->globalCode;
|
return context->d()->engine->globalCode;
|
||||||
}
|
}
|
||||||
|
@ -683,10 +679,8 @@ void NativeDebugger::pauseAndWait()
|
||||||
event.insert(QStringLiteral("event"), QStringLiteral("break"));
|
event.insert(QStringLiteral("event"), QStringLiteral("break"));
|
||||||
event.insert(QStringLiteral("language"), QStringLiteral("js"));
|
event.insert(QStringLiteral("language"), QStringLiteral("js"));
|
||||||
if (QV4::ExecutionContext *executionContext = m_engine->currentContext) {
|
if (QV4::ExecutionContext *executionContext = m_engine->currentContext) {
|
||||||
QV4::Heap::FunctionObject *heapFunctionObject = executionContext->getFunctionObject();
|
if (QV4::Function *function = executionContext->getFunction()) {
|
||||||
if (heapFunctionObject) {
|
event.insert(QStringLiteral("file"), function->sourceFile());
|
||||||
if (QV4::Function *function = heapFunctionObject->function)
|
|
||||||
event.insert(QStringLiteral("file"), function->sourceFile());
|
|
||||||
int line = executionContext->d()->lineNumber;
|
int line = executionContext->d()->lineNumber;
|
||||||
event.insert(QStringLiteral("line"), (line < 0 ? -line : line));
|
event.insert(QStringLiteral("line"), (line < 0 ? -line : line));
|
||||||
}
|
}
|
||||||
|
|
|
@ -252,9 +252,8 @@ QV4::Function *QV4Debugger::getFunction() const
|
||||||
{
|
{
|
||||||
QV4::Scope scope(m_engine);
|
QV4::Scope scope(m_engine);
|
||||||
QV4::ExecutionContext *context = m_engine->currentContext;
|
QV4::ExecutionContext *context = m_engine->currentContext;
|
||||||
QV4::ScopedFunctionObject function(scope, context->getFunctionObject());
|
if (QV4::Function *function = context->getFunction())
|
||||||
if (function)
|
return function;
|
||||||
return function->function();
|
|
||||||
else
|
else
|
||||||
return context->d()->engine->globalCode;
|
return context->d()->engine->globalCode;
|
||||||
}
|
}
|
||||||
|
|
|
@ -524,13 +524,13 @@ ReturnedValue ExecutionContext::getPropertyAndBase(String *name, Value *base)
|
||||||
return engine()->throwReferenceError(n);
|
return engine()->throwReferenceError(n);
|
||||||
}
|
}
|
||||||
|
|
||||||
Heap::FunctionObject *ExecutionContext::getFunctionObject() const
|
Function *ExecutionContext::getFunction() const
|
||||||
{
|
{
|
||||||
Scope scope(d()->engine);
|
Scope scope(d()->engine);
|
||||||
ScopedContext it(scope, this->d());
|
ScopedContext it(scope, this->d());
|
||||||
for (; it; it = it->d()->outer) {
|
for (; it; it = it->d()->outer) {
|
||||||
if (const CallContext *callCtx = it->asCallContext())
|
if (const CallContext *callCtx = it->asCallContext())
|
||||||
return callCtx->d()->function;
|
return callCtx->d()->v4Function;
|
||||||
else if (it->asCatchContext() || it->asWithContext())
|
else if (it->asCatchContext() || it->asWithContext())
|
||||||
continue; // look in the parent context for a FunctionObject
|
continue; // look in the parent context for a FunctionObject
|
||||||
else
|
else
|
||||||
|
|
|
@ -214,7 +214,7 @@ struct Q_QML_EXPORT ExecutionContext : public Managed
|
||||||
inline const CatchContext *asCatchContext() const;
|
inline const CatchContext *asCatchContext() const;
|
||||||
inline const WithContext *asWithContext() const;
|
inline const WithContext *asWithContext() const;
|
||||||
|
|
||||||
Heap::FunctionObject *getFunctionObject() const;
|
Function *getFunction() const;
|
||||||
|
|
||||||
static void markObjects(Heap::Base *m, ExecutionEngine *e);
|
static void markObjects(Heap::Base *m, ExecutionEngine *e);
|
||||||
|
|
||||||
|
|
|
@ -780,21 +780,17 @@ QVector<StackFrame> ExecutionEngine::stackTrace(int frameLimit) const
|
||||||
QVector<StackFrame> stack;
|
QVector<StackFrame> stack;
|
||||||
|
|
||||||
ExecutionContext *c = currentContext;
|
ExecutionContext *c = currentContext;
|
||||||
ScopedFunctionObject function(scope);
|
|
||||||
while (c && frameLimit) {
|
while (c && frameLimit) {
|
||||||
function = c->getFunctionObject();
|
QV4::Function *function = c->getFunction();
|
||||||
if (function) {
|
if (function) {
|
||||||
StackFrame frame;
|
StackFrame frame;
|
||||||
if (const Function *f = function->function())
|
frame.source = function->sourceFile();
|
||||||
frame.source = f->sourceFile();
|
|
||||||
name = function->name();
|
name = function->name();
|
||||||
frame.function = name->toQString();
|
frame.function = name->toQString();
|
||||||
frame.line = -1;
|
|
||||||
frame.column = -1;
|
|
||||||
|
|
||||||
if (function->function())
|
// line numbers can be negative for places where you can't set a real breakpoint
|
||||||
// line numbers can be negative for places where you can't set a real breakpoint
|
frame.line = qAbs(c->d()->lineNumber);
|
||||||
frame.line = qAbs(c->d()->lineNumber);
|
frame.column = -1;
|
||||||
|
|
||||||
stack.append(frame);
|
stack.append(frame);
|
||||||
--frameLimit;
|
--frameLimit;
|
||||||
|
|
|
@ -169,10 +169,8 @@ static Breakpoint qt_v4LastStop;
|
||||||
|
|
||||||
static QV4::Function *qt_v4ExtractFunction(QV4::ExecutionContext *context)
|
static QV4::Function *qt_v4ExtractFunction(QV4::ExecutionContext *context)
|
||||||
{
|
{
|
||||||
QV4::Scope scope(context->engine());
|
if (QV4::Function *function = context->getFunction())
|
||||||
QV4::ScopedFunctionObject function(scope, context->getFunctionObject());
|
return function;
|
||||||
if (function)
|
|
||||||
return function->function();
|
|
||||||
else
|
else
|
||||||
return context->d()->engine->globalCode;
|
return context->d()->engine->globalCode;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue