Fix tst_qqmlecmascript::propertyAssignmentErrors()
authorSimon Hausmann <simon.hausmann@digia.com>
Fri, 7 Jun 2013 14:59:32 +0000 (16:59 +0200)
committerLars Knoll <lars.knoll@digia.com>
Sat, 8 Jun 2013 20:33:40 +0000 (22:33 +0200)
Implement the non-standard but yet widelysupported stack property
in Error objects, that this test requires.

Change-Id: I37effb3c918498ba0d89014fbdcac9b2f623b1fa
Reviewed-by: Lars Knoll <lars.knoll@digia.com>
src/qml/qml/v4/qv4engine.cpp
src/qml/qml/v4/qv4errorobject.cpp
src/qml/qml/v4/qv4errorobject_p.h
src/qml/qml/v4/v4.pri

index 8bb62ae..1fa0260 100644 (file)
@@ -913,7 +913,10 @@ Exception::Exception(ExecutionContext *throwingContext, const Value &exceptionVa
 {
     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()
index 7a597b6..79504e1 100644 (file)
@@ -78,10 +78,39 @@ ErrorObject::ErrorObject(ExecutionEngine *engine, const Value &message, ErrorTyp
 {
     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);
@@ -294,3 +323,5 @@ Value ErrorPrototype::method_toString(SimpleCallContext *ctx)
 
     return Value::fromString(ctx, str);
 }
+
+#include "qv4errorobject_p_jsclass.cpp"
index babb81d..613c054 100644 (file)
@@ -50,7 +50,7 @@ namespace QV4 {
 
 struct SyntaxErrorObject;
 
-struct ErrorObject: Object {
+struct QV4_JS_CLASS(ErrorObject): Object {
     enum ErrorType {
         Error,
         EvalError,
@@ -62,8 +62,14 @@ struct ErrorObject: Object {
     };
 
     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 {
index a65ad2a..caaaccc 100644 (file)
@@ -117,7 +117,8 @@ JS_CLASS_SOURCES += $$PWD/qv4dateobject_p.h \
                     $$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