diff options
author | Lars Knoll <lars.knoll@digia.com> | 2013-09-16 22:02:27 +0200 |
---|---|---|
committer | The Qt Project <gerrit-noreply@qt-project.org> | 2013-09-22 01:06:20 +0200 |
commit | e441692b0b8f8fffdfdfa8a21c570adcd5cbae7a (patch) | |
tree | 9b764401d87682012328c46dc947721f47b428b2 /src/qml/types | |
parent | a0f8be4021caa9bb5055923f0eea3bee0e345235 (diff) |
Further work towards an exact GC
Add some more convenience in the helper classes
in qscopedvalue_p.h
Make accesses to CallData safer, and change
ExecutionEngine::newObject() to return a safe
pointer.
Change-Id: I980909754ce9681cf6faa1355bab3a1e5d6dd186
Reviewed-by: Simon Hausmann <simon.hausmann@digia.com>
Diffstat (limited to 'src/qml/types')
-rw-r--r-- | src/qml/types/qqmldelegatemodel.cpp | 18 | ||||
-rw-r--r-- | src/qml/types/qquickworkerscript.cpp | 29 |
2 files changed, 28 insertions, 19 deletions
diff --git a/src/qml/types/qqmldelegatemodel.cpp b/src/qml/types/qqmldelegatemodel.cpp index 0457adb348..b9f78da96e 100644 --- a/src/qml/types/qqmldelegatemodel.cpp +++ b/src/qml/types/qqmldelegatemodel.cpp @@ -83,10 +83,12 @@ struct DelegateModelGroupFunction: QV4::FunctionObject static QV4::ReturnedValue call(QV4::Managed *that, QV4::CallData *callData) { - DelegateModelGroupFunction *f = static_cast<DelegateModelGroupFunction *>(that); - QQmlDelegateModelItemObject *o = callData->thisObject.as<QQmlDelegateModelItemObject>(); + QV4::ExecutionEngine *v4 = that->engine(); + QV4::Scope scope(v4); + QV4::Scoped<DelegateModelGroupFunction> f(scope, that, QV4::Scoped<DelegateModelGroupFunction>::Cast); + QV4::Scoped<QQmlDelegateModelItemObject> o(scope, callData->thisObject); if (!o) - that->engine()->current->throwTypeError(QStringLiteral("Not a valid VisualData object")); + v4->current->throwTypeError(QStringLiteral("Not a valid VisualData object")); QV4::Value v = callData->argc ? callData->args[0] : QV4::Value::undefinedValue(); return f->code(o->item, f->flag, v); @@ -1622,8 +1624,9 @@ void QQmlDelegateModelItemMetaType::initializePrototype() { QQmlDelegateModelEngineData *data = engineData(v8Engine); QV4::ExecutionEngine *v4 = QV8Engine::getV4(v8Engine); + QV4::Scope scope(v4); - QV4::Object *proto = v4->newObject(); + QV4::Scoped<QV4::Object> proto(scope, v4->newObject()); proto->defineAccessorProperty(v4, QStringLiteral("model"), QQmlDelegateModelItem::get_model, 0); proto->defineAccessorProperty(v4, QStringLiteral("groups"), QQmlDelegateModelItem::get_groups, QQmlDelegateModelItem::set_groups); QV4::Property *p = proto->insertMember(v4->newString(QStringLiteral("isUnresolved")), @@ -1656,7 +1659,7 @@ void QQmlDelegateModelItemMetaType::initializePrototype() p = proto->insertMember(v4->newString(propertyName), QV4::Attr_Accessor|QV4::Attr_NotConfigurable|QV4::Attr_NotEnumerable); p->setGetter(new (v4->memoryManager) DelegateModelGroupFunction(v4->rootContext, i + 1, QQmlDelegateModelItem::get_index)); } - modelItemProto = QV4::Value::fromObject(proto); + modelItemProto = proto; } int QQmlDelegateModelItemMetaType::parseGroups(const QStringList &groups) const @@ -3233,15 +3236,16 @@ private: QQmlDelegateModelEngineData::QQmlDelegateModelEngineData(QV8Engine *e) { QV4::ExecutionEngine *v4 = QV8Engine::getV4(e); + QV4::Scope scope(v4); - QV4::Object *proto = v4->newObject(); + QV4::Scoped<QV4::Object> proto(scope, v4->newObject()); QV4::Property *p = proto->insertMember(v4->newString(QStringLiteral("index")), QV4::Attr_Accessor|QV4::Attr_NotConfigurable|QV4::Attr_NotEnumerable); p->setGetter(v4->newBuiltinFunction(v4->rootContext, v4->id_undefined, QQmlDelegateModelGroupChange::method_get_index)); p = proto->insertMember(v4->newString(QStringLiteral("count")), QV4::Attr_Accessor|QV4::Attr_NotConfigurable|QV4::Attr_NotEnumerable); p->setGetter(v4->newBuiltinFunction(v4->rootContext, v4->id_undefined, QQmlDelegateModelGroupChange::method_get_count)); p = proto->insertMember(v4->newString(QStringLiteral("moveId")), QV4::Attr_Accessor|QV4::Attr_NotConfigurable|QV4::Attr_NotEnumerable); p->setGetter(v4->newBuiltinFunction(v4->rootContext, v4->id_undefined, QQmlDelegateModelGroupChange::method_get_moveId)); - changeProto = QV4::Value::fromObject(proto); + changeProto = proto; } QQmlDelegateModelEngineData::~QQmlDelegateModelEngineData() diff --git a/src/qml/types/qquickworkerscript.cpp b/src/qml/types/qquickworkerscript.cpp index 4e39682d84..d80df760fa 100644 --- a/src/qml/types/qquickworkerscript.cpp +++ b/src/qml/types/qquickworkerscript.cpp @@ -177,7 +177,7 @@ public: }; QHash<int, WorkerScript *> workers; - QV4::Value getWorker(WorkerScript *); + QV4::ReturnedValue getWorker(WorkerScript *); int m_nextId; @@ -282,9 +282,9 @@ QV4::ReturnedValue QQuickWorkerScriptEnginePrivate::method_sendMessage(QV4::Simp { WorkerEngine *engine = (WorkerEngine*)ctx->engine->v8Engine; - int id = ctx->argument(1).toInt32(); + int id = ctx->argumentCount > 1 ? ctx->arguments[1].toInt32() : 0; - QByteArray data = QV4::Serialize::serialize(ctx->argument(2), engine); + QByteArray data = QV4::Serialize::serialize(ctx->argumentCount > 2 ? ctx->arguments[2] : QV4::Value::undefinedValue(), engine); QMutexLocker locker(&engine->p->m_lock); WorkerScript *script = engine->p->workers.value(id); @@ -298,27 +298,29 @@ QV4::ReturnedValue QQuickWorkerScriptEnginePrivate::method_sendMessage(QV4::Simp } // Requires handle scope and context scope -QV4::Value QQuickWorkerScriptEnginePrivate::getWorker(WorkerScript *script) +QV4::ReturnedValue QQuickWorkerScriptEnginePrivate::getWorker(WorkerScript *script) { if (!script->initialized) { script->initialized = true; QV4::ExecutionEngine *v4 = QV8Engine::getV4(workerEngine); + QV4::Scope scope(v4); script->object = QV4::QmlContextWrapper::urlScope(workerEngine, script->source); - QV4::QmlContextWrapper *w = script->object.value().asObject()->as<QV4::QmlContextWrapper>(); + QV4::Scoped<QV4::QmlContextWrapper> w(scope, script->object.value()); + Q_ASSERT(!!w); w->setReadOnly(false); - QV4::Object *api = v4->newObject(); + QV4::Scoped<QV4::Object> api(scope, v4->newObject()); api->put(v4->newString("sendMessage"), workerEngine->sendFunction(script->id)); - script->object.value().asObject()->put(v4->newString("WorkerScript"), QV4::Value::fromObject(api)); + script->object.value().asObject()->put(v4->newString("WorkerScript"), api.asValue()); w->setReadOnly(true); } - return script->object.value(); + return script->object.value().asReturnedValue(); } bool QQuickWorkerScriptEnginePrivate::event(QEvent *event) @@ -386,12 +388,15 @@ void QQuickWorkerScriptEnginePrivate::processLoad(int id, const QUrl &url) if (!script) return; script->source = url; - QV4::Value activation = getWorker(script); - if (activation.isEmpty()) - return; QV4::ExecutionEngine *v4 = QV8Engine::getV4(workerEngine); - QV4::Script program(v4, activation.asObject(), sourceCode, url.toString()); + QV4::Scope scope(v4); + + QV4::Scoped<QV4::Object> activation(scope, getWorker(script)); + if (!activation) + return; + + QV4::Script program(v4, activation.getPointer(), sourceCode, url.toString()); QV4::ExecutionContext *ctx = v4->current; try { |