Change some v8::Persistent to QV4::PersistentValue
authorLars Knoll <lars.knoll@digia.com>
Tue, 7 May 2013 06:54:12 +0000 (08:54 +0200)
committerSimon Hausmann <simon.hausmann@digia.com>
Tue, 7 May 2013 10:46:55 +0000 (12:46 +0200)
Change-Id: I2c4e98cf7e778de9aafabdbd68e6682106343d12
Reviewed-by: Simon Hausmann <simon.hausmann@digia.com>
src/qml/debugger/qqmlenginedebugservice.cpp
src/qml/qml/qqmlbinding.cpp
src/qml/qml/qqmlboundsignal.cpp
src/qml/qml/qqmlboundsignal_p.h
src/qml/qml/qqmlexpression.cpp
src/qml/qml/qqmlexpression_p.h
src/qml/qml/qqmljavascriptexpression.cpp
src/qml/qml/qqmljavascriptexpression_p.h
src/qml/qml/qqmlvmemetaobject.cpp
src/qml/qml/qqmlvmemetaobject_p.h
src/qml/qml/v4/qv4value_p.h

index c4c8cb2..bf52c42 100644 (file)
@@ -742,7 +742,8 @@ bool QQmlEngineDebugService::setMethodBody(int objectId, const QString &method,
     Q_ASSERT(vmeMetaObject); // the fact we found the property above should guarentee this
 
     int lineNumber = vmeMetaObject->vmeMethodLineNumber(prop->coreIndex);
-    vmeMetaObject->setVmeMethod(prop->coreIndex, QQmlExpressionPrivate::evalFunction(contextData, object, jsfunction, contextData->url.toString(), lineNumber));
+    vmeMetaObject->setVmeMethod(prop->coreIndex,
+                                QQmlExpressionPrivate::evalFunction(contextData, object, jsfunction, contextData->url.toString(), lineNumber));
     return true;
 }
 
index 4aebec4..9e1a152 100644 (file)
@@ -112,7 +112,7 @@ QQmlBinding::QQmlBinding(const QString &str, QObject *obj, QQmlContext *ctxt)
     QString code = rewriteBinding(str);
 
     m_expression = str.toUtf8();
-    v4function = evalFunction(context(), obj, code, QString(), 0)->v4Value();
+    v4function = evalFunction(context(), obj, code, QString(), 0);
 }
 
 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;
 
-    v4function = evalFunction(context(), scopeObject(), code, QString(), m_lineNumber)->v4Value();
+    v4function = evalFunction(context(), scopeObject(), code, QString(), m_lineNumber);
 }
 
 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();
-    v4function = evalFunction(ctxt, obj, code, QString(), 0)->v4Value();
+    v4function = evalFunction(ctxt, obj, code, QString(), 0);
 }
 
 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();
 
-    v4function = evalFunction(ctxt, obj, code, url, m_lineNumber)->v4Value();
+    v4function = evalFunction(ctxt, obj, code, url, m_lineNumber);
 }
 
 /*!
index 683f528..ff61fde 100644 (file)
@@ -121,8 +121,6 @@ void QQmlBoundSignalExpression::init(QQmlContextData *ctxt, QObject *scope)
 
 QQmlBoundSignalExpression::~QQmlBoundSignalExpression()
 {
-    qPersistentDispose(m_v8function);
-    qPersistentDispose(m_v8qmlscope);
 }
 
 QString QQmlBoundSignalExpression::expressionIdentifier(QQmlJavaScriptExpression *e)
@@ -140,7 +138,7 @@ QString QQmlBoundSignalExpression::expression() const
 {
     if (m_expressionFunctionValid) {
         Q_ASSERT (context() && engine());
-        return m_v8function->v4Value().toQString();
+        return m_v8function->toQString();
     } else if (!m_expressionUtf8.isEmpty()) {
         return QString::fromUtf8(m_expressionUtf8);
     } else {
@@ -208,7 +206,7 @@ void QQmlBoundSignalExpression::evaluate(void **a)
                                             m_fileName, m_line, &m_v8qmlscope);
             }
 
-            if (m_v8function.IsEmpty() || m_v8function->IsNull()) {
+            if (m_v8function->isDeleted() || m_v8function->isNull()) {
                 ep->dereferenceScarceResources();
                 return; // could not evaluate function.  Not valid.
             }
@@ -218,7 +216,7 @@ void QQmlBoundSignalExpression::evaluate(void **a)
         }
 
         if (!hasParameterInfo()) {
-            QQmlJavaScriptExpression::evaluate(context(), m_v8function, 0);
+            QQmlJavaScriptExpression::evaluate(context(), **m_v8function, 0);
         } else {
             QV8Engine *engine = ep->v8engine();
             QVarLengthArray<int, 9> dummy;
@@ -251,7 +249,7 @@ void QQmlBoundSignalExpression::evaluate(void **a)
                 }
             }
 
-            QQmlJavaScriptExpression::evaluate(context(), m_v8function, argCount, args.data(), 0);
+            QQmlJavaScriptExpression::evaluate(context(), **m_v8function, argCount, args.data(), 0);
         }
     }
     ep->dereferenceScarceResources(); // "release" scarce resources if top-level expression evaluation is complete.
index 910e1e3..33fa5be 100644 (file)
@@ -99,8 +99,8 @@ private:
     void init(QQmlContextData *ctxt, QObject *scope);
     bool hasParameterInfo() const { return m_parameterCountForJS > 0; }
 
-    v8::Persistent<v8::Object> m_v8qmlscope;
-    v8::Persistent<v8::Function> m_v8function;
+    QV4::PersistentValue m_v8qmlscope;
+    QV4::PersistentValue m_v8function;
 
     //either expressionUtf8 or expression will be used (but not both).
     //once m_v8function is valid, we clear both expressions, and
index 29f53f3..0f22522 100644 (file)
@@ -67,8 +67,6 @@ QQmlExpressionPrivate::QQmlExpressionPrivate()
 
 QQmlExpressionPrivate::~QQmlExpressionPrivate()
 {
-    qPersistentDispose(v8qmlscope);
-    qPersistentDispose(v8function);
 }
 
 void QQmlExpressionPrivate::init(QQmlContextData *ctxt, const QString &expr, QObject *me)
@@ -335,8 +333,6 @@ void QQmlExpression::setExpression(const QString &expression)
     d->expressionUtf8.clear();
     d->expressionFunctionValid = false;
     d->expressionFunctionRewritten = false;
-    qPersistentDispose(d->v8function);
-    qPersistentDispose(d->v8qmlscope);
 }
 
 // Must be called with a valid handle scope
@@ -358,7 +354,7 @@ v8::Handle<v8::Value> QQmlExpressionPrivate::v8value(bool *isUndefined)
         expressionFunctionValid = true;
     }
 
-    return evaluate(context(), v8function, isUndefined);
+    return evaluate(context(), **v8function, isUndefined);
 }
 
 QVariant QQmlExpressionPrivate::value(bool *isUndefined)
index e31d189..4577878 100644 (file)
@@ -105,8 +105,8 @@ public:
     QString expression;
     QByteArray expressionUtf8;
 
-    v8::Persistent<v8::Object> v8qmlscope;
-    v8::Persistent<v8::Function> v8function;
+    QV4::PersistentValue v8qmlscope;
+    QV4::PersistentValue v8function;
 
     QString url; // This is a QString for a reason.  QUrls are slooooooow...
     quint16 line;
index 05c6c24..cd88370 100644 (file)
@@ -326,11 +326,11 @@ void QQmlJavaScriptExpression::exceptionToError(v8::Handle<v8::Message> message,
 }
 
 // Callee owns the persistent handle
-v8::Persistent<v8::Function>
+QV4::PersistentValue
 QQmlJavaScriptExpression::evalFunction(QQmlContextData *ctxt, QObject *scope,
                                        const char *code, int codeLength,
                                        const QString &filename, quint16 line,
-                                       v8::Persistent<v8::Object> *qmlscope)
+                                       QV4::PersistentValue *qmlscope)
 {
     QQmlEngine *engine = ctxt->engine;
     QQmlEnginePrivate *ep = QQmlEnginePrivate::get(engine);
@@ -347,7 +347,7 @@ QQmlJavaScriptExpression::evalFunction(QQmlContextData *ctxt, QObject *scope,
         if (!message.IsEmpty())
             QQmlExpressionPrivate::exceptionToError(message, error);
         ep->warning(error);
-        return v8::Persistent<v8::Function>();
+        return QV4::PersistentValue();
     }
     v8::Handle<v8::Value> result = script->Run(scopeobject);
     if (tc.HasCaught()) {
@@ -359,17 +359,18 @@ QQmlJavaScriptExpression::evalFunction(QQmlContextData *ctxt, QObject *scope,
         if (!message.IsEmpty())
             QQmlExpressionPrivate::exceptionToError(message, error);
         ep->warning(error);
-        return v8::Persistent<v8::Function>();
+        return QV4::PersistentValue();
     }
-    if (qmlscope) *qmlscope = qPersistentNew<v8::Object>(scopeobject);
-    return qPersistentNew<v8::Function>(v8::Handle<v8::Function>::Cast(result));
+    if (qmlscope)
+        *qmlscope = scopeobject->v4Value();
+    return result->v4Value();
 }
 
 // Callee owns the persistent handle
-v8::Persistent<v8::Function>
+QV4::PersistentValue
 QQmlJavaScriptExpression::evalFunction(QQmlContextData *ctxt, QObject *scope,
                                        const QString &code, const QString &filename, quint16 line,
-                                       v8::Persistent<v8::Object> *qmlscope)
+                                       QV4::PersistentValue *qmlscope)
 {
     QQmlEngine *engine = ctxt->engine;
     QQmlEnginePrivate *ep = QQmlEnginePrivate::get(engine);
@@ -386,7 +387,7 @@ QQmlJavaScriptExpression::evalFunction(QQmlContextData *ctxt, QObject *scope,
         if (!message.IsEmpty())
             QQmlExpressionPrivate::exceptionToError(message, error);
         ep->warning(error);
-        return v8::Persistent<v8::Function>();
+        return QV4::PersistentValue();
     }
     v8::Handle<v8::Value> result = script->Run(scopeobject);
     if (tc.HasCaught()) {
@@ -398,10 +399,11 @@ QQmlJavaScriptExpression::evalFunction(QQmlContextData *ctxt, QObject *scope,
         if (!message.IsEmpty())
             QQmlExpressionPrivate::exceptionToError(message, error);
         ep->warning(error);
-        return v8::Persistent<v8::Function>();
+        return QV4::PersistentValue();
     }
-    if (qmlscope) *qmlscope = qPersistentNew<v8::Object>(scopeobject);
-    return qPersistentNew<v8::Function>(v8::Handle<v8::Function>::Cast(result));
+    if (qmlscope)
+        *qmlscope = scopeobject->v4Value();
+    return result->v4Value();
 }
 
 void QQmlJavaScriptExpression::clearGuards()
index c1d3d13..0d3b7b9 100644 (file)
@@ -148,14 +148,14 @@ public:
     QQmlDelayedError *delayedError();
 
     static void exceptionToError(v8::Handle<v8::Message>, QQmlError &);
-    static v8::Persistent<v8::Function> evalFunction(QQmlContextData *ctxt, QObject *scope,
+    static QV4::PersistentValue evalFunction(QQmlContextData *ctxt, QObject *scope,
                                                      const QString &code, const QString &filename,
                                                      quint16 line,
-                                                     v8::Persistent<v8::Object> *qmlscope = 0);
-    static v8::Persistent<v8::Function> evalFunction(QQmlContextData *ctxt, QObject *scope,
+                                                     QV4::PersistentValue *qmlscope = 0);
+    static QV4::PersistentValue evalFunction(QQmlContextData *ctxt, QObject *scope,
                                                      const char *code, int codeLength,
                                                      const QString &filename, quint16 line,
-                                                     v8::Persistent<v8::Object> *qmlscope = 0);
+                                                     QV4::PersistentValue *qmlscope = 0);
 protected:
     ~QQmlJavaScriptExpression();
 
index 6fc9579..9121f13 100644 (file)
@@ -602,10 +602,6 @@ QQmlVMEMetaObject::~QQmlVMEMetaObject()
     if (parent.isT1()) parent.asT1()->objectDestroyed(object);
     delete [] data;
     delete [] aliasEndpoints;
-
-    for (int ii = 0; v8methods && ii < metaData->methodCount; ++ii) {
-        qPersistentDispose(v8methods[ii]);
-    }
     delete [] v8methods;
 
     if (metaData->varPropertyCount)
@@ -974,9 +970,9 @@ v8::Handle<v8::Function> QQmlVMEMetaObject::method(int index)
     }
 
     if (!v8methods) 
-        v8methods = new v8::Persistent<v8::Function>[metaData->methodCount];
+        v8methods = new QV4::PersistentValue[metaData->methodCount];
 
-    if (v8methods[index].IsEmpty()) {
+    if (v8methods[index]->isDeleted()) {
         QQmlVMEMetaData::MethodData *data = metaData->methodData() + index;
 
         const char *body = ((const char*)metaData) + data->bodyOffset;
@@ -991,7 +987,7 @@ v8::Handle<v8::Function> QQmlVMEMetaObject::method(int index)
                                                                        data->lineNumber);
     }
 
-    return v8methods[index];
+    return v8::Handle<v8::Function>(v8methods[index]);
 }
 
 v8::Handle<v8::Value> QQmlVMEMetaObject::readVarProperty(int id)
@@ -1177,22 +1173,20 @@ v8::Handle<v8::Function> QQmlVMEMetaObject::vmeMethod(int index)
 }
 
 // Used by debugger
-void QQmlVMEMetaObject::setVmeMethod(int index, v8::Persistent<v8::Function> value)
+void QQmlVMEMetaObject::setVmeMethod(int index, QV4::PersistentValue function)
 {
     if (index < methodOffset()) {
         Q_ASSERT(parentVMEMetaObject());
-        return parentVMEMetaObject()->setVmeMethod(index, value);
+        return parentVMEMetaObject()->setVmeMethod(index, function);
     }
     int plainSignals = metaData->signalCount + metaData->propertyCount + metaData->aliasCount;
     Q_ASSERT(index >= (methodOffset() + plainSignals) && index < (methodOffset() + plainSignals + metaData->methodCount));
 
     if (!v8methods) 
-        v8methods = new v8::Persistent<v8::Function>[metaData->methodCount];
+        v8methods = new QV4::PersistentValue[metaData->methodCount];
 
     int methodIndex = index - methodOffset() - plainSignals;
-    if (!v8methods[methodIndex].IsEmpty()) 
-        qPersistentDispose(v8methods[methodIndex]);
-    v8methods[methodIndex] = value;
+    v8methods[methodIndex] = function;
 }
 
 v8::Handle<v8::Value> QQmlVMEMetaObject::vmeProperty(int index)
index 8b80d7f..ea9ccf2 100644 (file)
@@ -168,7 +168,7 @@ public:
     void registerInterceptor(int index, int valueIndex, QQmlPropertyValueInterceptor *interceptor);
     v8::Handle<v8::Function> vmeMethod(int index);
     quint16 vmeMethodLineNumber(int index);
-    void setVmeMethod(int index, v8::Persistent<v8::Function>);
+    void setVmeMethod(int index, QV4::PersistentValue function);
     v8::Handle<v8::Value> vmeProperty(int index);
     void setVMEProperty(int index, v8::Handle<v8::Value> v);
 
@@ -216,7 +216,7 @@ public:
 
     QQmlPropertyValueInterceptor *interceptors;
 
-    v8::Persistent<v8::Function> *v8methods;
+    QV4::PersistentValue *v8methods;
     v8::Handle<v8::Function> method(int);
 
     v8::Handle<v8::Value> readVarProperty(int);
index d583826..9e56df0 100644 (file)
@@ -579,6 +579,8 @@ public:
 
     Value *operator->() { return &d->value; }
     Value *operator*() { return &d->value; }
+    const Value *operator->() const { return &d->value; }
+    const Value *operator*() const { return &d->value; }
 
     ExecutionEngine *engine() {
         Managed *m = d->value.asManaged();