Avoid defining name twice in some error objects
authorLars Knoll <lars.knoll@digia.com>
Mon, 8 Apr 2013 11:42:27 +0000 (13:42 +0200)
committerSimon Hausmann <simon.hausmann@digia.com>
Mon, 8 Apr 2013 14:29:04 +0000 (16:29 +0200)
Change-Id: I2e96718556ef5a4262816233351b71dd6a80cb9d
Reviewed-by: Simon Hausmann <simon.hausmann@digia.com>
src/v4/qv4engine.cpp
src/v4/qv4errorobject.cpp
src/v4/qv4errorobject.h

index 7064ba4..54655d1 100644 (file)
@@ -120,7 +120,7 @@ ExecutionEngine::ExecutionEngine(EvalISelFactory *factory)
     datePrototype = new (memoryManager) DatePrototype(this);
     functionPrototype = new (memoryManager) FunctionPrototype(rootContext);
     regExpPrototype = new (memoryManager) RegExpPrototype(this);
-    errorPrototype = new (memoryManager) ErrorPrototype(this);
+    errorPrototype = new (memoryManager) ErrorPrototype(rootContext);
     evalErrorPrototype = new (memoryManager) EvalErrorPrototype(rootContext);
     rangeErrorPrototype = new (memoryManager) RangeErrorPrototype(rootContext);
     referenceErrorPrototype = new (memoryManager) ReferenceErrorPrototype(rootContext);
@@ -435,7 +435,7 @@ RegExpObject *ExecutionEngine::newRegExpObject(RegExp* re, bool global)
 
 Object *ExecutionEngine::newErrorObject(const Value &value)
 {
-    ErrorObject *object = new (memoryManager) ErrorObject(this, value);
+    ErrorObject *object = new (memoryManager) ErrorObject(rootContext, value);
     object->prototype = errorPrototype;
     return object;
 }
index 51a0930..b69262e 100644 (file)
 
 using namespace QQmlJS::VM;
 
-ErrorObject::ErrorObject(ExecutionEngine* engine, const Value &message)
-    : Object(engine)
+ErrorObject::ErrorObject(ExecutionContext *context, const Value &message, ErrorType t)
+    : Object(context->engine)
 {
     type = Type_ErrorObject;
-    subtype = Error;
+    subtype = t;
 
     if (!message.isUndefined())
-        defineDefaultProperty(engine->newString(QStringLiteral("message")), message);
-}
-
-void ErrorObject::setNameProperty(ExecutionContext *ctx)
-{
-    defineDefaultProperty(ctx, QLatin1String("name"), Value::fromString(ctx, className()));
+        defineDefaultProperty(context->engine->newString(QStringLiteral("message")), message);
+    defineDefaultProperty(context, QLatin1String("name"), Value::fromString(context, className()));
 }
 
 DEFINE_MANAGED_VTABLE(SyntaxErrorObject);
 
 SyntaxErrorObject::SyntaxErrorObject(ExecutionContext *ctx, DiagnosticMessage *message)
-    : ErrorObject(ctx->engine, message ? Value::fromString(message->buildFullMessage(ctx)) : ctx->argument(0))
+    : ErrorObject(ctx, message ? Value::fromString(message->buildFullMessage(ctx)) : ctx->argument(0), SyntaxError)
     , msg(message)
 {
     vtbl = &static_vtbl;
-    subtype = SyntaxError;
     prototype = ctx->engine->syntaxErrorPrototype;
-    setNameProperty(ctx);
 }
 
 
 
 EvalErrorObject::EvalErrorObject(ExecutionContext *ctx, const Value &message)
-    : ErrorObject(ctx->engine, message)
+    : ErrorObject(ctx, message, EvalError)
 {
-    subtype = EvalError;
-    setNameProperty(ctx);
     prototype = ctx->engine->evalErrorPrototype;
 }
 
 RangeErrorObject::RangeErrorObject(ExecutionContext *ctx, const Value &message)
