diff options
author | Erik Verbruggen <erik.verbruggen@digia.com> | 2012-12-04 13:40:18 +0100 |
---|---|---|
committer | Lars Knoll <lars.knoll@digia.com> | 2012-12-08 04:47:53 +0100 |
commit | 5f22fbd7fc4ca6a7f4629cbd34e0fc2e3c1b1cee (patch) | |
tree | 31a606540d68674315fbc2c71c76592be2ae3dc8 /qmljs_objects.cpp | |
parent | 3b3f3bebcd24073455de9f4abf2f0c7712a1c1ee (diff) |
Add a MemoryManager, which does GC for the interpreter.
Todo:
- stack walking for MASM
- fix all TODOs/FIXMEs and hidden treasures (bugs).
Change-Id: I36f8cdc3a545df7287ce1df17b3570a9c017865e
Reviewed-by: Lars Knoll <lars.knoll@digia.com>
Diffstat (limited to 'qmljs_objects.cpp')
-rw-r--r-- | qmljs_objects.cpp | 65 |
1 files changed, 62 insertions, 3 deletions
diff --git a/qmljs_objects.cpp b/qmljs_objects.cpp index 7fdb86aa72..d74a501a7e 100644 --- a/qmljs_objects.cpp +++ b/qmljs_objects.cpp @@ -43,6 +43,7 @@ #include "qv4ir_p.h" #include "qv4isel_p.h" #include "qv4ecmaobjects_p.h" +#include "qv4mm.h" #include <private/qqmljsengine_p.h> #include <private/qqmljslexer_p.h> @@ -59,6 +60,28 @@ using namespace QQmlJS::VM; + +Managed::~Managed() +{ +} + +void *Managed::operator new(size_t size, MemoryManager *mm) +{ + assert(mm); + + return mm->allocManaged(size); +} + +void Managed::operator delete(void *ptr) +{ + if (!ptr) + return; + + Managed *m = reinterpret_cast<Managed *>(ptr); + assert(m->mm); + m->mm->deallocManaged(m); +} + // // Object // @@ -107,6 +130,20 @@ bool Object::inplaceBinOp(Value rhs, Value index, BinOp op, ExecutionContext *ct return inplaceBinOp(rhs, name, op, ctx); } +void Object::getCollectables(QVector<Object *> &objects) +{ + if (prototype) + objects.append(prototype); + + if (members) { + for (PropertyTable::iterator it = members->begin(), eit = members->end(); it < eit; ++it) { + if ((*it)->descriptor.isData()) + if (Object *o = (*it)->descriptor.value.asObject()) + objects.append(o); + } + } +} + // Section 8.12.1 PropertyDescriptor *Object::__getOwnProperty__(ExecutionContext *, String *name) { @@ -349,6 +386,15 @@ String *ForEachIteratorObject::nextPropertyName() } } +void ForEachIteratorObject::getCollectables(QVector<Object *> &objects) +{ + Object::getCollectables(objects); + if (object) + objects.append(object); + if (current) + objects.append(current); +} + Value ArrayObject::__get__(ExecutionContext *ctx, String *name) { if (name->isEqualTo(ctx->engine->id_length)) @@ -368,6 +414,12 @@ bool ArrayObject::inplaceBinOp(Value rhs, Value index, BinOp op, ExecutionContex return Object::inplaceBinOp(rhs, index, op, ctx); } +void ArrayObject::getCollectables(QVector<Object *> &objects) +{ + Object::getCollectables(objects); + value.getCollectables(objects); +} + bool FunctionObject::hasInstance(ExecutionContext *ctx, const Value &value) { if (! value.isObject()) { @@ -490,7 +542,7 @@ Value EvalFunction::call(ExecutionContext *context, Value /*thisObject*/, Value bool directCall = true; const QString code = args[0].stringValue()->toQString(); - QQmlJS::IR::Function *f = parseSource(context, QStringLiteral("eval code"), code, QQmlJS::Codegen::EvalCode); + QScopedPointer<QQmlJS::IR::Function> f(parseSource(context, QStringLiteral("eval code"), code, QQmlJS::Codegen::EvalCode)); if (!f) return Value::undefinedValue(); @@ -534,6 +586,8 @@ QQmlJS::IR::Function *EvalFunction::parseSource(QQmlJS::VM::ExecutionContext *ct { using namespace QQmlJS; + MemoryManager::GCBlocker gcBlocker(ctx->engine->memoryManager); + VM::ExecutionEngine *vm = ctx->engine; IR::Module module; IR::Function *globalCode = 0; @@ -654,6 +708,13 @@ void ErrorObject::setNameProperty(ExecutionContext *ctx) __put__(ctx, QLatin1String("name"), Value::fromString(ctx, className())); } +void ErrorObject::getCollectables(QVector<Object *> &objects) +{ + Object::getCollectables(objects); + if (Object *o = value.asObject()) + objects.append(o); +} + SyntaxErrorObject::SyntaxErrorObject(ExecutionContext *ctx, DiagnosticMessage *message) : ErrorObject(ctx->argument(0)) , msg(message) @@ -675,7 +736,6 @@ Value ScriptFunction::construct(VM::ExecutionContext *ctx) return ctx->thisObject; } - Value ArgumentsObject::__get__(ExecutionContext *ctx, String *name) { if (name->isEqualTo(ctx->engine->id_length)) @@ -698,7 +758,6 @@ PropertyDescriptor *ArgumentsObject::__getPropertyDescriptor__(ExecutionContext return Object::__getPropertyDescriptor__(ctx, name, to_fill); } - NativeFunction::NativeFunction(ExecutionContext *scope, String *name, Value (*code)(ExecutionContext *)) : FunctionObject(scope) , code(code) |