aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/qml/jsruntime/qv4arraybuffer_p.h1
-rw-r--r--src/qml/jsruntime/qv4dateobject_p.h1
-rw-r--r--src/qml/jsruntime/qv4engine.cpp42
-rw-r--r--src/qml/jsruntime/qv4errorobject.cpp12
-rw-r--r--src/qml/jsruntime/qv4errorobject_p.h8
-rw-r--r--src/qml/jsruntime/qv4object_p.h14
-rw-r--r--src/qml/jsruntime/qv4regexpobject_p.h2
-rw-r--r--src/qml/jsruntime/qv4stringobject_p.h2
-rw-r--r--src/qml/jsruntime/qv4variantobject_p.h1
-rw-r--r--src/qml/memory/qv4mm_p.h107
10 files changed, 133 insertions, 57 deletions
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<Object>(emptyClass, objectPrototype());
+ return memoryManager->allocObject<Object>();
}
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<StringObject>(stringClass, stringPrototype(), string);
+ return memoryManager->allocObject<StringObject>(string);
}
Heap::Object *ExecutionEngine::newNumberObject(double value)
{
- return memoryManager->allocObject<NumberObject>(emptyClass, numberPrototype(), value);
+ return memoryManager->allocObject<NumberObject>(value);
}
Heap::Object *ExecutionEngine::newBooleanObject(bool b)
{
- return memoryManager->allocObject<BooleanObject>(emptyClass, booleanPrototype(), b);
+ return memoryManager->allocObject<BooleanObject>(b);
}
Heap::ArrayObject *ExecutionEngine::newArrayObject(int count)
{
Scope scope(this);
- ScopedArrayObject object(scope, memoryManager->allocObject<ArrayObject>(arrayClass, arrayPrototype()));
+ ScopedArrayObject object(scope, memoryManager->allocObject<ArrayObject>());
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<ArrayObject>(arrayClass, arrayPrototype(), list));
+ ScopedArrayObject object(scope, memoryManager->allocObject<ArrayObject>(list));
return object->d();
}
@@ -630,24 +630,24 @@ Heap::ArrayObject *ExecutionEngine::newArrayObject(InternalClass *internalClass,
Heap::ArrayBuffer *ExecutionEngine::newArrayBuffer(const QByteArray &array)
{
- return memoryManager->allocObject<ArrayBuffer>(emptyClass, arrayBufferPrototype(), array);
+ return memoryManager->allocObject<ArrayBuffer>(array);
}
Heap::ArrayBuffer *ExecutionEngine::newArrayBuffer(size_t length)
{
- return memoryManager->allocObject<ArrayBuffer>(emptyClass, arrayBufferPrototype(), length);
+ return memoryManager->allocObject<ArrayBuffer>(length);
}
Heap::DateObject *ExecutionEngine::newDateObject(const Value &value)
{
- return memoryManager->allocObject<DateObject>(emptyClass, datePrototype(), value);
+ return memoryManager->allocObject<DateObject>(value);
}
Heap::DateObject *ExecutionEngine::newDateObject(const QDateTime &dt)
{
Scope scope(this);
- Scoped<DateObject> object(scope, memoryManager->allocObject<DateObject>(emptyClass, datePrototype(), dt));
+ Scoped<DateObject> object(scope, memoryManager->allocObject<DateObject>(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<RegExpObject>(regExpObjectClass, regExpPrototype(), re, global);
+ return memoryManager->allocObject<RegExpObject>(re, global);
}
Heap::RegExpObject *ExecutionEngine::newRegExpObject(const QRegExp &re)
{
- return memoryManager->allocObject<RegExpObject>(regExpObjectClass, regExpPrototype(), re);
+ return memoryManager->allocObject<RegExpObject>(re);
}
Heap::Object *ExecutionEngine::newErrorObject(const Value &value)
{
Scope scope(this);
- ScopedObject object(scope, memoryManager->allocObject<ErrorObject>(errorClass, errorPrototype(), value));
+ ScopedObject object(scope, memoryManager->allocObject<ErrorObject>(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<SyntaxErrorObject>(errorClass, syntaxErrorPrototype(), s);
+ return memoryManager->allocObject<SyntaxErrorObject>(s);
}
Heap::Object *ExecutionEngine::newSyntaxErrorObject(const QString &message, const QString &fileName, int line, int column)
{
Scope scope(this);
- ScopedObject error(scope, memoryManager->allocObject<SyntaxErrorObject>(errorClass, syntaxErrorPrototype(), message, fileName, line, column));
+ ScopedObject error(scope, memoryManager->allocObject<SyntaxErrorObject>(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<ReferenceErrorObject>(errorClass, referenceErrorPrototype(), message));
+ ScopedObject o(scope, memoryManager->allocObject<ReferenceErrorObject>(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<ReferenceErrorObject>(errorClass, referenceErrorPrototype(), message, fileName, lineNumber, columnNumber));
+ ScopedObject o(scope, memoryManager->allocObject<ReferenceErrorObject>(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<TypeErrorObject>(errorClass, typeErrorPrototype(), message));
+ ScopedObject o(scope, memoryManager->allocObject<TypeErrorObject>(message));
return o->d();
}
Heap::Object *ExecutionEngine::newRangeErrorObject(const QString &message)
{
Scope scope(this);
- ScopedObject o(scope, memoryManager->allocObject<RangeErrorObject>(errorClass, rangeErrorPrototype(), message));
+ ScopedObject o(scope, memoryManager->allocObject<RangeErrorObject>(message));
return o->d();
}
Heap::Object *ExecutionEngine::newURIErrorObject(const Value &message)
{
Scope scope(this);
- ScopedObject o(scope, memoryManager->allocObject<URIErrorObject>(errorClass, uRIErrorPrototype(), message));
+ ScopedObject o(scope, memoryManager->allocObject<URIErrorObject>(message));
return o->d();
}
Heap::Object *ExecutionEngine::newVariantObject(const QVariant &v)
{
- return memoryManager->allocObject<VariantObject>(emptyClass, variantPrototype(), v);
+ return memoryManager->allocObject<VariantObject>(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<const EvalErrorCtor *>(m)->engine());
ScopedValue v(scope, callData->argument(0));
- return (scope.engine->memoryManager->allocObject<EvalErrorObject>(scope.engine->errorClass, scope.engine->evalErrorPrototype(), v))->asReturnedValue();
+ return (scope.engine->memoryManager->allocObject<EvalErrorObject>(v))->asReturnedValue();
}
Heap::RangeErrorCtor::RangeErrorCtor(QV4::ExecutionContext *scope)
@@ -286,7 +286,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>(scope.engine->errorClass, scope.engine->evalErrorPrototype(), v))->asReturnedValue();
+ return (scope.engine->memoryManager->allocObject<RangeErrorObject>(v))->asReturnedValue();
}
Heap::ReferenceErrorCtor::ReferenceErrorCtor(QV4::ExecutionContext *scope)
@@ -298,7 +298,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>(scope.engine->errorClass, scope.engine->referenceErrorPrototype(), v))->asReturnedValue();
+ return (scope.engine->memoryManager->allocObject<ReferenceErrorObject>(v))->asReturnedValue();
}
Heap::SyntaxErrorCtor::SyntaxErrorCtor(QV4::ExecutionContext *scope)
@@ -310,7 +310,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>(scope.engine->errorClass, scope.engine->syntaxErrorPrototype(), v))->asReturnedValue();
+ return (scope.engine->memoryManager->allocObject<SyntaxErrorObject>(v))->asReturnedValue();
}
Heap::TypeErrorCtor::TypeErrorCtor(QV4::ExecutionContext *scope)
@@ -322,7 +322,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>(scope.engine->errorClass, scope.engine->typeErrorPrototype(), v))->asReturnedValue();
+ return (scope.engine->memoryManager->allocObject<TypeErrorObject>(v))->asReturnedValue();
}
Heap::URIErrorCtor::URIErrorCtor(QV4::ExecutionContext *scope)
@@ -334,7 +334,7 @@ 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>(scope.engine->errorClass, scope.engine->uRIErrorPrototype(), v))->asReturnedValue();
+ return (scope.engine->memoryManager->allocObject<URIErrorObject>(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<const Data *>(ErrorObject::d()); }
Data *d() { return static_cast<Data *>(ErrorObject::d()); }
};
struct RangeErrorObject: ErrorObject {
typedef Heap::RangeErrorObject Data;
+ V4_PROTOTYPE(rangeErrorPrototype)
const Data *d() const { return static_cast<const Data *>(ErrorObject::d()); }
Data *d() { return static_cast<Data *>(ErrorObject::d()); }
};
struct ReferenceErrorObject: ErrorObject {
typedef Heap::ReferenceErrorObject Data;
+ V4_PROTOTYPE(referenceErrorPrototype)
const Data *d() const { return static_cast<const Data *>(ErrorObject::d()); }
Data *d() { return static_cast<Data *>(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<const Data *>(ErrorObject::d()); }
Data *d() { return static_cast<Data *>(ErrorObject::d()); }
};
struct URIErrorObject: ErrorObject {
typedef Heap::URIErrorObject Data;
+ V4_PROTOTYPE(uRIErrorPrototype)
const Data *d() const { return static_cast<const Data *>(ErrorObject::d()); }
Data *d() { return static_cast<Data *>(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<QV4::Heap::DataClass *>(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();
diff --git a/src/qml/memory/qv4mm_p.h b/src/qml/memory/qv4mm_p.h
index f21e96beb0..94abf491f3 100644
--- a/src/qml/memory/qv4mm_p.h
+++ b/src/qml/memory/qv4mm_p.h
@@ -92,6 +92,31 @@ public:
return static_cast<typename ManagedType::Data *>(o);
}
+ template <typename ObjectType>
+ typename ObjectType::Data *allocateObject(InternalClass *ic)
+ {
+ const int size = (sizeof(typename ObjectType::Data) + (sizeof(Value) - 1)) & ~(sizeof(Value) - 1);
+ typename ObjectType::Data *o = allocManaged<ObjectType>(size + ic->size*sizeof(Value));
+ o->internalClass = ic;
+ o->inlineMemberSize = ic->size;
+ o->inlineMemberOffset = size/sizeof(Value);
+ return o;
+ }
+
+ template <typename ObjectType>
+ typename ObjectType::Data *allocateObject()
+ {
+ InternalClass *ic = ObjectType::defaultInternalClass(engine());
+ const int size = (sizeof(typename ObjectType::Data) + (sizeof(Value) - 1)) & ~(sizeof(Value) - 1);
+ typename ObjectType::Data *o = allocManaged<ObjectType>(size + ic->size*sizeof(Value));
+ Object *prototype = ObjectType::defaultPrototype(engine());
+ o->internalClass = ic;
+ o->prototype = prototype->d();
+ o->inlineMemberSize = ic->size;
+ o->inlineMemberOffset = size/sizeof(Value);
+ return o;
+ }
+
template <typename ManagedType, typename Arg1>
typename ManagedType::Data *allocWithStringData(std::size_t unmanagedSize, Arg1 arg1)
{
@@ -105,11 +130,7 @@ public:
typename ObjectType::Data *allocObject(InternalClass *ic)
{
Scope scope(engine());
- const int size = (sizeof(typename ObjectType::Data) + (sizeof(Value) - 1)) & ~(sizeof(Value) - 1);
- Scoped<ObjectType> t(scope, allocManaged<ObjectType>(size + ic->size*sizeof(Value)));
- t->d()->internalClass = ic;
- t->d()->inlineMemberSize = ic->size;
- t->d()->inlineMemberOffset = size/sizeof(Value);
+ Scoped<ObjectType> t(scope, allocateObject<ObjectType>(ic));
(void)new (t->d()) typename ObjectType::Data();
return t->d();
}
@@ -118,12 +139,8 @@ public:
typename ObjectType::Data *allocObject(InternalClass *ic, Object *prototype)
{
Scope scope(engine());
- const int size = (sizeof(typename ObjectType::Data) + (sizeof(Value) - 1)) & ~(sizeof(Value) - 1);
- Scoped<ObjectType> t(scope, allocManaged<ObjectType>(size + ic->size*sizeof(Value)));
- t->d()->internalClass = ic;
+ Scoped<ObjectType> t(scope, allocateObject<ObjectType>(ic));
t->d()->prototype = prototype->d();
- t->d()->inlineMemberSize = ic->size;
- t->d()->inlineMemberOffset = size/sizeof(Value);
(void)new (t->d()) typename ObjectType::Data();
return t->d();
}
@@ -132,12 +149,8 @@ public:
typename ObjectType::Data *allocObject(InternalClass *ic, Object *prototype, Arg1 arg1)
{
Scope scope(engine());
- const int size = (sizeof(typename ObjectType::Data) + (sizeof(Value) - 1)) & ~(sizeof(Value) - 1);
- Scoped<ObjectType> t(scope, allocManaged<ObjectType>(size + ic->size*sizeof(Value)));
- t->d()->internalClass = ic;
+ Scoped<ObjectType> t(scope, allocateObject<ObjectType>(ic));
t->d()->prototype = prototype->d();
- t->d()->inlineMemberSize = ic->size;
- t->d()->inlineMemberOffset = size/sizeof(Value);
(void)new (t->d()) typename ObjectType::Data(arg1);
return t->d();
}
@@ -146,12 +159,8 @@ public:
typename ObjectType::Data *allocObject(InternalClass *ic, Object *prototype, Arg1 arg1, Arg2 arg2)
{
Scope scope(engine());
- const int size = (sizeof(typename ObjectType::Data) + (sizeof(Value) - 1)) & ~(sizeof(Value) - 1);
- Scoped<ObjectType> t(scope, allocManaged<ObjectType>(size + ic->size*sizeof(Value)));
- t->d()->internalClass = ic;
+ Scoped<ObjectType> t(scope, allocateObject<ObjectType>(ic));
t->d()->prototype = prototype->d();
- t->d()->inlineMemberSize = ic->size;
- t->d()->inlineMemberOffset = size/sizeof(Value);
(void)new (t->d()) typename ObjectType::Data(arg1, arg2);
return t->d();
}
@@ -160,12 +169,8 @@ public:
typename ObjectType::Data *allocObject(InternalClass *ic, Object *prototype, Arg1 arg1, Arg2 arg2, Arg3 arg3)
{
Scope scope(engine());
- const int size = (sizeof(typename ObjectType::Data) + (sizeof(Value) - 1)) & ~(sizeof(Value) - 1);
- Scoped<ObjectType> t(scope, allocManaged<ObjectType>(size + ic->size*sizeof(Value)));
- t->d()->internalClass = ic;
+ Scoped<ObjectType> t(scope, allocateObject<ObjectType>(ic));
t->d()->prototype = prototype->d();
- t->d()->inlineMemberSize = ic->size;
- t->d()->inlineMemberOffset = size/sizeof(Value);
(void)new (t->d()) typename ObjectType::Data(arg1, arg2, arg3);
return t->d();
}
@@ -174,16 +179,58 @@ public:
typename ObjectType::Data *allocObject(InternalClass *ic, Object *prototype, Arg1 arg1, Arg2 arg2, Arg3 arg3, Arg4 arg4)
{
Scope scope(engine());
- const int size = (sizeof(typename ObjectType::Data) + (sizeof(Value) - 1)) & ~(sizeof(Value) - 1);
- Scoped<ObjectType> t(scope, allocManaged<ObjectType>(size + ic->size*sizeof(Value)));
- t->d()->internalClass = ic;
+ Scoped<ObjectType> t(scope, allocateObject<ObjectType>(ic));
t->d()->prototype = prototype->d();
- t->d()->inlineMemberSize = ic->size;
- t->d()->inlineMemberOffset = size/sizeof(Value);
(void)new (t->d()) typename ObjectType::Data(arg1, arg2, arg3, arg4);
return t->d();
}
+ template <typename ObjectType>
+ typename ObjectType::Data *allocObject()
+ {
+ Scope scope(engine());
+ Scoped<ObjectType> t(scope, allocateObject<ObjectType>());
+ (void)new (t->d()) typename ObjectType::Data();
+ return t->d();
+ }
+
+ template <typename ObjectType, typename Arg1>
+ typename ObjectType::Data *allocObject(Arg1 arg1)
+ {
+ Scope scope(engine());
+ Scoped<ObjectType> t(scope, allocateObject<ObjectType>());
+ (void)new (t->d()) typename ObjectType::Data(arg1);
+ return t->d();
+ }
+
+ template <typename ObjectType, typename Arg1, typename Arg2>
+ typename ObjectType::Data *allocObject(Arg1 arg1, Arg2 arg2)
+ {
+ Scope scope(engine());
+ Scoped<ObjectType> t(scope, allocateObject<ObjectType>());
+ (void)new (t->d()) typename ObjectType::Data(arg1, arg2);
+ return t->d();
+ }
+
+ template <typename ObjectType, typename Arg1, typename Arg2, typename Arg3>
+ typename ObjectType::Data *allocObject(Arg1 arg1, Arg2 arg2, Arg3 arg3)
+ {
+ Scope scope(engine());
+ Scoped<ObjectType> t(scope, allocateObject<ObjectType>());
+ (void)new (t->d()) typename ObjectType::Data(arg1, arg2, arg3);
+ return t->d();
+ }
+
+ template <typename ObjectType, typename Arg1, typename Arg2, typename Arg3, typename Arg4>
+ typename ObjectType::Data *allocObject(Arg1 arg1, Arg2 arg2, Arg3 arg3, Arg4 arg4)
+ {
+ Scope scope(engine());
+ Scoped<ObjectType> t(scope, allocateObject<ObjectType>());
+ (void)new (t->d()) typename ObjectType::Data(arg1, arg2, arg3, arg4);
+ return t->d();
+ }
+
+
template <typename ManagedType>
typename ManagedType::Data *alloc()
{