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;
|
||||
QV4::ExecutionContext *executionContext = m_engine->currentContext;
|
||||
for (int i = 0; i < limit && executionContext; ++i) {
|
||||
QV4::Heap::FunctionObject *heapFunctionObject = executionContext->getFunctionObject();
|
||||
if (heapFunctionObject) {
|
||||
if (QV4::Function *function = executionContext->getFunction()) {
|
||||
|
||||
QJsonObject frame;
|
||||
frame[QStringLiteral("language")] = QStringLiteral("js");
|
||||
frame[QStringLiteral("context")] = encodeContext(executionContext);
|
||||
|
||||
if (QV4::Function *function = heapFunctionObject->function) {
|
||||
if (QV4::Heap::String *functionName = function->name())
|
||||
frame[QStringLiteral("function")] = functionName->toQString();
|
||||
frame[QStringLiteral("file")] = function->sourceFile();
|
||||
}
|
||||
|
||||
int line = executionContext->d()->lineNumber;
|
||||
frame[QStringLiteral("line")] = (line < 0 ? -line : line);
|
||||
|
||||
|
@ -667,11 +665,9 @@ void NativeDebugger::aboutToThrow()
|
|||
|
||||
QV4::Function *NativeDebugger::getFunction() const
|
||||
{
|
||||
QV4::Scope scope(m_engine);
|
||||
QV4::ExecutionContext *context = m_engine->currentContext;
|
||||
QV4::ScopedFunctionObject function(scope, context->getFunctionObject());
|
||||
if (function)
|
||||
return function->function();
|
||||
if (QV4::Function *function = context->getFunction())
|
||||
return function;
|
||||
else
|
||||
return context->d()->engine->globalCode;
|
||||
}
|
||||
|
@ -683,9 +679,7 @@ void NativeDebugger::pauseAndWait()
|
|||
event.insert(QStringLiteral("event"), QStringLiteral("break"));
|
||||
event.insert(QStringLiteral("language"), QStringLiteral("js"));
|
||||
if (QV4::ExecutionContext *executionContext = m_engine->currentContext) {
|
||||
QV4::Heap::FunctionObject *heapFunctionObject = executionContext->getFunctionObject();
|
||||
if (heapFunctionObject) {
|
||||
if (QV4::Function *function = heapFunctionObject->function)
|
||||
if (QV4::Function *function = executionContext->getFunction()) {
|
||||
event.insert(QStringLiteral("file"), function->sourceFile());
|
||||
int line = executionContext->d()->lineNumber;
|
||||
event.insert(QStringLiteral("line"), (line < 0 ? -line : line));
|
||||
|
|
|
@ -252,9 +252,8 @@ QV4::Function *QV4Debugger::getFunction() const
|
|||
{
|
||||
QV4::Scope scope(m_engine);
|
||||
QV4::ExecutionContext *context = m_engine->currentContext;
|
||||
QV4::ScopedFunctionObject function(scope, context->getFunctionObject());
|
||||
if (function)
|
||||
return function->function();
|
||||
if (QV4::Function *function = context->getFunction())
|
||||
return function;
|
||||
else
|
||||
return context->d()->engine->globalCode;
|
||||
}
|
||||
|
|
|
@ -524,13 +524,13 @@ ReturnedValue ExecutionContext::getPropertyAndBase(String *name, Value *base)
|
|||
return engine()->throwReferenceError(n);
|
||||
}
|
||||
|
||||
Heap::FunctionObject *ExecutionContext::getFunctionObject() const
|
||||
Function *ExecutionContext::getFunction() const
|
||||
{
|
||||
Scope scope(d()->engine);
|
||||
ScopedContext it(scope, this->d());
|
||||
for (; it; it = it->d()->outer) {
|
||||
if (const CallContext *callCtx = it->asCallContext())
|
||||
return callCtx->d()->function;
|
||||
return callCtx->d()->v4Function;
|
||||
else if (it->asCatchContext() || it->asWithContext())
|
||||
continue; // look in the parent context for a FunctionObject
|
||||
else
|
||||
|
|
|
@ -214,7 +214,7 @@ struct Q_QML_EXPORT ExecutionContext : public Managed
|
|||
inline const CatchContext *asCatchContext() const;
|
||||
inline const WithContext *asWithContext() const;
|
||||
|
||||
Heap::FunctionObject *getFunctionObject() const;
|
||||
Function *getFunction() const;
|
||||
|
||||
static void markObjects(Heap::Base *m, ExecutionEngine *e);
|
||||
|
||||
|
|
|
@ -780,21 +780,17 @@ QVector<StackFrame> ExecutionEngine::stackTrace(int frameLimit) const
|
|||
QVector<StackFrame> stack;
|
||||
|
||||
ExecutionContext *c = currentContext;
|
||||
ScopedFunctionObject function(scope);
|
||||
while (c && frameLimit) {
|
||||
function = c->getFunctionObject();
|
||||
QV4::Function *function = c->getFunction();
|
||||
if (function) {
|
||||
StackFrame frame;
|
||||
if (const Function *f = function->function())
|
||||
frame.source = f->sourceFile();
|
||||
frame.source = function->sourceFile();
|
||||
name = function->name();
|
||||
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
|
||||
frame.line = qAbs(c->d()->lineNumber);
|
||||
frame.column = -1;
|
||||
|
||||
stack.append(frame);
|
||||
--frameLimit;
|
||||
|
|
|
@ -169,10 +169,8 @@ static Breakpoint qt_v4LastStop;
|
|||
|
||||
static QV4::Function *qt_v4ExtractFunction(QV4::ExecutionContext *context)
|
||||
{
|
||||
QV4::Scope scope(context->engine());
|
||||
QV4::ScopedFunctionObject function(scope, context->getFunctionObject());
|
||||
if (function)
|
||||
return function->function();
|
||||
if (QV4::Function *function = context->getFunction())
|
||||
return function;
|
||||
else
|
||||
return context->d()->engine->globalCode;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue