From: Lars Knoll Date: Tue, 4 Dec 2012 18:50:25 +0000 (-0800) Subject: Throw proper type and reference errors X-Git-Tag: upstream/5.2.1~669^2~659^2~756 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=944af86fca2eac90cd6528d2dfbff5316fa911a9;p=platform%2Fupstream%2Fqtdeclarative.git Throw proper type and reference errors Change-Id: I898017f3e63ada72fc2e50abfa1880f9fd7ffe37 Reviewed-by: Simon Hausmann --- diff --git a/qmljs_engine.cpp b/qmljs_engine.cpp index 4af9005..027cc33 100644 --- a/qmljs_engine.cpp +++ b/qmljs_engine.cpp @@ -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); diff --git a/qmljs_engine.h b/qmljs_engine.h index d47c2d4..2b053fd 100644 --- a/qmljs_engine.h +++ b/qmljs_engine.h @@ -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); diff --git a/qmljs_environment.cpp b/qmljs_environment.cpp index 94a8775..12a2091 100644 --- a/qmljs_environment.cpp +++ b/qmljs_environment.cpp @@ -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) diff --git a/qmljs_objects.h b/qmljs_objects.h index 2590b01..4a98ee1 100644 --- a/qmljs_objects.h +++ b/qmljs_objects.h @@ -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"); } };