This makes all runtime structures fully non virtual.
Change-Id: I804568ca9bc33d4be0324ed542df8eab5892c0eb
Reviewed-by: Simon Hausmann <simon.hausmann@digia.com>
}
}
+void ArgumentsObject::destroy(Managed *that)
+{
+ static_cast<ArgumentsObject *>(that)->~ArgumentsObject();
+}
+
bool ArgumentsObject::defineOwnProperty(ExecutionContext *ctx, uint index, const PropertyDescriptor *desc)
{
PropertyDescriptor *pd = arrayAt(index);
ExecutionContext *context;
QVector<Value> mappedArguments;
ArgumentsObject(ExecutionContext *context, int formalParameterCount, int actualParameterCount);
+ ~ArgumentsObject() {}
bool defineOwnProperty(ExecutionContext *ctx, uint index, const PropertyDescriptor *desc);
- static const ManagedVTable static_vtbl;
static void markObjects(Managed *that);
+protected:
+ static const ManagedVTable static_vtbl;
+ static void destroy(Managed *);
};
}
defineDefaultProperty(ctx, QLatin1String("name"), Value::fromString(ctx, className()));
}
+DEFINE_MANAGED_VTABLE(SyntaxErrorObject);
+
SyntaxErrorObject::SyntaxErrorObject(ExecutionContext *ctx, DiagnosticMessage *message)
: ErrorObject(ctx->engine, message ? Value::fromString(message->buildFullMessage(ctx)) : ctx->argument(0))
, msg(message)
{
+ vtbl = &static_vtbl;
subtype = SyntaxError;
prototype = ctx->engine->syntaxErrorPrototype;
setNameProperty(ctx);
struct SyntaxErrorObject: ErrorObject {
SyntaxErrorObject(ExecutionContext *ctx, DiagnosticMessage *msg);
~SyntaxErrorObject() { delete msg; }
+ static void destroy(Managed *that) { static_cast<SyntaxErrorObject *>(that)->~SyntaxErrorObject(); }
DiagnosticMessage *message() { return msg; }
private:
DiagnosticMessage *msg;
+protected:
+ static const ManagedVTable static_vtbl;
};
struct TypeErrorObject: ErrorObject {
}
}
-ScriptFunction::~ScriptFunction()
-{
-}
-
Value ScriptFunction::construct(Managed *that, ExecutionContext *context, Value *args, int argc)
{
ScriptFunction *f = static_cast<ScriptFunction *>(that);
*insertMember(scope->engine->id_caller) = pd;
}
+void BoundFunction::destroy(Managed *that)
+{
+ static_cast<BoundFunction *>(that)->~BoundFunction();
+}
+
Value BoundFunction::call(Managed *that, ExecutionContext *context, const Value &, Value *args, int argc)
{
BoundFunction *f = static_cast<BoundFunction *>(that);
struct ScriptFunction: FunctionObject {
ScriptFunction(ExecutionContext *scope, VM::Function *function);
- ~ScriptFunction();
static Value construct(Managed *, ExecutionContext *context, Value *args, int argc);
static Value call(Managed *that, ExecutionContext *, const Value &, Value *, int);
BoundFunction(ExecutionContext *scope, FunctionObject *target, Value boundThis, const QVector<Value> &boundArgs);
~BoundFunction() {}
+
static Value construct(Managed *, ExecutionContext *context, Value *args, int argc);
static Value call(Managed *that, ExecutionContext *, const Value &, Value *, int);
static const ManagedVTable static_vtbl;
+ static void destroy(Managed *);
static void markObjects(Managed *that);
static bool hasInstance(Managed *that, ExecutionContext *ctx, const Value &value);
};
const ManagedVTable Managed::static_vtbl =
{
- "Managed",
+ call,
+ construct,
0 /*markObjects*/,
+ destroy,
hasInstance,
- construct,
- call,
- ManagedVTable::EndOfVTable
+ "Managed",
};
-Managed::~Managed()
-{
- _data = 0;
-}
-
void *Managed::operator new(size_t size, MemoryManager *mm)
{
assert(mm);
struct ManagedVTable
{
- enum _EndOfVTable {
- EndOfVTable
- };
- const char *className;
+ Value (*call)(Managed *, ExecutionContext *context, const Value &thisObject, Value *args, int argc);
+ Value (*construct)(Managed *, ExecutionContext *context, Value *args, int argc);
void (*markObjects)(Managed *);
+ void (*destroy)(Managed *);
bool (*hasInstance)(Managed *, ExecutionContext *ctx, const Value &value);
- Value (*construct)(Managed *, ExecutionContext *context, Value *args, int argc);
- Value (*call)(Managed *, ExecutionContext *context, const Value &thisObject, Value *args, int argc);
- _EndOfVTable endofVTable;
+ const char *className;
};
#define DEFINE_MANAGED_VTABLE(classname) \
const ManagedVTable classname::static_vtbl = \
{ \
- #classname, \
+ call, \
+ construct, \
markObjects, \
+ destroy, \
hasInstance, \
- construct, \
- call, \
- ManagedVTable::EndOfVTable \
+ #classname \
}
Managed()
: vtbl(&static_vtbl), _data(0)
{ inUse = 1; extensible = 1; }
- virtual ~Managed();
public:
void *operator new(size_t size, MemoryManager *mm);
inline Value construct(ExecutionContext *context, Value *args, int argc);
inline Value call(ExecutionContext *context, const Value &thisObject, Value *args, int argc);
+ static void destroy(Managed *that) { that->_data = 0; }
static bool hasInstance(Managed *that, ExecutionContext *ctx, const Value &value);
static Value construct(Managed *, ExecutionContext *context, Value *, int);
static Value call(Managed *, ExecutionContext *, const Value &, Value *, int);
protected:
static const ManagedVTable static_vtbl;
+
const ManagedVTable *vtbl;
union {
m->markBit = 0;
} else {
// qDebug() << "-- collecting it." << m << *f << m->nextFree();
- m->~Managed();
+ m->vtbl->destroy(m);
m->setNextFree(*f);
*f = m;
delete [] memberData;
delete [] (arrayData - (sparseArray ? 0 : arrayOffset));
delete sparseArray;
+ _data = 0;
+}
+
+void Object::destroy(Managed *that)
+{
+ static_cast<Object *>(that)->~Object();
}
void Object::__put__(ExecutionContext *ctx, const QString &name, const Value &value)
protected:
static const ManagedVTable static_vtbl;
+ static void destroy(Managed *that);
static void markObjects(Managed *that);
friend struct ObjectIterator;
using namespace QQmlJS::VM;
+DEFINE_MANAGED_VTABLE(RegExpObject);
RegExpObject::RegExpObject(ExecutionEngine *engine, PassRefPtr<RegExp> value, bool global)
: Object(engine)
defineReadonlyProperty(engine->newIdentifier(QStringLiteral("multiline")), Value::fromBoolean(this->value->multiLine()));
}
+void RegExpObject::destroy(Managed *that)
+{
+ static_cast<RegExpObject *>(that)->~RegExpObject();
+}
+
PropertyDescriptor *RegExpObject::lastIndexProperty(ExecutionContext *ctx)
{
assert(0 == internalClass->find(ctx->engine->newIdentifier(QStringLiteral("lastIndex"))));
PropertyDescriptor *lastIndexProperty(ExecutionContext *ctx);
bool global;
RegExpObject(ExecutionEngine *engine, PassRefPtr<RegExp> value, bool global);
+ ~RegExpObject() {}
+
+protected:
+ static const ManagedVTable static_vtbl;
+ static void destroy(Managed *that);
};
return i;
}
+const ManagedVTable String::static_vtbl =
+{
+ call,
+ construct,
+ 0 /*markObjects*/,
+ destroy,
+ hasInstance,
+ "String",
+};
+
+void String::destroy(Managed *that)
+{
+ static_cast<String*>(that)->~String();
+}
+
uint String::toUInt(bool *ok) const
{
*ok = true;
String(const QString &text)
: _text(text), stringHash(UINT_MAX), identifier(UINT_MAX)
- { type = Type_String; subtype = StringType_Unknown; }
+ { vtbl = &static_vtbl; type = Type_String; subtype = StringType_Unknown; }
+ ~String() { _data = 0; }
inline bool isEqualTo(const String *other) const {
if (this == other)
QString _text;
mutable uint stringHash;
mutable uint identifier;
+
+protected:
+ static void destroy(Managed *);
+ static const ManagedVTable static_vtbl;
};
} // namespace VM