diff options
Diffstat (limited to 'src/qml/jsruntime/qv4errorobject.cpp')
-rw-r--r-- | src/qml/jsruntime/qv4errorobject.cpp | 146 |
1 files changed, 70 insertions, 76 deletions
diff --git a/src/qml/jsruntime/qv4errorobject.cpp b/src/qml/jsruntime/qv4errorobject.cpp index 9f1e6b613b..597ded6ae1 100644 --- a/src/qml/jsruntime/qv4errorobject.cpp +++ b/src/qml/jsruntime/qv4errorobject.cpp @@ -67,8 +67,11 @@ using namespace QV4; -Heap::ErrorObject::ErrorObject() +void Heap::ErrorObject::init() { + Object::init(); + stackTrace = nullptr; + Scope scope(internalClass->engine); Scoped<QV4::ErrorObject> e(scope, this); @@ -81,8 +84,9 @@ Heap::ErrorObject::ErrorObject() *propertyData(QV4::ErrorObject::Index_LineNumber) = Encode::undefined(); } -Heap::ErrorObject::ErrorObject(const Value &message, ErrorType t) +void Heap::ErrorObject::init(const Value &message, ErrorType t) { + Object::init(); errorType = t; Scope scope(internalClass->engine); @@ -91,18 +95,19 @@ 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(); - 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); + e->d()->stackTrace = new 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 Value &message, const QString &fileName, int line, int column, ErrorObject::ErrorType t) +void Heap::ErrorObject::init(const Value &message, const QString &fileName, int line, int column, ErrorObject::ErrorType t) { + Object::init(); errorType = t; Scope scope(internalClass->engine); @@ -111,16 +116,16 @@ Heap::ErrorObject::ErrorObject(const Value &message, const QString &fileName, in *propertyData(QV4::ErrorObject::Index_Stack) = scope.engine->getStackFunction(); *propertyData(QV4::ErrorObject::Index_Stack + QV4::Object::SetterOffset) = Encode::undefined(); - e->d()->stackTrace = scope.engine->stackTrace(); + e->d()->stackTrace = new StackTrace(scope.engine->stackTrace()); StackFrame frame; frame.source = fileName; frame.line = line; frame.column = column; - e->d()->stackTrace.prepend(frame); + e->d()->stackTrace->prepend(frame); - 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 (!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()) @@ -156,17 +161,13 @@ ReturnedValue ErrorObject::method_get_stack(CallContext *ctx) return ctx->engine()->throwTypeError(); if (!This->d()->stack) { QString trace; - for (int i = 0; i < This->d()->stackTrace.count(); ++i) { + for (int i = 0; i < This->d()->stackTrace->count(); ++i) { if (i > 0) trace += QLatin1Char('\n'); - const StackFrame &frame = This->d()->stackTrace[i]; - trace += frame.function; - trace += QLatin1Char('@'); - trace += frame.source; - if (frame.line >= 0) { - trace += QLatin1Char(':'); - trace += QString::number(frame.line); - } + const StackFrame &frame = This->d()->stackTrace->at(i); + trace += frame.function + QLatin1Char('@') + frame.source; + if (frame.line >= 0) + trace += QLatin1Char(':') + QString::number(frame.line); } This->d()->stack = ctx->d()->engine->newString(trace); } @@ -185,44 +186,44 @@ DEFINE_OBJECT_VTABLE(ErrorObject); DEFINE_OBJECT_VTABLE(SyntaxErrorObject); -Heap::SyntaxErrorObject::SyntaxErrorObject(const Value &msg) - : Heap::ErrorObject(msg, SyntaxError) +void Heap::SyntaxErrorObject::init(const Value &msg) { + Heap::ErrorObject::init(msg, SyntaxError); } -Heap::SyntaxErrorObject::SyntaxErrorObject(const Value &msg, const QString &fileName, int lineNumber, int columnNumber) - : Heap::ErrorObject(msg, fileName, lineNumber, columnNumber, SyntaxError) +void Heap::SyntaxErrorObject::init(const Value &msg, const QString &fileName, int lineNumber, int columnNumber) { + Heap::ErrorObject::init(msg, fileName, lineNumber, columnNumber, SyntaxError); } -Heap::EvalErrorObject::EvalErrorObject(const Value &message) - : Heap::ErrorObject(message, EvalError) +void Heap::EvalErrorObject::init(const Value &message) { + Heap::ErrorObject::init(message, EvalError); } -Heap::RangeErrorObject::RangeErrorObject(const Value &message) - : Heap::ErrorObject(message, RangeError) +void Heap::RangeErrorObject::init(const Value &message) { + Heap::ErrorObject::init(message, RangeError); } -Heap::ReferenceErrorObject::ReferenceErrorObject(const Value &message) - : Heap::ErrorObject(message, ReferenceError) +void Heap::ReferenceErrorObject::init(const Value &message) { + Heap::ErrorObject::init(message, ReferenceError); } -Heap::ReferenceErrorObject::ReferenceErrorObject(const Value &msg, const QString &fileName, int lineNumber, int columnNumber) - : Heap::ErrorObject(msg, fileName, lineNumber, columnNumber, ReferenceError) +void Heap::ReferenceErrorObject::init(const Value &msg, const QString &fileName, int lineNumber, int columnNumber) { + Heap::ErrorObject::init(msg, fileName, lineNumber, columnNumber, ReferenceError); } -Heap::TypeErrorObject::TypeErrorObject(const Value &message) - : Heap::ErrorObject(message, TypeError) +void Heap::TypeErrorObject::init(const Value &message) { + Heap::ErrorObject::init(message, TypeError); } -Heap::URIErrorObject::URIErrorObject(const Value &message) - : Heap::ErrorObject(message, URIError) +void Heap::URIErrorObject::init(const Value &message) { + Heap::ErrorObject::init(message, URIError); } DEFINE_OBJECT_VTABLE(ErrorCtor); @@ -233,98 +234,91 @@ DEFINE_OBJECT_VTABLE(SyntaxErrorCtor); DEFINE_OBJECT_VTABLE(TypeErrorCtor); DEFINE_OBJECT_VTABLE(URIErrorCtor); -Heap::ErrorCtor::ErrorCtor(QV4::ExecutionContext *scope) - : Heap::FunctionObject(scope, QStringLiteral("Error")) +void Heap::ErrorCtor::init(QV4::ExecutionContext *scope) { + Heap::FunctionObject::init(scope, QStringLiteral("Error")); } -Heap::ErrorCtor::ErrorCtor(QV4::ExecutionContext *scope, const QString &name) - : Heap::FunctionObject(scope, name) +void Heap::ErrorCtor::init(QV4::ExecutionContext *scope, const QString &name) { + Heap::FunctionObject::init(scope, name); } -ReturnedValue ErrorCtor::construct(const Managed *m, CallData *callData) +void ErrorCtor::construct(const Managed *, Scope &scope, CallData *callData) { - Scope scope(static_cast<const ErrorCtor *>(m)->engine()); ScopedValue v(scope, callData->argument(0)); - return ErrorObject::create<ErrorObject>(scope.engine, v)->asReturnedValue(); + scope.result = ErrorObject::create<ErrorObject>(scope.engine, v); } -ReturnedValue ErrorCtor::call(const Managed *that, CallData *callData) +void ErrorCtor::call(const Managed *that, Scope &scope, CallData *callData) { - return static_cast<const Object *>(that)->construct(callData); + static_cast<const Object *>(that)->construct(scope, callData); } -Heap::EvalErrorCtor::EvalErrorCtor(QV4::ExecutionContext *scope) - : Heap::ErrorCtor(scope, QStringLiteral("EvalError")) +void Heap::EvalErrorCtor::init(QV4::ExecutionContext *scope) { + Heap::ErrorCtor::init(scope, QStringLiteral("EvalError")); } -ReturnedValue EvalErrorCtor::construct(const Managed *m, CallData *callData) +void EvalErrorCtor::construct(const Managed *, Scope &scope, CallData *callData) { - Scope scope(static_cast<const EvalErrorCtor *>(m)->engine()); ScopedValue v(scope, callData->argument(0)); - return ErrorObject::create<EvalErrorObject>(scope.engine, v)->asReturnedValue(); + scope.result = ErrorObject::create<EvalErrorObject>(scope.engine, v); } -Heap::RangeErrorCtor::RangeErrorCtor(QV4::ExecutionContext *scope) - : Heap::ErrorCtor(scope, QStringLiteral("RangeError")) +void Heap::RangeErrorCtor::init(QV4::ExecutionContext *scope) { + Heap::ErrorCtor::init(scope, QStringLiteral("RangeError")); } -ReturnedValue RangeErrorCtor::construct(const Managed *m, CallData *callData) +void RangeErrorCtor::construct(const Managed *, Scope &scope, CallData *callData) { - Scope scope(static_cast<const RangeErrorCtor *>(m)->engine()); ScopedValue v(scope, callData->argument(0)); - return ErrorObject::create<RangeErrorObject>(scope.engine, v)->asReturnedValue(); + scope.result = ErrorObject::create<RangeErrorObject>(scope.engine, v); } -Heap::ReferenceErrorCtor::ReferenceErrorCtor(QV4::ExecutionContext *scope) - : Heap::ErrorCtor(scope, QStringLiteral("ReferenceError")) +void Heap::ReferenceErrorCtor::init(QV4::ExecutionContext *scope) { + Heap::ErrorCtor::init(scope, QStringLiteral("ReferenceError")); } -ReturnedValue ReferenceErrorCtor::construct(const Managed *m, CallData *callData) +void ReferenceErrorCtor::construct(const Managed *, Scope &scope, CallData *callData) { - Scope scope(static_cast<const ReferenceErrorCtor *>(m)->engine()); ScopedValue v(scope, callData->argument(0)); - return ErrorObject::create<ReferenceErrorObject>(scope.engine, v)->asReturnedValue(); + scope.result = ErrorObject::create<ReferenceErrorObject>(scope.engine, v); } -Heap::SyntaxErrorCtor::SyntaxErrorCtor(QV4::ExecutionContext *scope) - : Heap::ErrorCtor(scope, QStringLiteral("SyntaxError")) +void Heap::SyntaxErrorCtor::init(QV4::ExecutionContext *scope) { + Heap::ErrorCtor::init(scope, QStringLiteral("SyntaxError")); } -ReturnedValue SyntaxErrorCtor::construct(const Managed *m, CallData *callData) +void SyntaxErrorCtor::construct(const Managed *, Scope &scope, CallData *callData) { - Scope scope(static_cast<const SyntaxErrorCtor *>(m)->engine()); ScopedValue v(scope, callData->argument(0)); - return ErrorObject::create<SyntaxErrorObject>(scope.engine, v)->asReturnedValue(); + scope.result = ErrorObject::create<SyntaxErrorObject>(scope.engine, v); } -Heap::TypeErrorCtor::TypeErrorCtor(QV4::ExecutionContext *scope) - : Heap::ErrorCtor(scope, QStringLiteral("TypeError")) +void Heap::TypeErrorCtor::init(QV4::ExecutionContext *scope) { + Heap::ErrorCtor::init(scope, QStringLiteral("TypeError")); } -ReturnedValue TypeErrorCtor::construct(const Managed *m, CallData *callData) +void TypeErrorCtor::construct(const Managed *, Scope &scope, CallData *callData) { - Scope scope(static_cast<const TypeErrorCtor *>(m)->engine()); ScopedValue v(scope, callData->argument(0)); - return ErrorObject::create<TypeErrorObject>(scope.engine, v)->asReturnedValue(); + scope.result = ErrorObject::create<TypeErrorObject>(scope.engine, v); } -Heap::URIErrorCtor::URIErrorCtor(QV4::ExecutionContext *scope) - : Heap::ErrorCtor(scope, QStringLiteral("URIError")) +void Heap::URIErrorCtor::init(QV4::ExecutionContext *scope) { + Heap::ErrorCtor::init(scope, QStringLiteral("URIError")); } -ReturnedValue URIErrorCtor::construct(const Managed *m, CallData *callData) +void URIErrorCtor::construct(const Managed *, Scope &scope, CallData *callData) { - Scope scope(static_cast<const URIErrorCtor *>(m)->engine()); ScopedValue v(scope, callData->argument(0)); - return ErrorObject::create<URIErrorObject>(scope.engine, v)->asReturnedValue(); + scope.result = ErrorObject::create<URIErrorObject>(scope.engine, v); } void ErrorPrototype::init(ExecutionEngine *engine, Object *ctor, Object *obj, Heap::ErrorObject::ErrorType t) |