Get rid of the bindingKeyFlag
authorLars Knoll <lars.knoll@theqtcompany.com>
Fri, 9 Jan 2015 11:11:09 +0000 (12:11 +0100)
committerSimon Hausmann <simon.hausmann@digia.com>
Mon, 12 Jan 2015 10:04:15 +0000 (11:04 +0100)
Instead use the vtable to identify that we have a
binding function.

Change-Id: I794aebb6fb83f648ba36f2f15cad94d2af3cae91
Reviewed-by: Robin Burchell <robin.burchell@viroteck.net>
Reviewed-by: Simon Hausmann <simon.hausmann@digia.com>
src/qml/jsruntime/qv4functionobject.cpp
src/qml/jsruntime/qv4functionobject_p.h
src/qml/jsruntime/qv4qobjectwrapper.cpp
src/qml/jsruntime/qv4value_p.h
src/qml/qml/qqmlbinding.cpp
src/qml/qml/qqmlproperty.cpp
src/qml/qml/qqmlvaluetypewrapper.cpp
src/qml/qml/v8/qqmlbuiltinfunctions.cpp

index 0cdf6b5..f70ddb0 100644 (file)
@@ -50,6 +50,7 @@
 #include <private/qqmlengine_p.h>
 #include <qv4codegen_p.h>
 #include "private/qlocale_tools_p.h"
+#include "private/qqmlbuiltinfunctions_p.h"
 
 #include <QtCore/qmath.h>
 #include <QtCore/QDebug>
@@ -202,6 +203,11 @@ Heap::FunctionObject *FunctionObject::createScriptFunction(ExecutionContext *sco
     return scope->d()->engine->memoryManager->alloc<SimpleScriptFunction>(scope, function, createProto);
 }
 
+bool FunctionObject::isBinding() const
+{
+    return d()->internalClass->vtable == QQmlBindingFunction::staticVTable();
+}
+
 DEFINE_OBJECT_VTABLE(FunctionCtor);
 
 Heap::FunctionCtor::FunctionCtor(QV4::ExecutionContext *scope)
index 7406e9b..d3053ce 100644 (file)
@@ -143,7 +143,7 @@ struct Q_QML_EXPORT FunctionObject: Object {
 
     bool needsActivation() const { return d()->needsActivation; }
     bool strictMode() const { return d()->function ? d()->function->isStrict() : false; }
-    bool bindingKeyFlag() const { return d()->bindingKeyFlag; }
+    bool isBinding() const;
 
     static void markObjects(Heap::Base *that, ExecutionEngine *e);
 };
index 46a458b..149bf24 100644 (file)
@@ -458,7 +458,7 @@ void QObjectWrapper::setProperty(QObject *object, ExecutionContext *ctx, QQmlPro
     QV4::Scope scope(ctx);
     QV4::ScopedFunctionObject f(scope, value);
     if (f) {
-        if (!f->bindingKeyFlag()) {
+        if (!f->isBinding()) {
             if (!property->isVarProperty() && property->propType != qMetaTypeId<QJSValue>()) {
                 // assigning a JS function to a non var or QJSValue property or is not allowed.
                 QString error = QLatin1String("Cannot assign JavaScript function to ");
index 01a1542..6a67719 100644 (file)
@@ -63,7 +63,7 @@ struct Q_QML_EXPORT Base {
         uchar extensible : 1; // used by Object
         uchar needsActivation : 1; // used by FunctionObject
         uchar _strictMode : 1; // used by FunctionObject
-        uchar bindingKeyFlag : 1;
+        uchar _bindingKeyFlag : 1;
         uchar hasAccessorProperty : 1;
         uchar _unused : 1;
         mutable uchar subtype;
index 3eb3870..3de2955 100644 (file)
@@ -169,7 +169,7 @@ void QQmlBinding::update(QQmlPropertyPrivate::WriteFlags flags)
     QV4::Scope scope(ep->v4engine());
     QV4::ScopedFunctionObject f(scope, v4function.value());
     Q_ASSERT(f);
-    if (f->bindingKeyFlag()) {
+    if (f->isBinding()) {
         Q_ASSERT(f->as<QV4::QQmlBindingFunction>());
         QQmlSourceLocation loc = static_cast<QV4::Heap::QQmlBindingFunction *>(f->d())->bindingLocation;
         url = loc.sourceFile;
index b22943e..a4c46a1 100644 (file)
@@ -1526,7 +1526,7 @@ bool QQmlPropertyPrivate::writeBinding(QObject *object,
         return false;
     } else if (isVarProperty) {
         QV4::FunctionObject *f = result->asFunctionObject();
-        if (f && f->bindingKeyFlag()) {
+        if (f && f->isBinding()) {
             // we explicitly disallow this case to avoid confusion.  Users can still store one
             // in an array in a var property if they need to, but the common case is user error.
             expression->delayedError()->setErrorDescription(QLatin1String("Invalid use of Qt.binding() in a binding declaration."));
@@ -1544,7 +1544,7 @@ bool QQmlPropertyPrivate::writeBinding(QObject *object,
         writeValueProperty(object, core, QVariant(), context, flags);
     } else if (type == qMetaTypeId<QJSValue>()) {
         QV4::FunctionObject *f = result->asFunctionObject();
-        if (f && f->bindingKeyFlag()) {
+        if (f && f->isBinding()) {
             expression->delayedError()->setErrorDescription(QLatin1String("Invalid use of Qt.binding() in a binding declaration."));
             expression->delayedError()->setErrorObject(object);
             return false;
@@ -1562,7 +1562,7 @@ bool QQmlPropertyPrivate::writeBinding(QObject *object,
         expression->delayedError()->setErrorObject(object);
         return false;
     } else if (QV4::FunctionObject *f = result->asFunctionObject()) {
-        if (f->bindingKeyFlag())
+        if (f->isBinding())
             expression->delayedError()->setErrorDescription(QLatin1String("Invalid use of Qt.binding() in a binding declaration."));
         else
             expression->delayedError()->setErrorDescription(QLatin1String("Unable to assign a function to a property of any type other than var."));
index fb52fba..b72b89c 100644 (file)
@@ -364,7 +364,7 @@ void QQmlValueTypeWrapper::put(Managed *m, String *name, const ValueRef value)
 
     QV4::ScopedFunctionObject f(scope, value);
     if (reference && f) {
-        if (!f->bindingKeyFlag()) {
+        if (!f->isBinding()) {
             // assigning a JS function to a non-var-property is not allowed.
             QString error = QStringLiteral("Cannot assign JavaScript function to value-type property");
             ScopedString e(scope, v4->newString(error));
index eb4e7c4..6cb7990 100644 (file)
@@ -1149,7 +1149,6 @@ Heap::QQmlBindingFunction::QQmlBindingFunction(QV4::FunctionObject *originalFunc
     , originalFunction(originalFunction->d())
 {
     setVTable(QV4::QQmlBindingFunction::staticVTable());
-    bindingKeyFlag = true;
 }
 
 void QQmlBindingFunction::initBindingLocation()