}
struct CallContext;
-struct CallContext;
struct CatchContext;
struct WithContext;
inline CallContext *asCallContext();
inline const CallContext *asCallContext() const;
+ inline const CatchContext *asCatchContext() const;
+
+ inline FunctionObject *getFunctionObject() const;
static void markObjects(Managed *m, ExecutionEngine *e);
};
return d()->type >= Type_SimpleCallContext ? static_cast<const CallContext *>(this) : 0;
}
+inline const CatchContext *ExecutionContext::asCatchContext() const
+{
+ return d()->type == Type_CatchContext ? static_cast<const CatchContext *>(this) : 0;
+}
+
+inline FunctionObject *ExecutionContext::getFunctionObject() const
+{
+ for (const ExecutionContext *it = this; it; it = it->d()->parent) {
+ if (const CallContext *callCtx = it->asCallContext())
+ return callCtx->d()->function;
+ else if (it->asCatchContext())
+ continue; // look in the parent context for a FunctionObject
+ else
+ break;
+ }
+
+ return 0;
+}
inline void ExecutionEngine::pushContext(CallContext *context)
{
return;
QMutexLocker locker(&m_lock);
- int lineNumber = engine()->currentContext()->d()->lineNumber;
if (m_gatherSources) {
m_gatherSources->run();
if (m_pauseRequested) { // Serve debugging requests from the agent
m_pauseRequested = false;
pauseAndWait(PauseRequest);
- } else if (m_haveBreakPoints && reallyHitTheBreakPoint(getFunction()->sourceFile(), lineNumber)) {
- pauseAndWait(BreakPoint);
+ } else if (m_haveBreakPoints) {
+ if (Function *f = getFunction()) {
+ const int lineNumber = engine()->currentContext()->d()->lineNumber;
+ if (reallyHitTheBreakPoint(f->sourceFile(), lineNumber))
+ pauseAndWait(BreakPoint);
+ }
}
}
Function *Debugger::getFunction() const
{
ExecutionContext *context = m_engine->currentContext();
- if (CallContext *callCtx = context->asCallContext())
- return callCtx->d()->function->function();
- else {
- Q_ASSERT(context->d()->type == QV4::ExecutionContext::Type_GlobalContext);
+ if (const FunctionObject *function = context->getFunctionObject())
+ return function->function();
+ else
return context->d()->engine->globalCode;
- }
}
void Debugger::pauseAndWait(PauseReason reason)
QV4::ExecutionContext *c = currentContext();
while (c && frameLimit) {
- CallContext *callCtx = c->asCallContext();
- if (callCtx && callCtx->d()->function) {
+ if (FunctionObject *function = c->getFunctionObject()) {
StackFrame frame;
- if (callCtx->d()->function->function())
- frame.source = callCtx->d()->function->function()->sourceFile();
- name = callCtx->d()->function->name();
+ if (const Function *f = function->function())
+ frame.source = f->sourceFile();
+ name = function->name();
frame.function = name->toQString();
frame.line = -1;
frame.column = -1;
- if (callCtx->d()->function->function())
+ if (function->function())
// line numbers can be negative for places where you can't set a real breakpoint
- frame.line = qAbs(callCtx->d()->lineNumber);
+ frame.line = qAbs(c->d()->lineNumber);
stack.append(frame);
--frameLimit;
frame.line = rootContext->d()->lineNumber;
frame.column = -1;
-
stack.append(frame);
}
return stack;
ExecutionContext *scope() { return d()->scope; }
- Function *function() { return d()->function; }
+ Function *function() const { return d()->function; }
ReturnedValue name();
unsigned int formalParameterCount() { return function() ? function()->compiledFunction->nFormals : 0; }
// exceptions:
void pauseOnThrow();
+ void breakInCatch();
void evaluateExpression();
QCOMPARE(m_debuggerAgent->m_thrownValue.toString(), QString("hard"));
}
+void tst_qv4debugger::breakInCatch()
+{
+ QString script =
+ "try {\n"
+ " throw 'catch...'\n"
+ "} catch (e) {\n"
+ " console.log(e, 'me');\n"
+ "}\n";
+
+ m_debuggerAgent->addBreakPoint("breakInCatch", 4);
+ evaluateJavaScript(script, "breakInCatch");
+ QVERIFY(m_debuggerAgent->m_wasPaused);
+ QCOMPARE(m_debuggerAgent->m_pauseReason, BreakPoint);
+ QCOMPARE(m_debuggerAgent->m_statesWhenPaused.count(), 1);
+ QV4::Debugging::Debugger::ExecutionState state = m_debuggerAgent->m_statesWhenPaused.first();
+ QCOMPARE(state.fileName, QString("breakInCatch"));
+ QCOMPARE(state.lineNumber, 4);
+}
+
void tst_qv4debugger::evaluateExpression()
{
QString script =