From 3fe97384fef6fd7d167017cd950313b34a64c9c1 Mon Sep 17 00:00:00 2001 From: Lars Knoll Date: Tue, 7 May 2013 13:17:57 +0200 Subject: Make the default constructor of PersistentValue not allocate a d pointer This is also required to change the v8::Persistent in QQmlData over to v4. Change-Id: Ib3164ded9c772e977f6b43ef6163a3aa74da3800 Reviewed-by: Simon Hausmann --- src/qml/qml/qqmlbinding.cpp | 4 ++-- src/qml/qml/qqmlboundsignal.cpp | 8 ++++---- src/qml/qml/qqmlexpression.cpp | 2 +- src/qml/qml/qqmlpropertycache.cpp | 6 +++--- src/qml/qml/qqmlvmemetaobject.cpp | 2 +- src/qml/qml/v4/qv4value.cpp | 25 +++++++++++++++---------- src/qml/qml/v4/qv4value_p.h | 21 +++++++++------------ src/qml/qml/v8/qjsvalue_p.h | 2 +- src/qml/qml/v8/qv8bindings.cpp | 4 ++-- src/qml/qml/v8/qv8engine.cpp | 2 +- src/qml/qml/v8/qv8qobjectwrapper.cpp | 4 ++-- 11 files changed, 41 insertions(+), 39 deletions(-) diff --git a/src/qml/qml/qqmlbinding.cpp b/src/qml/qml/qqmlbinding.cpp index 9e1a1522af..b66f053b0f 100644 --- a/src/qml/qml/qqmlbinding.cpp +++ b/src/qml/qml/qqmlbinding.cpp @@ -279,7 +279,7 @@ void QQmlBinding::update(QQmlPropertyPrivate::WriteFlags flags) bool isUndefined = false; v8::Handle result = - QQmlJavaScriptExpression::evaluate(context(), **v4function, &isUndefined); + QQmlJavaScriptExpression::evaluate(context(), v4function.value(), &isUndefined); trace.event("writing binding result"); @@ -320,7 +320,7 @@ QVariant QQmlBinding::evaluate() bool isUndefined = false; v8::Handle result = - QQmlJavaScriptExpression::evaluate(context(), **v4function, &isUndefined); + QQmlJavaScriptExpression::evaluate(context(), v4function.value(), &isUndefined); ep->dereferenceScarceResources(); diff --git a/src/qml/qml/qqmlboundsignal.cpp b/src/qml/qml/qqmlboundsignal.cpp index d84d7a492d..acb79032e7 100644 --- a/src/qml/qml/qqmlboundsignal.cpp +++ b/src/qml/qml/qqmlboundsignal.cpp @@ -138,7 +138,7 @@ QString QQmlBoundSignalExpression::expression() const { if (m_expressionFunctionValid) { Q_ASSERT (context() && engine()); - return m_v8function->toQString(); + return m_v8function.value().toQString(); } else if (!m_expressionUtf8.isEmpty()) { return QString::fromUtf8(m_expressionUtf8); } else { @@ -206,7 +206,7 @@ void QQmlBoundSignalExpression::evaluate(void **a) m_fileName, m_line, &m_v8qmlscope); } - if (m_v8function->isEmpty() || m_v8function->isNull()) { + if (m_v8function.isEmpty() || m_v8function.value().isNull()) { ep->dereferenceScarceResources(); return; // could not evaluate function. Not valid. } @@ -216,7 +216,7 @@ void QQmlBoundSignalExpression::evaluate(void **a) } if (!hasParameterInfo()) { - QQmlJavaScriptExpression::evaluate(context(), **m_v8function, 0); + QQmlJavaScriptExpression::evaluate(context(), m_v8function.value(), 0); } else { QV8Engine *engine = ep->v8engine(); QVarLengthArray dummy; @@ -249,7 +249,7 @@ void QQmlBoundSignalExpression::evaluate(void **a) } } - QQmlJavaScriptExpression::evaluate(context(), **m_v8function, argCount, args.data(), 0); + QQmlJavaScriptExpression::evaluate(context(), m_v8function.value(), argCount, args.data(), 0); } } ep->dereferenceScarceResources(); // "release" scarce resources if top-level expression evaluation is complete. diff --git a/src/qml/qml/qqmlexpression.cpp b/src/qml/qml/qqmlexpression.cpp index 0f225228b3..32dbbb0e6c 100644 --- a/src/qml/qml/qqmlexpression.cpp +++ b/src/qml/qml/qqmlexpression.cpp @@ -354,7 +354,7 @@ v8::Handle QQmlExpressionPrivate::v8value(bool *isUndefined) expressionFunctionValid = true; } - return evaluate(context(), **v8function, isUndefined); + return evaluate(context(), v8function.value(), isUndefined); } QVariant QQmlExpressionPrivate::value(bool *isUndefined) diff --git a/src/qml/qml/qqmlpropertycache.cpp b/src/qml/qml/qqmlpropertycache.cpp index df3d558cb4..bcfc901c53 100644 --- a/src/qml/qml/qqmlpropertycache.cpp +++ b/src/qml/qml/qqmlpropertycache.cpp @@ -290,8 +290,8 @@ QQmlPropertyCache::~QQmlPropertyCache() void QQmlPropertyCache::destroy() { - Q_ASSERT(engine || constructor->isEmpty()); - if (constructor->isEmpty()) + Q_ASSERT(engine || constructor.isEmpty()); + if (constructor.isEmpty()) delete this; else QQmlEnginePrivate::deleteInEngineThread(engine, this); @@ -598,7 +598,7 @@ void QQmlPropertyCache::append(QQmlEngine *engine, const QMetaObject *metaObject QQmlPropertyData::Flag signalFlags) { Q_UNUSED(revision); - Q_ASSERT(constructor->isEmpty()); // We should not be appending to an in-use property cache + Q_ASSERT(constructor.isEmpty()); // We should not be appending to an in-use property cache _metaObject = metaObject; diff --git a/src/qml/qml/qqmlvmemetaobject.cpp b/src/qml/qml/qqmlvmemetaobject.cpp index 37adaad57a..0f808db9a5 100644 --- a/src/qml/qml/qqmlvmemetaobject.cpp +++ b/src/qml/qml/qqmlvmemetaobject.cpp @@ -972,7 +972,7 @@ v8::Handle QQmlVMEMetaObject::method(int index) if (!v8methods) v8methods = new QV4::PersistentValue[metaData->methodCount]; - if (v8methods[index]->isEmpty()) { + if (v8methods[index].isEmpty()) { QQmlVMEMetaData::MethodData *data = metaData->methodData() + index; const char *body = ((const char*)metaData) + data->bodyOffset; diff --git a/src/qml/qml/v4/qv4value.cpp b/src/qml/qml/v4/qv4value.cpp index f330aebad9..af57c47b90 100644 --- a/src/qml/qml/v4/qv4value.cpp +++ b/src/qml/qml/v4/qv4value.cpp @@ -217,11 +217,6 @@ Value Value::property(ExecutionContext *ctx, String *name) const } -PersistentValue::PersistentValue() - : d(new PersistentValuePrivate) -{ -} - PersistentValue::PersistentValue(const Value &val) : d(new PersistentValuePrivate(val)) { @@ -230,7 +225,8 @@ PersistentValue::PersistentValue(const Value &val) PersistentValue::PersistentValue(const PersistentValue &other) : d(other.d) { - d->ref(); + if (d) + d->ref(); } PersistentValue &PersistentValue::operator=(const PersistentValue &other) @@ -239,13 +235,20 @@ PersistentValue &PersistentValue::operator=(const PersistentValue &other) return *this; // the memory manager cleans up those with a refcount of 0 - d->deref(); + + if (d) + d->deref(); d = other.d; - d->ref(); + if (d) + d->ref(); } PersistentValue &PersistentValue::operator =(const Value &other) { + if (!d) { + d = new PersistentValuePrivate(other); + return *this; + } d->value = other; if (!d->prev) { if (Managed *m = d->value.asManaged()) { @@ -261,7 +264,8 @@ PersistentValue &PersistentValue::operator =(const Value &other) PersistentValue::~PersistentValue() { - d->deref(); + if (d) + d->deref(); } PersistentValuePrivate::PersistentValuePrivate(const Value &v) @@ -287,7 +291,8 @@ void PersistentValuePrivate::deref() // and will get cleaned up in the next gc run if (!--refcount) { if (prev) { - next->prev = prev; + if (next) + next->prev = prev; *prev = next; } delete this; diff --git a/src/qml/qml/v4/qv4value_p.h b/src/qml/qml/v4/qv4value_p.h index 1d2285cbc7..5b56c910e5 100644 --- a/src/qml/qml/v4/qv4value_p.h +++ b/src/qml/qml/v4/qv4value_p.h @@ -551,12 +551,6 @@ inline Value Managed::call(ExecutionContext *context, const Value &thisObject, V struct PersistentValuePrivate { - PersistentValuePrivate() - : value(Value::emptyValue()) - , refcount(1) - , prev(0) - , next(0) - {} PersistentValuePrivate(const Value &v); Value value; int refcount; @@ -570,24 +564,27 @@ struct PersistentValuePrivate class PersistentValue { public: - PersistentValue(); + PersistentValue() : d(0) {} PersistentValue(const Value &val); PersistentValue(const PersistentValue &other); PersistentValue &operator=(const PersistentValue &other); PersistentValue &operator=(const Value &other); ~PersistentValue(); - Value *operator->() { return &d->value; } - Value *operator*() { return &d->value; } - const Value *operator->() const { return &d->value; } - const Value *operator*() const { return &d->value; } + Value value() const { + return d ? d->value : Value::emptyValue(); + } ExecutionEngine *engine() { + if (!d) + return 0; Managed *m = d->value.asManaged(); return m ? m->engine() : 0; } - operator Value() const { return d->value; } + operator Value() const { return value(); } + + bool isEmpty() const { return !d; } private: PersistentValuePrivate *d; diff --git a/src/qml/qml/v8/qjsvalue_p.h b/src/qml/qml/v8/qjsvalue_p.h index ab8572baf9..db30ad8c92 100644 --- a/src/qml/qml/v8/qjsvalue_p.h +++ b/src/qml/qml/v8/qjsvalue_p.h @@ -80,7 +80,7 @@ public: : PersistentValuePrivate(QV4::Value::fromString(s)) {} QJSValuePrivate(const QString &s) - : PersistentValuePrivate() + : PersistentValuePrivate(QV4::Value::undefinedValue()) , string(0, s) { value = QV4::Value::fromString(&string); diff --git a/src/qml/qml/v8/qv8bindings.cpp b/src/qml/qml/v8/qv8bindings.cpp index a17f2a732a..f437984ec6 100644 --- a/src/qml/qml/v8/qv8bindings.cpp +++ b/src/qml/qml/v8/qv8bindings.cpp @@ -245,7 +245,7 @@ QV8Bindings::QV8Bindings(QQmlCompiledData::V8Program *program, { QV8Engine *engine = QQmlEnginePrivate::getV8Engine(context->engine); - if (program->bindings->isEmpty()) { + if (program->bindings.isEmpty()) { v8::Handle script; bool compileFailed = false; { @@ -327,7 +327,7 @@ const QString &QV8Bindings::urlString() const QV4::ArrayObject *QV8Bindings::functions() const { - return program->bindings->asArrayObject(); + return program->bindings.value().asArrayObject(); } diff --git a/src/qml/qml/v8/qv8engine.cpp b/src/qml/qml/v8/qv8engine.cpp index 4a6300c256..6dc3ac714b 100644 --- a/src/qml/qml/v8/qv8engine.cpp +++ b/src/qml/qml/v8/qv8engine.cpp @@ -688,7 +688,7 @@ void QV8Engine::initializeGlobal(v8::Handle global) void QV8Engine::freezeObject(const QV4::Value &value) { QV4::Value args = value; - m_freezeObject->asFunctionObject()->call(m_v4Engine->rootContext, QV4::Value::fromObject(m_v4Engine->globalObject), &args, 1); + m_freezeObject.value().asFunctionObject()->call(m_v4Engine->rootContext, QV4::Value::fromObject(m_v4Engine->globalObject), &args, 1); } void QV8Engine::gc() diff --git a/src/qml/qml/v8/qv8qobjectwrapper.cpp b/src/qml/qml/v8/qv8qobjectwrapper.cpp index e25b8b478b..86ae6a165a 100644 --- a/src/qml/qml/v8/qv8qobjectwrapper.cpp +++ b/src/qml/qml/v8/qv8qobjectwrapper.cpp @@ -961,7 +961,7 @@ v8::Handle QQmlPropertyCache::newQObject(QObject *object, QV8Engine Q_ASSERT(QQmlData::get(object, false)->propertyCache == this); // Setup constructor - if (constructor->isEmpty()) { + if (constructor.isEmpty()) { v8::Handle ft; const QHashedString toString(QStringLiteral("toString")); @@ -1050,7 +1050,7 @@ v8::Handle QQmlPropertyCache::newQObject(QObject *object, QV8Engine QQmlCleanup::addToEngine(this->engine); } - v8::Handle result = constructor->asFunctionObject()->newInstance(); + v8::Handle result = constructor.value().asFunctionObject()->newInstance(); QV8QObjectResource *r = new QV8QObjectResource(engine, object); result->SetExternalResource(r); return result; -- cgit v1.2.3