-    : ErrorObject(ctx->engine, message)
+    : ErrorObject(ctx, message, RangeError)
 {
-    subtype = RangeError;
-    setNameProperty(ctx);
     prototype = ctx->engine->rangeErrorPrototype;
 }
 
 RangeErrorObject::RangeErrorObject(ExecutionContext *ctx, const QString &message)
-    : ErrorObject(ctx->engine, Value::fromString(ctx,message))
+    : ErrorObject(ctx, Value::fromString(ctx,message), RangeError)
 {
-    subtype = RangeError;
-    setNameProperty(ctx);
     prototype = ctx->engine->rangeErrorPrototype;
 }
 
 ReferenceErrorObject::ReferenceErrorObject(ExecutionContext *ctx, const Value &message)
-    : ErrorObject(ctx->engine, message)
+    : ErrorObject(ctx, message, ReferenceError)
 {
-    subtype = ReferenceError;
-    setNameProperty(ctx);
     prototype = ctx->engine->referenceErrorPrototype;
 }
 
 ReferenceErrorObject::ReferenceErrorObject(ExecutionContext *ctx, const QString &message)
-    : ErrorObject(ctx->engine, Value::fromString(ctx,message))
+    : ErrorObject(ctx, Value::fromString(ctx,message), ReferenceError)
 {
-    subtype = ReferenceError;
-    setNameProperty(ctx);
     prototype = ctx->engine->referenceErrorPrototype;
 }
 
 TypeErrorObject::TypeErrorObject(ExecutionContext *ctx, const Value &message)
-    : ErrorObject(ctx->engine, message)
+    : ErrorObject(ctx, message, TypeError)
 {
-    subtype = TypeError;
-    setNameProperty(ctx);
     prototype = ctx->engine->typeErrorPrototype;
 }
 
 TypeErrorObject::TypeErrorObject(ExecutionContext *ctx, const QString &message)
-    : ErrorObject(ctx->engine, Value::fromString(ctx,message))
+    : ErrorObject(ctx, Value::fromString(ctx,message), TypeError)
 {
-    subtype = TypeError;
-    setNameProperty(ctx);
     prototype = ctx->engine->typeErrorPrototype;
 }
 
 URIErrorObject::URIErrorObject(ExecutionContext *ctx, const Value &message)
-    : ErrorObject(ctx->engine, message)
+    : ErrorObject(ctx, message, URIError)
 {
-    subtype = URIError;
-    setNameProperty(ctx);
     prototype = ctx->engine->uRIErrorPrototype;
 }
 
@@ -227,7 +205,6 @@ void ErrorPrototype::init(ExecutionContext *ctx, const Value &ctor, Object *obj)
     obj->defineDefaultProperty(ctx, QStringLiteral("constructor"), ctor);
     obj->defineDefaultProperty(ctx, QStringLiteral("toString"), method_toString, 0);
     obj->defineDefaultProperty(ctx, QStringLiteral("message"), Value::fromString(ctx, QString()));
-    obj->defineDefaultProperty(ctx, QStringLiteral("name"), Value::fromString(ctx, QStringLiteral("Error")));
 }
 
 Value ErrorPrototype::method_toString(SimpleCallContext *ctx)
index 2db8848..20a20ad 100644 (file)
@@ -62,12 +62,9 @@ struct ErrorObject: Object {
         URIError
     };
 
-    ErrorObject(ExecutionEngine* engine, const Value &message);
+    ErrorObject(ExecutionContext *context, const Value &message, ErrorType t = Error);
 
     SyntaxErrorObject *asSyntaxError();
-
-protected:
-    void setNameProperty(ExecutionContext *ctx);
 };
 
 struct EvalErrorObject: ErrorObject {
@@ -181,7 +178,7 @@ protected:
 struct ErrorPrototype: ErrorObject
 {
     // ### shouldn't be undefined
-    ErrorPrototype(ExecutionEngine* engine): ErrorObject(engine, Value::undefinedValue()) {}
+    ErrorPrototype(ExecutionContext *context): ErrorObject(context, Value::undefinedValue()) {}
     void init(ExecutionContext *ctx, const Value &ctor) { init(ctx, ctor, this); }
 
     static void init(ExecutionContext *ctx, const Value &ctor, Object *obj);