{
this->throwingContext = throwingContext->engine->current;
accepted = false;
- m_stackTrace = throwingContext->engine->stackTrace();
+ if (ErrorObject *error = exceptionValue.asErrorObject())
+ m_stackTrace = error->stackTrace;
+ else
+ m_stackTrace = throwingContext->engine->stackTrace();
}
Exception::~Exception()
{
type = Type_ErrorObject;
subtype = t;
+ initClass(engine);
if (!message.isUndefined())
defineDefaultProperty(engine->newString(QStringLiteral("message")), message);
defineDefaultProperty(engine, QStringLiteral("name"), Value::fromString(engine, className()));
+
+ stackTrace = engine->stackTrace();
+
+ stack = Value::emptyValue();
+}
+
+Value ErrorObject::method_get_stack(SimpleCallContext *ctx)
+{
+ ErrorObject *This = ctx->thisObject.asErrorObject();
+ if (!This)
+ ctx->throwTypeError();
+ if (This->stack.isEmpty()) {
+ QString trace;
+ for (int i = 0; i < This->stackTrace.count(); ++i) {
+ if (i > 0)
+ trace += QLatin1Char('\n');
+ const ExecutionEngine::StackFrame &frame = This->stackTrace[i];
+ trace += frame.function;
+ trace += QLatin1Char('@');
+ trace += frame.source;
+ if (frame.line >= 0) {
+ trace += QLatin1Char(':');
+ trace += QString::number(frame.line);
+ }
+ }
+ This->stack = Value::fromString(ctx, trace);
+ }
+ return This->stack;
}
DEFINE_MANAGED_VTABLE(SyntaxErrorObject);
return Value::fromString(ctx, str);
}
+
+#include "qv4errorobject_p_jsclass.cpp"
struct SyntaxErrorObject;
-struct ErrorObject: Object {
+struct QV4_JS_CLASS(ErrorObject): Object {
enum ErrorType {
Error,
EvalError,
};
ErrorObject(ExecutionEngine *engine, const Value &message, ErrorType t = Error);
+ void initClass(ExecutionEngine *engine);
SyntaxErrorObject *asSyntaxError();
+
+ ExecutionEngine::StackTrace stackTrace;
+ Value stack;
+
+ static Value method_get_stack(SimpleCallContext *ctx);
};
struct EvalErrorObject: ErrorObject {
$$PWD/qv4booleanobject_p.h \
$$PWD/qv4regexpobject_p.h \
$$PWD/qv4variantobject_p.h \
- $$PWD/qv4sequenceobject_p.h
+ $$PWD/qv4sequenceobject_p.h \
+ $$PWD/qv4errorobject_p.h
js_class_bindings.output = ${QMAKE_FILE_BASE}_jsclass.cpp
js_class_bindings.input = JS_CLASS_SOURCES