diff options
-rw-r--r-- | src/qml/jsruntime/qv4engine.cpp | 60 | ||||
-rw-r--r-- | src/qml/jsruntime/qv4engine_p.h | 4 | ||||
-rw-r--r-- | src/qml/jsruntime/qv4errorobject.cpp | 104 | ||||
-rw-r--r-- | src/qml/jsruntime/qv4errorobject_p.h | 67 | ||||
-rw-r--r-- | src/qml/jsruntime/qv4managed.cpp | 24 |
5 files changed, 121 insertions, 138 deletions
diff --git a/src/qml/jsruntime/qv4engine.cpp b/src/qml/jsruntime/qv4engine.cpp index 9bd296166f..e306106aea 100644 --- a/src/qml/jsruntime/qv4engine.cpp +++ b/src/qml/jsruntime/qv4engine.cpp @@ -353,25 +353,29 @@ ExecutionEngine::ExecutionEngine(EvalISelFactory *factory) errorClass = emptyClass->addMember((str = newIdentifier(QStringLiteral("stack"))), Attr_Accessor|Attr_NotConfigurable|Attr_NotEnumerable, &index); Q_ASSERT(index == ErrorObject::Index_Stack); - errorClass = errorClass->addMember((str = newIdentifier(QStringLiteral("message"))), Attr_Data|Attr_NotEnumerable, &index); - Q_ASSERT(index == ErrorObject::Index_Message); - errorClass = errorClass->addMember((str = newIdentifier(QStringLiteral("name"))), Attr_Data|Attr_NotEnumerable, &index); - Q_ASSERT(index == ErrorObject::Index_Name); errorClass = errorClass->addMember((str = newIdentifier(QStringLiteral("fileName"))), Attr_Data|Attr_NotEnumerable, &index); Q_ASSERT(index == ErrorObject::Index_FileName); errorClass = errorClass->addMember((str = newIdentifier(QStringLiteral("lineNumber"))), Attr_Data|Attr_NotEnumerable, &index); Q_ASSERT(index == ErrorObject::Index_LineNumber); + errorClassWithMessage = errorClass->addMember((str = newIdentifier(QStringLiteral("message"))), Attr_Data|Attr_NotEnumerable, &index); + Q_ASSERT(index == ErrorObject::Index_Message); + errorProtoClass = emptyClass->addMember(id_constructor(), Attr_Data|Attr_NotEnumerable, &index); + Q_ASSERT(index == ErrorPrototype::Index_Constructor); + errorProtoClass = errorProtoClass->addMember((str = newIdentifier(QStringLiteral("message"))), Attr_Data|Attr_NotEnumerable, &index); + Q_ASSERT(index == ErrorPrototype::Index_Message); + errorProtoClass = errorProtoClass->addMember(id_name(), Attr_Data|Attr_NotEnumerable, &index); + Q_ASSERT(index == ErrorPrototype::Index_Name); jsObjects[GetStack_Function] = BuiltinFunction::create(rootContext(), str = newIdentifier(QStringLiteral("stack")), ErrorObject::method_get_stack); getStackFunction()->defineReadonlyProperty(id_length(), Primitive::fromInt32(0)); - jsObjects[ErrorProto] = memoryManager->allocObject<ErrorPrototype>(errorClass, objectPrototype()); - jsObjects[EvalErrorProto] = memoryManager->allocObject<EvalErrorPrototype>(errorClass, errorPrototype()); - jsObjects[RangeErrorProto] = memoryManager->allocObject<RangeErrorPrototype>(errorClass, errorPrototype()); - jsObjects[ReferenceErrorProto] = memoryManager->allocObject<ReferenceErrorPrototype>(errorClass, errorPrototype()); - jsObjects[SyntaxErrorProto] = memoryManager->allocObject<SyntaxErrorPrototype>(errorClass, errorPrototype()); - jsObjects[TypeErrorProto] = memoryManager->allocObject<TypeErrorPrototype>(errorClass, errorPrototype()); - jsObjects[URIErrorProto] = memoryManager->allocObject<URIErrorPrototype>(errorClass, errorPrototype()); + jsObjects[ErrorProto] = memoryManager->allocObject<ErrorPrototype>(errorProtoClass, objectPrototype()); + jsObjects[EvalErrorProto] = memoryManager->allocObject<EvalErrorPrototype>(errorProtoClass, errorPrototype()); + jsObjects[RangeErrorProto] = memoryManager->allocObject<RangeErrorPrototype>(errorProtoClass, errorPrototype()); + jsObjects[ReferenceErrorProto] = memoryManager->allocObject<ReferenceErrorPrototype>(errorProtoClass, errorPrototype()); + jsObjects[SyntaxErrorProto] = memoryManager->allocObject<SyntaxErrorPrototype>(errorProtoClass, errorPrototype()); + jsObjects[TypeErrorProto] = memoryManager->allocObject<TypeErrorPrototype>(errorProtoClass, errorPrototype()); + jsObjects[URIErrorProto] = memoryManager->allocObject<URIErrorPrototype>(errorProtoClass, errorPrototype()); jsObjects[VariantProto] = memoryManager->allocObject<VariantPrototype>(emptyClass, objectPrototype()); Q_ASSERT(variantPrototype()->prototype() == objectPrototype()->d()); @@ -678,60 +682,44 @@ Heap::RegExpObject *ExecutionEngine::newRegExpObject(const QRegExp &re) Heap::Object *ExecutionEngine::newErrorObject(const Value &value) { - Scope scope(this); - ScopedObject object(scope, memoryManager->allocObject<ErrorObject>(value)); - return object->d(); + return ErrorObject::create<ErrorObject>(this, value); } Heap::Object *ExecutionEngine::newSyntaxErrorObject(const QString &message) { - Scope scope(this); - ScopedString s(scope, newString(message)); - return memoryManager->allocObject<SyntaxErrorObject>(s); + return ErrorObject::create<SyntaxErrorObject>(this, message); } Heap::Object *ExecutionEngine::newSyntaxErrorObject(const QString &message, const QString &fileName, int line, int column) { - Scope scope(this); - ScopedObject error(scope, memoryManager->allocObject<SyntaxErrorObject>(message, fileName, line, column)); - return error->d(); + return ErrorObject::create<SyntaxErrorObject>(this, message, fileName, line, column); } Heap::Object *ExecutionEngine::newReferenceErrorObject(const QString &message) { - Scope scope(this); - ScopedObject o(scope, memoryManager->allocObject<ReferenceErrorObject>(message)); - return o->d(); + return ErrorObject::create<ReferenceErrorObject>(this, message); } -Heap::Object *ExecutionEngine::newReferenceErrorObject(const QString &message, const QString &fileName, int lineNumber, int columnNumber) +Heap::Object *ExecutionEngine::newReferenceErrorObject(const QString &message, const QString &fileName, int line, int column) { - Scope scope(this); - ScopedObject o(scope, memoryManager->allocObject<ReferenceErrorObject>(message, fileName, lineNumber, columnNumber)); - return o->d(); + return ErrorObject::create<ReferenceErrorObject>(this, message, fileName, line, column); } Heap::Object *ExecutionEngine::newTypeErrorObject(const QString &message) { - Scope scope(this); - ScopedObject o(scope, memoryManager->allocObject<TypeErrorObject>(message)); - return o->d(); + return ErrorObject::create<TypeErrorObject>(this, message); } Heap::Object *ExecutionEngine::newRangeErrorObject(const QString &message) { - Scope scope(this); - ScopedObject o(scope, memoryManager->allocObject<RangeErrorObject>(message)); - return o->d(); + return ErrorObject::create<RangeErrorObject>(this, message); } Heap::Object *ExecutionEngine::newURIErrorObject(const Value &message) { - Scope scope(this); - ScopedObject o(scope, memoryManager->allocObject<URIErrorObject>(message)); - return o->d(); + return ErrorObject::create<URIErrorObject>(this, message); } Heap::Object *ExecutionEngine::newVariantObject(const QVariant &v) diff --git a/src/qml/jsruntime/qv4engine_p.h b/src/qml/jsruntime/qv4engine_p.h index ea3ec6e6a4..447105c2ab 100644 --- a/src/qml/jsruntime/qv4engine_p.h +++ b/src/qml/jsruntime/qv4engine_p.h @@ -237,6 +237,8 @@ public: InternalClass *strictArgumentsObjectClass; InternalClass *errorClass; + InternalClass *errorClassWithMessage; + InternalClass *errorProtoClass; EvalFunction *evalFunction() const { return reinterpret_cast<EvalFunction *>(jsObjects + Eval_Function); } FunctionObject *getStackFunction() const { return reinterpret_cast<FunctionObject *>(jsObjects + GetStack_Function); } @@ -388,7 +390,7 @@ public: Heap::Object *newSyntaxErrorObject(const QString &message, const QString &fileName, int line, int column); Heap::Object *newSyntaxErrorObject(const QString &message); Heap::Object *newReferenceErrorObject(const QString &message); - Heap::Object *newReferenceErrorObject(const QString &message, const QString &fileName, int lineNumber, int columnNumber); + Heap::Object *newReferenceErrorObject(const QString &message, const QString &fileName, int line, int column); Heap::Object *newTypeErrorObject(const QString &message); Heap::Object *newRangeErrorObject(const QString &message); Heap::Object *newURIErrorObject(const Value &message); diff --git a/src/qml/jsruntime/qv4errorobject.cpp b/src/qml/jsruntime/qv4errorobject.cpp index 219f4845c4..87b7a88a2b 100644 --- a/src/qml/jsruntime/qv4errorobject.cpp +++ b/src/qml/jsruntime/qv4errorobject.cpp @@ -66,13 +66,11 @@ Heap::ErrorObject::ErrorObject() Scope scope(internalClass->engine); Scoped<QV4::ErrorObject> e(scope, this); + if (internalClass == scope.engine->errorProtoClass) + return; + *propertyData(QV4::ErrorObject::Index_Stack) = scope.engine->getStackFunction(); *propertyData(QV4::ErrorObject::Index_Stack + QV4::Object::SetterOffset) = Encode::undefined(); - *propertyData(QV4::ErrorObject::Index_Message) = Encode::undefined(); - - ScopedString s(scope, scope.engine->newString(QStringLiteral("Error"))); - *propertyData(QV4::ErrorObject::Index_Name) = s; - *propertyData(QV4::ErrorObject::Index_FileName) = Encode::undefined(); *propertyData(QV4::ErrorObject::Index_LineNumber) = Encode::undefined(); } @@ -86,38 +84,18 @@ Heap::ErrorObject::ErrorObject(const Value &message, ErrorType t) *propertyData(QV4::ErrorObject::Index_Stack) = scope.engine->getStackFunction(); *propertyData(QV4::ErrorObject::Index_Stack + QV4::Object::SetterOffset) = Encode::undefined(); - *propertyData(QV4::ErrorObject::Index_Message) = message; - - *propertyData(QV4::ErrorObject::Index_Name) = scope.engine->newString(e->className()); e->d()->stackTrace = scope.engine->stackTrace(); if (!e->d()->stackTrace.isEmpty()) { *propertyData(QV4::ErrorObject::Index_FileName) = scope.engine->newString(e->d()->stackTrace.at(0).source); *propertyData(QV4::ErrorObject::Index_LineNumber) = Primitive::fromInt32(e->d()->stackTrace.at(0).line); } -} - -Heap::ErrorObject::ErrorObject(const QString &message, ErrorObject::ErrorType t) -{ - errorType = t; - - Scope scope(internalClass->engine); - Scoped<QV4::ErrorObject> e(scope, this); - - *propertyData(QV4::ErrorObject::Index_Stack) = scope.engine->getStackFunction(); - *propertyData(QV4::ErrorObject::Index_Stack + QV4::Object::SetterOffset) = Encode::undefined(); - *propertyData(QV4::ErrorObject::Index_Message) = scope.engine->newString(message); - *propertyData(QV4::ErrorObject::Index_Name) = scope.engine->newString(e->className()); - - e->d()->stackTrace = scope.engine->stackTrace(); - if (!e->d()->stackTrace.isEmpty()) { - *propertyData(QV4::ErrorObject::Index_FileName) = scope.engine->newString(e->d()->stackTrace.at(0).source); - *propertyData(QV4::ErrorObject::Index_LineNumber) = Primitive::fromInt32(e->d()->stackTrace.at(0).line); - } + if (!message.isUndefined()) + *propertyData(QV4::ErrorObject::Index_Message) = message; } -Heap::ErrorObject::ErrorObject(const QString &message, const QString &fileName, int line, int column, ErrorObject::ErrorType t) +Heap::ErrorObject::ErrorObject(const Value &message, const QString &fileName, int line, int column, ErrorObject::ErrorType t) { errorType = t; @@ -126,9 +104,6 @@ Heap::ErrorObject::ErrorObject(const QString &message, const QString &fileName, *propertyData(QV4::ErrorObject::Index_Stack) = scope.engine->getStackFunction(); *propertyData(QV4::ErrorObject::Index_Stack + QV4::Object::SetterOffset) = Encode::undefined(); - *propertyData(QV4::ErrorObject::Index_Message) = scope.engine->newString(message); - - *propertyData(QV4::ErrorObject::Index_Name) = scope.engine->newString(e->className()); e->d()->stackTrace = scope.engine->stackTrace(); StackFrame frame; @@ -141,6 +116,30 @@ Heap::ErrorObject::ErrorObject(const QString &message, const QString &fileName, *propertyData(QV4::ErrorObject::Index_FileName) = scope.engine->newString(e->d()->stackTrace.at(0).source); *propertyData(QV4::ErrorObject::Index_LineNumber) = Primitive::fromInt32(e->d()->stackTrace.at(0).line); } + + if (!message.isUndefined()) + *propertyData(QV4::ErrorObject::Index_Message) = message; +} + +const char *ErrorObject::className(Heap::ErrorObject::ErrorType t) +{ + switch (t) { + case Heap::ErrorObject::Error: + return "Error"; + case Heap::ErrorObject::EvalError: + return "EvalError"; + case Heap::ErrorObject::RangeError: + return "RangeError"; + case Heap::ErrorObject::ReferenceError: + return "ReferenceError"; + case Heap::ErrorObject::SyntaxError: + return "SyntaxError"; + case Heap::ErrorObject::TypeError: + return "TypeError"; + case Heap::ErrorObject::URIError: + return "URIError"; + } + Q_UNREACHABLE(); } ReturnedValue ErrorObject::method_get_stack(CallContext *ctx) @@ -185,7 +184,7 @@ Heap::SyntaxErrorObject::SyntaxErrorObject(const Value &msg) { } -Heap::SyntaxErrorObject::SyntaxErrorObject(const QString &msg, const QString &fileName, int lineNumber, int columnNumber) +Heap::SyntaxErrorObject::SyntaxErrorObject(const Value &msg, const QString &fileName, int lineNumber, int columnNumber) : Heap::ErrorObject(msg, fileName, lineNumber, columnNumber, SyntaxError) { } @@ -200,22 +199,12 @@ Heap::RangeErrorObject::RangeErrorObject(const Value &message) { } -Heap::RangeErrorObject::RangeErrorObject(const QString &message) - : Heap::ErrorObject(message, RangeError) -{ -} - Heap::ReferenceErrorObject::ReferenceErrorObject(const Value &message) : Heap::ErrorObject(message, ReferenceError) { } -Heap::ReferenceErrorObject::ReferenceErrorObject(const QString &message) - : Heap::ErrorObject(message, ReferenceError) -{ -} - -Heap::ReferenceErrorObject::ReferenceErrorObject(const QString &msg, const QString &fileName, int lineNumber, int columnNumber) +Heap::ReferenceErrorObject::ReferenceErrorObject(const Value &msg, const QString &fileName, int lineNumber, int columnNumber) : Heap::ErrorObject(msg, fileName, lineNumber, columnNumber, ReferenceError) { } @@ -225,11 +214,6 @@ Heap::TypeErrorObject::TypeErrorObject(const Value &message) { } -Heap::TypeErrorObject::TypeErrorObject(const QString &message) - : Heap::ErrorObject(message, TypeError) -{ -} - Heap::URIErrorObject::URIErrorObject(const Value &message) : Heap::ErrorObject(message, URIError) { @@ -257,7 +241,7 @@ ReturnedValue ErrorCtor::construct(const Managed *m, CallData *callData) { Scope scope(static_cast<const ErrorCtor *>(m)->engine()); ScopedValue v(scope, callData->argument(0)); - return Encode(scope.engine->newErrorObject(v)); + return ErrorObject::create<ErrorObject>(scope.engine, v)->asReturnedValue(); } ReturnedValue ErrorCtor::call(const Managed *that, CallData *callData) @@ -274,7 +258,7 @@ ReturnedValue EvalErrorCtor::construct(const Managed *m, CallData *callData) { Scope scope(static_cast<const EvalErrorCtor *>(m)->engine()); ScopedValue v(scope, callData->argument(0)); - return (scope.engine->memoryManager->allocObject<EvalErrorObject>(v))->asReturnedValue(); + return ErrorObject::create<EvalErrorObject>(scope.engine, v)->asReturnedValue(); } Heap::RangeErrorCtor::RangeErrorCtor(QV4::ExecutionContext *scope) @@ -286,7 +270,7 @@ ReturnedValue RangeErrorCtor::construct(const Managed *m, CallData *callData) { Scope scope(static_cast<const RangeErrorCtor *>(m)->engine()); ScopedValue v(scope, callData->argument(0)); - return (scope.engine->memoryManager->allocObject<RangeErrorObject>(v))->asReturnedValue(); + return ErrorObject::create<RangeErrorObject>(scope.engine, v)->asReturnedValue(); } Heap::ReferenceErrorCtor::ReferenceErrorCtor(QV4::ExecutionContext *scope) @@ -298,7 +282,7 @@ ReturnedValue ReferenceErrorCtor::construct(const Managed *m, CallData *callData { Scope scope(static_cast<const ReferenceErrorCtor *>(m)->engine()); ScopedValue v(scope, callData->argument(0)); - return (scope.engine->memoryManager->allocObject<ReferenceErrorObject>(v))->asReturnedValue(); + return ErrorObject::create<ReferenceErrorObject>(scope.engine, v)->asReturnedValue(); } Heap::SyntaxErrorCtor::SyntaxErrorCtor(QV4::ExecutionContext *scope) @@ -310,7 +294,7 @@ ReturnedValue SyntaxErrorCtor::construct(const Managed *m, CallData *callData) { Scope scope(static_cast<const SyntaxErrorCtor *>(m)->engine()); ScopedValue v(scope, callData->argument(0)); - return (scope.engine->memoryManager->allocObject<SyntaxErrorObject>(v))->asReturnedValue(); + return ErrorObject::create<SyntaxErrorObject>(scope.engine, v)->asReturnedValue(); } Heap::TypeErrorCtor::TypeErrorCtor(QV4::ExecutionContext *scope) @@ -322,7 +306,7 @@ ReturnedValue TypeErrorCtor::construct(const Managed *m, CallData *callData) { Scope scope(static_cast<const TypeErrorCtor *>(m)->engine()); ScopedValue v(scope, callData->argument(0)); - return (scope.engine->memoryManager->allocObject<TypeErrorObject>(v))->asReturnedValue(); + return ErrorObject::create<TypeErrorObject>(scope.engine, v)->asReturnedValue(); } Heap::URIErrorCtor::URIErrorCtor(QV4::ExecutionContext *scope) @@ -334,19 +318,21 @@ ReturnedValue URIErrorCtor::construct(const Managed *m, CallData *callData) { Scope scope(static_cast<const URIErrorCtor *>(m)->engine()); ScopedValue v(scope, callData->argument(0)); - return (scope.engine->memoryManager->allocObject<URIErrorObject>(v))->asReturnedValue(); + return ErrorObject::create<URIErrorObject>(scope.engine, v)->asReturnedValue(); } -void ErrorPrototype::init(ExecutionEngine *engine, Object *ctor, Object *obj) +void ErrorPrototype::init(ExecutionEngine *engine, Object *ctor, Object *obj, Heap::ErrorObject::ErrorType t) { Scope scope(engine); ScopedString s(scope); ScopedObject o(scope); ctor->defineReadonlyProperty(engine->id_prototype(), (o = obj)); ctor->defineReadonlyProperty(engine->id_length(), Primitive::fromInt32(1)); - obj->defineDefaultProperty(QStringLiteral("constructor"), (o = ctor)); - obj->defineDefaultProperty(engine->id_toString(), method_toString, 0); - obj->defineDefaultProperty(QStringLiteral("message"), (s = engine->newString())); + *obj->propertyData(Index_Constructor) = ctor; + *obj->propertyData(Index_Message) = engine->id_empty(); + *obj->propertyData(Index_Name) = engine->newString(QString::fromLatin1(ErrorObject::className(t))); + if (t == Heap::ErrorObject::Error) + obj->defineDefaultProperty(engine->id_toString(), method_toString, 0); } ReturnedValue ErrorPrototype::method_toString(CallContext *ctx) diff --git a/src/qml/jsruntime/qv4errorobject_p.h b/src/qml/jsruntime/qv4errorobject_p.h index 050979ad53..7f3babaa79 100644 --- a/src/qml/jsruntime/qv4errorobject_p.h +++ b/src/qml/jsruntime/qv4errorobject_p.h @@ -35,6 +35,7 @@ #include "qv4object_p.h" #include "qv4functionobject_p.h" +#include "qv4string_p.h" QT_BEGIN_NAMESPACE @@ -57,8 +58,7 @@ struct ErrorObject : Object { ErrorObject(); ErrorObject(const Value &message, ErrorType t = Error); - ErrorObject(const QString &message, ErrorType t = Error); - ErrorObject(const QString &message, const QString &fileName, int line, int column, ErrorType t = Error); + ErrorObject(const Value &message, const QString &fileName, int line, int column, ErrorType t = Error); ErrorType errorType; StackTrace stackTrace; @@ -71,23 +71,20 @@ struct EvalErrorObject : ErrorObject { struct RangeErrorObject : ErrorObject { RangeErrorObject(const Value &message); - RangeErrorObject(const QString &msg); }; struct ReferenceErrorObject : ErrorObject { ReferenceErrorObject(const Value &message); - ReferenceErrorObject(const QString &msg); - ReferenceErrorObject(const QString &msg, const QString &fileName, int lineNumber, int columnNumber); + ReferenceErrorObject(const Value &msg, const QString &fileName, int lineNumber, int columnNumber); }; struct SyntaxErrorObject : ErrorObject { SyntaxErrorObject(const Value &message); - SyntaxErrorObject(const QString &msg, const QString &fileName, int lineNumber, int columnNumber); + SyntaxErrorObject(const Value &msg, const QString &fileName, int lineNumber, int columnNumber); }; struct TypeErrorObject : ErrorObject { TypeErrorObject(const Value &message); - TypeErrorObject(const QString &msg); }; struct URIErrorObject : ErrorObject { @@ -132,10 +129,9 @@ struct ErrorObject: Object { enum { Index_Stack = 0, // Accessor Property - Index_Message = 2, - Index_Name = 3, - Index_FileName = 4, - Index_LineNumber = 5 + Index_FileName = 2, + Index_LineNumber = 3, + Index_Message = 4 }; V4_OBJECT2(ErrorObject, Object) @@ -144,8 +140,17 @@ struct ErrorObject: Object { V4_PROTOTYPE(errorPrototype) V4_NEEDS_DESTROY + template <typename T> + static Heap::Object *create(ExecutionEngine *e, const Value &message); + template <typename T> + static Heap::Object *create(ExecutionEngine *e, const QString &message); + template <typename T> + static Heap::Object *create(ExecutionEngine *e, const QString &message, const QString &filename, int line, int column); + SyntaxErrorObject *asSyntaxError(); + static const char *className(Heap::ErrorObject::ErrorType t); + static ReturnedValue method_get_stack(CallContext *ctx); static void markObjects(Heap::Base *that, ExecutionEngine *e); }; @@ -248,40 +253,45 @@ struct URIErrorCtor: ErrorCtor struct ErrorPrototype : ErrorObject { - void init(ExecutionEngine *engine, Object *ctor) { init(engine, ctor, this); } + enum { + Index_Constructor = 0, + Index_Message = 1, + Index_Name = 2 + }; + void init(ExecutionEngine *engine, Object *ctor) { init(engine, ctor, this, Heap::ErrorObject::Error); } - static void init(ExecutionEngine *engine, Object *ctor, Object *obj); + static void init(ExecutionEngine *engine, Object *ctor, Object *obj, Heap::ErrorObject::ErrorType t); static ReturnedValue method_toString(CallContext *ctx); }; struct EvalErrorPrototype : ErrorObject { - void init(ExecutionEngine *engine, Object *ctor) { ErrorPrototype::init(engine, ctor, this); } + void init(ExecutionEngine *engine, Object *ctor) { ErrorPrototype::init(engine, ctor, this, Heap::ErrorObject::EvalError); } }; struct RangeErrorPrototype : ErrorObject { - void init(ExecutionEngine *engine, Object *ctor) { ErrorPrototype::init(engine, ctor, this); } + void init(ExecutionEngine *engine, Object *ctor) { ErrorPrototype::init(engine, ctor, this, Heap::ErrorObject::RangeError); } }; struct ReferenceErrorPrototype : ErrorObject { - void init(ExecutionEngine *engine, Object *ctor) { ErrorPrototype::init(engine, ctor, this); } + void init(ExecutionEngine *engine, Object *ctor) { ErrorPrototype::init(engine, ctor, this, Heap::ErrorObject::ReferenceError); } }; struct SyntaxErrorPrototype : ErrorObject { - void init(ExecutionEngine *engine, Object *ctor) { ErrorPrototype::init(engine, ctor, this); } + void init(ExecutionEngine *engine, Object *ctor) { ErrorPrototype::init(engine, ctor, this, Heap::ErrorObject::SyntaxError); } }; struct TypeErrorPrototype : ErrorObject { - void init(ExecutionEngine *engine, Object *ctor) { ErrorPrototype::init(engine, ctor, this); } + void init(ExecutionEngine *engine, Object *ctor) { ErrorPrototype::init(engine, ctor, this, Heap::ErrorObject::TypeError); } }; struct URIErrorPrototype : ErrorObject { - void init(ExecutionEngine *engine, Object *ctor) { ErrorPrototype::init(engine, ctor, this); } + void init(ExecutionEngine *engine, Object *ctor) { ErrorPrototype::init(engine, ctor, this, Heap::ErrorObject::URIError); } }; @@ -290,6 +300,25 @@ inline SyntaxErrorObject *ErrorObject::asSyntaxError() return d()->errorType == QV4::Heap::ErrorObject::SyntaxError ? static_cast<SyntaxErrorObject *>(this) : 0; } + +template <typename T> +Heap::Object *ErrorObject::create(ExecutionEngine *e, const Value &message) { + return e->memoryManager->allocObject<T>(message.isUndefined() ? e->errorClass : e->errorClassWithMessage, T::defaultPrototype(e), message); +} +template <typename T> +Heap::Object *ErrorObject::create(ExecutionEngine *e, const QString &message) { + Scope scope(e); + ScopedValue v(scope, message.isEmpty() ? Encode::undefined() : e->newString(message)->asReturnedValue()); + return e->memoryManager->allocObject<T>(v->isUndefined() ? e->errorClass : e->errorClassWithMessage, T::defaultPrototype(e), v); +} +template <typename T> +Heap::Object *ErrorObject::create(ExecutionEngine *e, const QString &message, const QString &filename, int line, int column) { + Scope scope(e); + ScopedValue v(scope, message.isEmpty() ? Encode::undefined() : e->newString(message)->asReturnedValue()); + return e->memoryManager->allocObject<T>(v->isUndefined() ? e->errorClass : e->errorClassWithMessage, T::defaultPrototype(e), v, filename, line, column); +} + + } QT_END_NAMESPACE diff --git a/src/qml/jsruntime/qv4managed.cpp b/src/qml/jsruntime/qv4managed.cpp index bb7ee43b4e..e2de36d18e 100644 --- a/src/qml/jsruntime/qv4managed.cpp +++ b/src/qml/jsruntime/qv4managed.cpp @@ -88,29 +88,7 @@ QString Managed::className() const s = "RegExp"; break; case Type_ErrorObject: - switch (static_cast<Heap::ErrorObject *>(d())->errorType) { - case Heap::ErrorObject::Error: - s = "Error"; - break; - case Heap::ErrorObject::EvalError: - s = "EvalError"; - break; - case Heap::ErrorObject::RangeError: - s = "RangeError"; - break; - case Heap::ErrorObject::ReferenceError: - s = "ReferenceError"; - break; - case Heap::ErrorObject::SyntaxError: - s = "SyntaxError"; - break; - case Heap::ErrorObject::TypeError: - s = "TypeError"; - break; - case Heap::ErrorObject::URIError: - s = "URIError"; - break; - } + s = ErrorObject::className(static_cast<Heap::ErrorObject *>(d())->errorType); break; case Type_ArgumentsObject: s = "Arguments"; |