From 19c6f620dd35916466c36234231d798f79732ab0 Mon Sep 17 00:00:00 2001 From: Lars Knoll <lars.knoll@digia.com> Date: Mon, 6 May 2013 15:32:56 +0200 Subject: [PATCH] Convert some v8::Persistent to v4 Change-Id: Ic6613b020dbbb1ee75e2096707d8fb1aa228083d Reviewed-by: Simon Hausmann <simon.hausmann@digia.com> --- src/qml/qml/qqmlbinding.cpp | 15 +++++++-------- src/qml/qml/qqmlbinding_p.h | 2 +- src/qml/qml/qqmlcompileddata.cpp | 2 -- src/qml/qml/qqmlcompiler_p.h | 2 +- src/qml/qml/v8/qv8bindings.cpp | 26 ++++++++++++++++---------- src/qml/qml/v8/qv8bindings_p.h | 2 +- 6 files changed, 26 insertions(+), 23 deletions(-) diff --git a/src/qml/qml/qqmlbinding.cpp b/src/qml/qml/qqmlbinding.cpp index da34d06b8c..284a0afdcc 100644 --- a/src/qml/qml/qqmlbinding.cpp +++ b/src/qml/qml/qqmlbinding.cpp @@ -112,7 +112,7 @@ QQmlBinding::QQmlBinding(const QString &str, QObject *obj, QQmlContext *ctxt) QString code = rewriteBinding(str); m_expression = str.toUtf8(); - v8function = evalFunction(context(), obj, code, QString(), 0); + v4function = evalFunction(context(), obj, code, QString(), 0)->v4Value(); } QQmlBinding::QQmlBinding(const QQmlScriptString &script, QObject *obj, QQmlContext *ctxt) @@ -159,7 +159,7 @@ QQmlBinding::QQmlBinding(const QQmlScriptString &script, QObject *obj, QQmlConte m_lineNumber = scriptPrivate->lineNumber; m_columnNumber = scriptPrivate->columnNumber; - v8function = evalFunction(context(), scopeObject(), code, QString(), m_lineNumber); + v4function = evalFunction(context(), scopeObject(), code, QString(), m_lineNumber)->v4Value(); } QQmlBinding::QQmlBinding(const QString &str, QObject *obj, QQmlContextData *ctxt) @@ -174,7 +174,7 @@ QQmlBinding::QQmlBinding(const QString &str, QObject *obj, QQmlContextData *ctxt QString code = rewriteBinding(str); m_expression = str.toUtf8(); - v8function = evalFunction(ctxt, obj, code, QString(), 0); + v4function = evalFunction(ctxt, obj, code, QString(), 0)->v4Value(); } QQmlBinding::QQmlBinding(const QString &str, bool isRewritten, QObject *obj, @@ -197,7 +197,7 @@ QQmlBinding::QQmlBinding(const QString &str, bool isRewritten, QObject *obj, m_expression = str.toUtf8(); - v8function = evalFunction(ctxt, obj, code, url, m_lineNumber); + v4function = evalFunction(ctxt, obj, code, url, m_lineNumber)->v4Value(); } /*! @@ -217,12 +217,11 @@ QQmlBinding::QQmlBinding(void *functionPtr, QObject *obj, QQmlContextData *ctxt, QQmlAbstractExpression::setContext(ctxt); setScopeObject(obj); - v8function = qPersistentNew<v8::Function>(*(v8::Handle<v8::Function> *)functionPtr); + v4function = (*(v8::Handle<v8::Function> *)functionPtr)->v4Value(); } QQmlBinding::~QQmlBinding() { - qPersistentDispose(v8function); } void QQmlBinding::setEvaluateFlags(EvaluateFlags flags) @@ -280,7 +279,7 @@ void QQmlBinding::update(QQmlPropertyPrivate::WriteFlags flags) bool isUndefined = false; v8::Local<v8::Value> result = - QQmlJavaScriptExpression::evaluate(context(), v8function, &isUndefined); + QQmlJavaScriptExpression::evaluate(context(), **v4function, &isUndefined); trace.event("writing binding result"); @@ -321,7 +320,7 @@ QVariant QQmlBinding::evaluate() bool isUndefined = false; v8::Local<v8::Value> result = - QQmlJavaScriptExpression::evaluate(context(), v8function, &isUndefined); + QQmlJavaScriptExpression::evaluate(context(), **v4function, &isUndefined); ep->dereferenceScarceResources(); diff --git a/src/qml/qml/qqmlbinding_p.h b/src/qml/qml/qqmlbinding_p.h index 5b547595e2..f2a4bf293e 100644 --- a/src/qml/qml/qqmlbinding_p.h +++ b/src/qml/qml/qqmlbinding_p.h @@ -131,7 +131,7 @@ protected: ~QQmlBinding(); private: - v8::Persistent<v8::Function> v8function; + QV4::PersistentValue v4function; inline bool updatingFlag() const; inline void setUpdatingFlag(bool); diff --git a/src/qml/qml/qqmlcompileddata.cpp b/src/qml/qml/qqmlcompileddata.cpp index 7279762565..4dba670be8 100644 --- a/src/qml/qml/qqmlcompileddata.cpp +++ b/src/qml/qml/qqmlcompileddata.cpp @@ -134,8 +134,6 @@ QQmlCompiledData::~QQmlCompiledData() void QQmlCompiledData::clear() { - for (int ii = 0; ii < programs.count(); ++ii) - qPersistentDispose(programs[ii].bindings); } /*! diff --git a/src/qml/qml/qqmlcompiler_p.h b/src/qml/qml/qqmlcompiler_p.h index 5ad2ee5c48..01d403553e 100644 --- a/src/qml/qml/qqmlcompiler_p.h +++ b/src/qml/qml/qqmlcompiler_p.h @@ -111,7 +111,7 @@ public: : program(p), cdata(c) {} QByteArray program; - v8::Persistent<v8::Array> bindings; + QV4::PersistentValue bindings; QQmlCompiledData *cdata; }; diff --git a/src/qml/qml/v8/qv8bindings.cpp b/src/qml/qml/v8/qv8bindings.cpp index 43d1e8654f..f471a65bd4 100644 --- a/src/qml/qml/v8/qv8bindings.cpp +++ b/src/qml/qml/v8/qv8bindings.cpp @@ -50,6 +50,8 @@ #include <private/qqmltrace_p.h> #include <private/qqmlprofilerservice_p.h> +#include <private/qv4object_p.h> + QT_BEGIN_NAMESPACE QQmlAbstractBinding::VTable QV8Bindings_Binding_vtable = { @@ -86,7 +88,8 @@ void QV8Bindings::Binding::setEnabled(QQmlAbstractBinding *_This, bool e, void QV8Bindings::refresh() { - int count = functions()->Length(); + QV4::ArrayObject *f = functions(); + int count = f ? f->arrayLength() : 0; for (int ii = 0; ii < count; ++ii) bindings[ii].refresh(); } @@ -170,10 +173,12 @@ void QV8Bindings::Binding::update(QQmlPropertyPrivate::WriteFlags flags) DeleteWatcher watcher(this); ep->referenceScarceResources(); - v8::Local<v8::Value> result = + QV4::ArrayObject *f = parent->functions(); + v8::Local<v8::Value> result = f ? evaluate(context, - v8::Handle<v8::Function>::Cast(parent->functions()->Get(instruction->value)), - &isUndefined); + f->getIndexed(f->internalClass->engine->current, instruction->value), + &isUndefined) + : v8::Local<v8::Value>::New(QV4::Value::undefinedValue()); trace.event("writing V8 result"); bool needsErrorLocationData = false; @@ -240,7 +245,7 @@ QV8Bindings::QV8Bindings(QQmlCompiledData::V8Program *program, { QV8Engine *engine = QQmlEnginePrivate::getV8Engine(context->engine); - if (program->bindings.IsEmpty()) { + if (program->bindings->isDeleted()) { v8::Local<v8::Script> script; bool compileFailed = false; { @@ -260,20 +265,21 @@ QV8Bindings::QV8Bindings(QQmlCompiledData::V8Program *program, if (!message.IsEmpty()) QQmlExpressionPrivate::exceptionToError(message, error); QQmlEnginePrivate::get(engine->engine())->warning(error); - program->bindings = qPersistentNew(v8::Array::New()); + program->bindings = QV4::Value::nullValue(); } } if (!compileFailed) { v8::Local<v8::Value> result = script->Run(engine->contextWrapper()->sharedContext()); if (result->IsArray()) { - program->bindings = qPersistentNew(v8::Local<v8::Array>::Cast(result)); + program->bindings = result->v4Value(); program->program.clear(); // We don't need the source anymore } } } - int bindingsCount = functions()->Length(); + QV4::ArrayObject *f = functions(); + int bindingsCount = f ? f->arrayLength() : 0; if (bindingsCount) bindings = new QV8Bindings::Binding[bindingsCount]; setContext(context); @@ -319,9 +325,9 @@ const QString &QV8Bindings::urlString() const return program->cdata->name; } -v8::Persistent<v8::Array> &QV8Bindings::functions() const +QV4::ArrayObject *QV8Bindings::functions() const { - return program->bindings; + return program->bindings->asArrayObject(); } diff --git a/src/qml/qml/v8/qv8bindings_p.h b/src/qml/qml/v8/qv8bindings_p.h index 98b367ac72..74fe04258f 100644 --- a/src/qml/qml/v8/qv8bindings_p.h +++ b/src/qml/qml/v8/qv8bindings_p.h @@ -136,7 +136,7 @@ private: const QUrl &url() const; const QString &urlString() const; - v8::Persistent<v8::Array> &functions() const; + QV4::ArrayObject *functions() const; QQmlCompiledData::V8Program *program; Binding *bindings; -- GitLab