diff options
author | Chris Adams <christopher.adams@nokia.com> | 2012-02-27 10:51:57 +1000 |
---|---|---|
committer | Qt by Nokia <qt-info@nokia.com> | 2012-03-05 10:06:48 +0100 |
commit | 92b1f9981d225ecee28da1f0a88fb3046000cb5e (patch) | |
tree | 83ddfc1b5372d114e8ea46fd78d008966a7d4bd3 /src/qml/qml/v8/qv8qobjectwrapper.cpp | |
parent | b6e78b38367a23f0b053bbd2abe4ef161e4053b9 (diff) |
Allow function assignment to cause binding for non-var props
This patch maintains the old function-assignment behaviour for non-var
properties, and will be reverted soon.
Change-Id: I523e464501106616c51ff7478f7eb7171c1ca350
Reviewed-by: Matthew Vogt <matthew.vogt@nokia.com>
Diffstat (limited to 'src/qml/qml/v8/qv8qobjectwrapper.cpp')
-rw-r--r-- | src/qml/qml/v8/qv8qobjectwrapper.cpp | 29 |
1 files changed, 25 insertions, 4 deletions
diff --git a/src/qml/qml/v8/qv8qobjectwrapper.cpp b/src/qml/qml/v8/qv8qobjectwrapper.cpp index 59b58ca503..4be93d111d 100644 --- a/src/qml/qml/v8/qv8qobjectwrapper.cpp +++ b/src/qml/qml/v8/qv8qobjectwrapper.cpp @@ -582,11 +582,32 @@ static inline void StoreProperty(QV8Engine *engine, QObject *object, QQmlPropert if (value->IsFunction()) { if (value->ToObject()->GetHiddenValue(engine->bindingFlagKey()).IsEmpty()) { if (!property->isVMEProperty()) { + // XXX TODO: uncomment the following lines // assigning a JS function to a non-var-property is not allowed. - QString error = QLatin1String("Cannot assign JavaScript function to ") + - QLatin1String(QMetaType::typeName(property->propType)); - v8::ThrowException(v8::Exception::Error(engine->toString(error))); - return; + //QString error = QLatin1String("Cannot assign JavaScript function to ") + + // QLatin1String(QMetaType::typeName(property->propType)); + //v8::ThrowException(v8::Exception::Error(engine->toString(error))); + //return; + // XXX TODO: remove the following transition behaviour + // Temporarily allow assignment of functions to non-var properties + // to mean binding assignment (as per old behaviour). + QQmlContextData *context = engine->callingContext(); + v8::Handle<v8::Function> function = v8::Handle<v8::Function>::Cast(value); + + v8::Local<v8::StackTrace> trace = + v8::StackTrace::CurrentStackTrace(1, (v8::StackTrace::StackTraceOptions)(v8::StackTrace::kLineNumber | + v8::StackTrace::kScriptName)); + v8::Local<v8::StackFrame> frame = trace->GetFrame(0); + int lineNumber = frame->GetLineNumber(); + int columNumber = frame->GetColumn(); + QString url = engine->toString(frame->GetScriptName()); + + newBinding = new QQmlBinding(&function, object, context); + newBinding->setSourceLocation(url, lineNumber, columNumber); + newBinding->setTarget(object, *property, context); + newBinding->setEvaluateFlags(newBinding->evaluateFlags() | + QQmlBinding::RequiresThisObject); + qWarning("WARNING: function assignment is DEPRECATED and will be removed! Wrap RHS in Qt.binding(): %s:%d", qPrintable(engine->toString(frame->GetScriptName())), frame->GetLineNumber()); } } else { // binding assignment. |