From b3cdc489142e673c8cb6ac81df7d01191a30c1aa Mon Sep 17 00:00:00 2001 From: Lars Knoll Date: Fri, 28 Aug 2015 10:57:37 +0200 Subject: Simplify new construction scheme Declare the default prototype and internal class in the class itself. Change-Id: I08c2b42aa61a886580061336ae60cef8dedc0f03 Reviewed-by: Simon Hausmann --- src/qml/jsruntime/qv4arraybuffer_p.h | 1 + src/qml/jsruntime/qv4dateobject_p.h | 1 + src/qml/jsruntime/qv4engine.cpp | 42 +++++++++++++++++----------------- src/qml/jsruntime/qv4errorobject.cpp | 12 +++++----- src/qml/jsruntime/qv4errorobject_p.h | 8 +++++++ src/qml/jsruntime/qv4object_p.h | 14 ++++++++++++ src/qml/jsruntime/qv4regexpobject_p.h | 2 ++ src/qml/jsruntime/qv4stringobject_p.h | 2 ++ src/qml/jsruntime/qv4variantobject_p.h | 1 + 9 files changed, 56 insertions(+), 27 deletions(-) (limited to 'src/qml/jsruntime') diff --git a/src/qml/jsruntime/qv4arraybuffer_p.h b/src/qml/jsruntime/qv4arraybuffer_p.h index 2a5b812546..19fd74465c 100644 --- a/src/qml/jsruntime/qv4arraybuffer_p.h +++ b/src/qml/jsruntime/qv4arraybuffer_p.h @@ -72,6 +72,7 @@ struct Q_QML_PRIVATE_EXPORT ArrayBuffer : Object { V4_OBJECT2(ArrayBuffer, Object) V4_NEEDS_DESTROY + V4_PROTOTYPE(arrayBufferPrototype) QByteArray asByteArray() const; uint byteLength() const { return d()->byteLength(); } diff --git a/src/qml/jsruntime/qv4dateobject_p.h b/src/qml/jsruntime/qv4dateobject_p.h index 434eebfa43..a324e216e4 100644 --- a/src/qml/jsruntime/qv4dateobject_p.h +++ b/src/qml/jsruntime/qv4dateobject_p.h @@ -69,6 +69,7 @@ struct DateCtor : FunctionObject { struct DateObject: Object { V4_OBJECT2(DateObject, Object) Q_MANAGED_TYPE(DateObject) + V4_PROTOTYPE(datePrototype) double date() const { return d()->date; } diff --git a/src/qml/jsruntime/qv4engine.cpp b/src/qml/jsruntime/qv4engine.cpp index 1a480f1aa4..8fabecb3d4 100644 --- a/src/qml/jsruntime/qv4engine.cpp +++ b/src/qml/jsruntime/qv4engine.cpp @@ -567,7 +567,7 @@ ExecutionContext *ExecutionEngine::parentContext(ExecutionContext *context) cons Heap::Object *ExecutionEngine::newObject() { - return memoryManager->allocObject(emptyClass, objectPrototype()); + return memoryManager->allocObject(); } Heap::Object *ExecutionEngine::newObject(InternalClass *internalClass, QV4::Object *prototype) @@ -588,23 +588,23 @@ Heap::String *ExecutionEngine::newIdentifier(const QString &text) Heap::Object *ExecutionEngine::newStringObject(const String *string) { - return memoryManager->allocObject(stringClass, stringPrototype(), string); + return memoryManager->allocObject(string); } Heap::Object *ExecutionEngine::newNumberObject(double value) { - return memoryManager->allocObject(emptyClass, numberPrototype(), value); + return memoryManager->allocObject(value); } Heap::Object *ExecutionEngine::newBooleanObject(bool b) { - return memoryManager->allocObject(emptyClass, booleanPrototype(), b); + return memoryManager->allocObject(b); } Heap::ArrayObject *ExecutionEngine::newArrayObject(int count) { Scope scope(this); - ScopedArrayObject object(scope, memoryManager->allocObject(arrayClass, arrayPrototype())); + ScopedArrayObject object(scope, memoryManager->allocObject()); if (count) { if (count < 0x1000) @@ -617,7 +617,7 @@ Heap::ArrayObject *ExecutionEngine::newArrayObject(int count) Heap::ArrayObject *ExecutionEngine::newArrayObject(const QStringList &list) { Scope scope(this); - ScopedArrayObject object(scope, memoryManager->allocObject(arrayClass, arrayPrototype(), list)); + ScopedArrayObject object(scope, memoryManager->allocObject(list)); return object->d(); } @@ -630,24 +630,24 @@ Heap::ArrayObject *ExecutionEngine::newArrayObject(InternalClass *internalClass, Heap::ArrayBuffer *ExecutionEngine::newArrayBuffer(const QByteArray &array) { - return memoryManager->allocObject(emptyClass, arrayBufferPrototype(), array); + return memoryManager->allocObject(array); } Heap::ArrayBuffer *ExecutionEngine::newArrayBuffer(size_t length) { - return memoryManager->allocObject(emptyClass, arrayBufferPrototype(), length); + return memoryManager->allocObject(length); } Heap::DateObject *ExecutionEngine::newDateObject(const Value &value) { - return memoryManager->allocObject(emptyClass, datePrototype(), value); + return memoryManager->allocObject(value); } Heap::DateObject *ExecutionEngine::newDateObject(const QDateTime &dt) { Scope scope(this); - Scoped object(scope, memoryManager->allocObject(emptyClass, datePrototype(), dt)); + Scoped object(scope, memoryManager->allocObject(dt)); return object->d(); } @@ -668,18 +668,18 @@ Heap::RegExpObject *ExecutionEngine::newRegExpObject(const QString &pattern, int Heap::RegExpObject *ExecutionEngine::newRegExpObject(RegExp *re, bool global) { - return memoryManager->allocObject(regExpObjectClass, regExpPrototype(), re, global); + return memoryManager->allocObject(re, global); } Heap::RegExpObject *ExecutionEngine::newRegExpObject(const QRegExp &re) { - return memoryManager->allocObject(regExpObjectClass, regExpPrototype(), re); + return memoryManager->allocObject(re); } Heap::Object *ExecutionEngine::newErrorObject(const Value &value) { Scope scope(this); - ScopedObject object(scope, memoryManager->allocObject(errorClass, errorPrototype(), value)); + ScopedObject object(scope, memoryManager->allocObject(value)); return object->d(); } @@ -687,13 +687,13 @@ Heap::Object *ExecutionEngine::newSyntaxErrorObject(const QString &message) { Scope scope(this); ScopedString s(scope, newString(message)); - return memoryManager->allocObject(errorClass, syntaxErrorPrototype(), s); + return memoryManager->allocObject(s); } Heap::Object *ExecutionEngine::newSyntaxErrorObject(const QString &message, const QString &fileName, int line, int column) { Scope scope(this); - ScopedObject error(scope, memoryManager->allocObject(errorClass, syntaxErrorPrototype(), message, fileName, line, column)); + ScopedObject error(scope, memoryManager->allocObject(message, fileName, line, column)); return error->d(); } @@ -701,14 +701,14 @@ Heap::Object *ExecutionEngine::newSyntaxErrorObject(const QString &message, cons Heap::Object *ExecutionEngine::newReferenceErrorObject(const QString &message) { Scope scope(this); - ScopedObject o(scope, memoryManager->allocObject(errorClass, referenceErrorPrototype(), message)); + ScopedObject o(scope, memoryManager->allocObject(message)); return o->d(); } Heap::Object *ExecutionEngine::newReferenceErrorObject(const QString &message, const QString &fileName, int lineNumber, int columnNumber) { Scope scope(this); - ScopedObject o(scope, memoryManager->allocObject(errorClass, referenceErrorPrototype(), message, fileName, lineNumber, columnNumber)); + ScopedObject o(scope, memoryManager->allocObject(message, fileName, lineNumber, columnNumber)); return o->d(); } @@ -716,27 +716,27 @@ Heap::Object *ExecutionEngine::newReferenceErrorObject(const QString &message, c Heap::Object *ExecutionEngine::newTypeErrorObject(const QString &message) { Scope scope(this); - ScopedObject o(scope, memoryManager->allocObject(errorClass, typeErrorPrototype(), message)); + ScopedObject o(scope, memoryManager->allocObject(message)); return o->d(); } Heap::Object *ExecutionEngine::newRangeErrorObject(const QString &message) { Scope scope(this); - ScopedObject o(scope, memoryManager->allocObject(errorClass, rangeErrorPrototype(), message)); + ScopedObject o(scope, memoryManager->allocObject(message)); return o->d(); } Heap::Object *ExecutionEngine::newURIErrorObject(const Value &message) { Scope scope(this); - ScopedObject o(scope, memoryManager->allocObject(errorClass, uRIErrorPrototype(), message)); + ScopedObject o(scope, memoryManager->allocObject(message)); return o->d(); } Heap::Object *ExecutionEngine::newVariantObject(const QVariant &v) { - return memoryManager->allocObject(emptyClass, variantPrototype(), v); + return memoryManager->allocObject(v); } Heap::Object *ExecutionEngine::newForEachIteratorObject(Object *o) diff --git a/src/qml/jsruntime/qv4errorobject.cpp b/src/qml/jsruntime/qv4errorobject.cpp index eb45ca6513..219f4845c4 100644 --- a/src/qml/jsruntime/qv4errorobject.cpp +++ b/src/qml/jsruntime/qv4errorobject.cpp @@ -274,7 +274,7 @@ ReturnedValue EvalErrorCtor::construct(const Managed *m, CallData *callData) { Scope scope(static_cast(m)->engine()); ScopedValue v(scope, callData->argument(0)); - return (scope.engine->memoryManager->allocObject(scope.engine->errorClass, scope.engine->evalErrorPrototype(), v))->asReturnedValue(); + return (scope.engine->memoryManager->allocObject(v))->asReturnedValue(); } Heap::RangeErrorCtor::RangeErrorCtor(QV4::ExecutionContext *scope) @@ -286,7 +286,7 @@ ReturnedValue RangeErrorCtor::construct(const Managed *m, CallData *callData) { Scope scope(static_cast(m)->engine()); ScopedValue v(scope, callData->argument(0)); - return (scope.engine->memoryManager->allocObject(scope.engine->errorClass, scope.engine->evalErrorPrototype(), v))->asReturnedValue(); + return (scope.engine->memoryManager->allocObject(v))->asReturnedValue(); } Heap::ReferenceErrorCtor::ReferenceErrorCtor(QV4::ExecutionContext *scope) @@ -298,7 +298,7 @@ ReturnedValue ReferenceErrorCtor::construct(const Managed *m, CallData *callData { Scope scope(static_cast(m)->engine()); ScopedValue v(scope, callData->argument(0)); - return (scope.engine->memoryManager->allocObject(scope.engine->errorClass, scope.engine->referenceErrorPrototype(), v))->asReturnedValue(); + return (scope.engine->memoryManager->allocObject(v))->asReturnedValue(); } Heap::SyntaxErrorCtor::SyntaxErrorCtor(QV4::ExecutionContext *scope) @@ -310,7 +310,7 @@ ReturnedValue SyntaxErrorCtor::construct(const Managed *m, CallData *callData) { Scope scope(static_cast(m)->engine()); ScopedValue v(scope, callData->argument(0)); - return (scope.engine->memoryManager->allocObject(scope.engine->errorClass, scope.engine->syntaxErrorPrototype(), v))->asReturnedValue(); + return (scope.engine->memoryManager->allocObject(v))->asReturnedValue(); } Heap::TypeErrorCtor::TypeErrorCtor(QV4::ExecutionContext *scope) @@ -322,7 +322,7 @@ ReturnedValue TypeErrorCtor::construct(const Managed *m, CallData *callData) { Scope scope(static_cast(m)->engine()); ScopedValue v(scope, callData->argument(0)); - return (scope.engine->memoryManager->allocObject(scope.engine->errorClass, scope.engine->typeErrorPrototype(), v))->asReturnedValue(); + return (scope.engine->memoryManager->allocObject(v))->asReturnedValue(); } Heap::URIErrorCtor::URIErrorCtor(QV4::ExecutionContext *scope) @@ -334,7 +334,7 @@ ReturnedValue URIErrorCtor::construct(const Managed *m, CallData *callData) { Scope scope(static_cast(m)->engine()); ScopedValue v(scope, callData->argument(0)); - return (scope.engine->memoryManager->allocObject(scope.engine->errorClass, scope.engine->uRIErrorPrototype(), v))->asReturnedValue(); + return (scope.engine->memoryManager->allocObject(v))->asReturnedValue(); } void ErrorPrototype::init(ExecutionEngine *engine, Object *ctor, Object *obj) diff --git a/src/qml/jsruntime/qv4errorobject_p.h b/src/qml/jsruntime/qv4errorobject_p.h index ec7de590bf..050979ad53 100644 --- a/src/qml/jsruntime/qv4errorobject_p.h +++ b/src/qml/jsruntime/qv4errorobject_p.h @@ -140,6 +140,8 @@ struct ErrorObject: Object { V4_OBJECT2(ErrorObject, Object) Q_MANAGED_TYPE(ErrorObject) + V4_INTERNALCLASS(errorClass) + V4_PROTOTYPE(errorPrototype) V4_NEEDS_DESTROY SyntaxErrorObject *asSyntaxError(); @@ -155,34 +157,40 @@ inline const ErrorObject *Value::as() const { struct EvalErrorObject: ErrorObject { typedef Heap::EvalErrorObject Data; + V4_PROTOTYPE(evalErrorPrototype) const Data *d() const { return static_cast(ErrorObject::d()); } Data *d() { return static_cast(ErrorObject::d()); } }; struct RangeErrorObject: ErrorObject { typedef Heap::RangeErrorObject Data; + V4_PROTOTYPE(rangeErrorPrototype) const Data *d() const { return static_cast(ErrorObject::d()); } Data *d() { return static_cast(ErrorObject::d()); } }; struct ReferenceErrorObject: ErrorObject { typedef Heap::ReferenceErrorObject Data; + V4_PROTOTYPE(referenceErrorPrototype) const Data *d() const { return static_cast(ErrorObject::d()); } Data *d() { return static_cast(ErrorObject::d()); } }; struct SyntaxErrorObject: ErrorObject { V4_OBJECT2(SyntaxErrorObject, ErrorObject) + V4_PROTOTYPE(syntaxErrorPrototype) }; struct TypeErrorObject: ErrorObject { typedef Heap::TypeErrorObject Data; + V4_PROTOTYPE(typeErrorPrototype) const Data *d() const { return static_cast(ErrorObject::d()); } Data *d() { return static_cast(ErrorObject::d()); } }; struct URIErrorObject: ErrorObject { typedef Heap::URIErrorObject Data; + V4_PROTOTYPE(uRIErrorPrototype) const Data *d() const { return static_cast(ErrorObject::d()); } Data *d() { return static_cast(ErrorObject::d()); } }; diff --git a/src/qml/jsruntime/qv4object_p.h b/src/qml/jsruntime/qv4object_p.h index 578e4065c3..cd54e6c83d 100644 --- a/src/qml/jsruntime/qv4object_p.h +++ b/src/qml/jsruntime/qv4object_p.h @@ -42,6 +42,7 @@ QT_BEGIN_NAMESPACE + namespace QV4 { namespace Heap { @@ -83,6 +84,13 @@ struct Object : Base { V4_MANAGED_SIZE_TEST \ QV4::Heap::DataClass *d() const { return static_cast(m()); } +#define V4_INTERNALCLASS(c) \ + static QV4::InternalClass *defaultInternalClass(QV4::ExecutionEngine *e) \ + { return e->c; } +#define V4_PROTOTYPE(p) \ + static QV4::Object *defaultPrototype(QV4::ExecutionEngine *e) \ + { return e->p(); } + struct ObjectVTable { VTable vTable; @@ -127,6 +135,8 @@ const QV4::ObjectVTable classname::static_vtbl = \ struct Q_QML_EXPORT Object: Managed { V4_OBJECT2(Object, Object) Q_MANAGED_TYPE(Object) + V4_INTERNALCLASS(emptyClass) + V4_PROTOTYPE(objectPrototype) enum { IsObject = true, @@ -372,6 +382,7 @@ struct ArrayObject : Object { struct BooleanObject: Object { V4_OBJECT2(BooleanObject, Object) Q_MANAGED_TYPE(BooleanObject) + V4_PROTOTYPE(booleanPrototype) bool value() const { return d()->b; } @@ -380,6 +391,7 @@ struct BooleanObject: Object { struct NumberObject: Object { V4_OBJECT2(NumberObject, Object) Q_MANAGED_TYPE(NumberObject) + V4_PROTOTYPE(numberPrototype) double value() const { return d()->value; } }; @@ -387,6 +399,8 @@ struct NumberObject: Object { struct ArrayObject: Object { V4_OBJECT2(ArrayObject, Object) Q_MANAGED_TYPE(ArrayObject) + V4_INTERNALCLASS(arrayClass) + V4_PROTOTYPE(arrayPrototype) void init(ExecutionEngine *engine); diff --git a/src/qml/jsruntime/qv4regexpobject_p.h b/src/qml/jsruntime/qv4regexpobject_p.h index 0c9757a514..4f803df9c8 100644 --- a/src/qml/jsruntime/qv4regexpobject_p.h +++ b/src/qml/jsruntime/qv4regexpobject_p.h @@ -79,6 +79,8 @@ struct RegExpCtor : FunctionObject { struct RegExpObject: Object { V4_OBJECT2(RegExpObject, Object) Q_MANAGED_TYPE(RegExpObject) + V4_INTERNALCLASS(regExpObjectClass) + V4_PROTOTYPE(regExpPrototype) // needs to be compatible with the flags in qv4jsir_p.h enum Flags { diff --git a/src/qml/jsruntime/qv4stringobject_p.h b/src/qml/jsruntime/qv4stringobject_p.h index 4a7a0b383e..86d77c726a 100644 --- a/src/qml/jsruntime/qv4stringobject_p.h +++ b/src/qml/jsruntime/qv4stringobject_p.h @@ -65,6 +65,8 @@ struct StringCtor : FunctionObject { struct StringObject: Object { V4_OBJECT2(StringObject, Object) Q_MANAGED_TYPE(StringObject) + V4_INTERNALCLASS(stringClass) + V4_PROTOTYPE(stringPrototype) Heap::String *getIndex(uint index) const { return d()->getIndex(index); diff --git a/src/qml/jsruntime/qv4variantobject_p.h b/src/qml/jsruntime/qv4variantobject_p.h index 40a45f8eb5..4680912354 100644 --- a/src/qml/jsruntime/qv4variantobject_p.h +++ b/src/qml/jsruntime/qv4variantobject_p.h @@ -75,6 +75,7 @@ struct VariantObject : Object, public ExecutionEngine::ScarceResourceData struct VariantObject : Object { V4_OBJECT2(VariantObject, Object) + V4_PROTOTYPE(variantPrototype) V4_NEEDS_DESTROY void addVmePropertyReference(); -- cgit v1.2.3