Throw proper type and reference errors
authorLars Knoll <lars.knoll@digia.com>
Tue, 4 Dec 2012 18:50:25 +0000 (10:50 -0800)
committerSimon Hausmann <simon.hausmann@digia.com>
Tue, 4 Dec 2012 19:08:43 +0000 (20:08 +0100)
Change-Id: I898017f3e63ada72fc2e50abfa1880f9fd7ffe37
Reviewed-by: Simon Hausmann <simon.hausmann@digia.com>
qmljs_engine.cpp
qmljs_engine.h
qmljs_environment.cpp
qmljs_objects.h

index 4af9005..027cc33 100644 (file)
@@ -348,6 +348,20 @@ Object *ExecutionEngine::newSyntaxErrorObject(ExecutionContext *ctx, DiagnosticM
     return object;
 }
 
+Object *ExecutionEngine::newReferenceErrorObject(ExecutionContext *ctx, const QString &message)
+{
+    ReferenceErrorObject *object = new ReferenceErrorObject(ctx, message);
+    object->prototype = referenceErrorPrototype;
+    return object;
+}
+
+Object *ExecutionEngine::newTypeErrorObject(ExecutionContext *ctx, const QString &message)
+{
+    TypeErrorObject *object = new TypeErrorObject(ctx, message);
+    object->prototype = typeErrorPrototype;
+    return object;
+}
+
 Object *ExecutionEngine::newMathObject(ExecutionContext *ctx)
 {
     MathObject *object = new MathObject(ctx);
index d47c2d4..2b053fd 100644 (file)
@@ -186,6 +186,9 @@ struct ExecutionEngine
 
     Object *newErrorObject(const Value &value);
     Object *newSyntaxErrorObject(ExecutionContext *ctx, DiagnosticMessage *message);
+    Object *newReferenceErrorObject(ExecutionContext *ctx, const QString &message);
+    Object *newTypeErrorObject(ExecutionContext *ctx, const QString &message);
+
     Object *newMathObject(ExecutionContext *ctx);
     Object *newActivationObject(ExecutionContext *ctx);
 
index 94a8775..12a2091 100644 (file)
@@ -284,8 +284,7 @@ void ExecutionContext::throwSyntaxError(DiagnosticMessage *message)
 
 void ExecutionContext::throwTypeError()
 {
-    Value v = Value::fromString(this, QStringLiteral("Type error"));
-    throwError(Value::fromObject(engine->newErrorObject(v)));
+    throwError(Value::fromObject(engine->newTypeErrorObject(this, QStringLiteral("Type error"))));
 }
 
 void ExecutionContext::throwUnimplemented(const QString &message)
@@ -298,7 +297,7 @@ void ExecutionContext::throwReferenceError(Value value)
 {
     String *s = value.toString(this);
     QString msg = s->toQString() + QStringLiteral(" is not defined");
-    throwError(Value::fromObject(engine->newErrorObject(Value::fromString(this, msg))));
+    throwError(Value::fromObject(engine->newReferenceErrorObject(this, msg)));
 }
 
 void ExecutionContext::initCallContext(ExecutionContext *parent, const Value that, FunctionObject *f, Value *args, unsigned argc)
index 2590b01..4a98ee1 100644 (file)
@@ -610,6 +610,8 @@ struct RangeErrorObject: ErrorObject {
 struct ReferenceErrorObject: ErrorObject {
     ReferenceErrorObject(ExecutionContext *ctx)
         : ErrorObject(ctx->argument(0)) { setNameProperty(ctx); }
+    ReferenceErrorObject(ExecutionContext *ctx, const QString &msg)
+        : ErrorObject(Value::fromString(ctx,msg)) { setNameProperty(ctx); }
     virtual QString className() { return QStringLiteral("ReferenceError"); }
 };
 
@@ -628,6 +630,8 @@ private:
 struct TypeErrorObject: ErrorObject {
     TypeErrorObject(ExecutionContext *ctx)
         : ErrorObject(ctx->argument(0)) { setNameProperty(ctx); }
+    TypeErrorObject(ExecutionContext *ctx, const QString &msg)
+        : ErrorObject(Value::fromString(ctx,msg)) { setNameProperty(ctx); }
     virtual QString className() { return QStringLiteral("TypeError"); }
 };