diff options
author | Lars Knoll <lars.knoll@digia.com> | 2013-05-24 13:26:38 +0200 |
---|---|---|
committer | Simon Hausmann <simon.hausmann@digia.com> | 2013-05-24 13:58:56 +0200 |
commit | 0de6e8bb1bf0ca6e4d7992be15ed31f87514e48a (patch) | |
tree | 29e0e58b32607a5edb6c309dd53645d5af4b8ee9 /src/qml/qml/v8 | |
parent | 74632fa02a5bd8653c02a4d84a1bcb6b1d5a88f5 (diff) |
Get rid of Get/SetHiddenValue in the v8 API
It was only used to mark an object as something to be used as a binding.
Simply use one of the free bits in QV4::Managed for that.
Also changed a bit more code over from v8 to v4.
Change-Id: I6e787e611041e058fe109df1d7a13598655f8eba
Reviewed-by: Simon Hausmann <simon.hausmann@digia.com>
Diffstat (limited to 'src/qml/qml/v8')
-rw-r--r-- | src/qml/qml/v8/qqmlbuiltinfunctions.cpp | 10 | ||||
-rw-r--r-- | src/qml/qml/v8/qv8contextwrapper.cpp | 8 | ||||
-rw-r--r-- | src/qml/qml/v8/qv8contextwrapper_p.h | 4 | ||||
-rw-r--r-- | src/qml/qml/v8/qv8engine_p.h | 12 | ||||
-rw-r--r-- | src/qml/qml/v8/qv8qobjectwrapper.cpp | 5 | ||||
-rw-r--r-- | src/qml/qml/v8/qv8valuetypewrapper.cpp | 5 |
6 files changed, 20 insertions, 24 deletions
diff --git a/src/qml/qml/v8/qqmlbuiltinfunctions.cpp b/src/qml/qml/v8/qqmlbuiltinfunctions.cpp index 31d89b726a..387a23f5a1 100644 --- a/src/qml/qml/v8/qqmlbuiltinfunctions.cpp +++ b/src/qml/qml/v8/qqmlbuiltinfunctions.cpp @@ -53,6 +53,7 @@ #include <private/qqmlglobal_p.h> #include <private/qv4engine_p.h> +#include <private/qv4functionobject_p.h> #include <QtCore/qstring.h> #include <QtCore/qdatetime.h> @@ -1584,13 +1585,14 @@ QV4::Value binding(const v8::Arguments &args) QString code; if (args.Length() != 1) V4THROW_ERROR("binding() requires 1 argument"); - if (!args[0]->IsFunction()) + QV4::FunctionObject *f = args[0]->v4Value().asFunctionObject(); + if (!f) V4THROW_TYPE("binding(): argument (binding expression) must be a function"); - v8::Handle<v8::Object> rv = args[0]->ToObject(); - if (!rv->SetHiddenValue(v8::Value::fromV4Value(V8ENGINE()->bindingFlagKey()), QV4::Value::fromBoolean(true))) + if (f->bindingKeyFlag) V4THROW_ERROR("function passed to binding() can only be bound once"); // FIXME: With v8 we cloned the binding argument - return rv->v4Value(); + f->bindingKeyFlag = true; + return QV4::Value::fromObject(f); } } // namespace QQmlBuiltinFunctions diff --git a/src/qml/qml/v8/qv8contextwrapper.cpp b/src/qml/qml/v8/qv8contextwrapper.cpp index b24b71ee29..7bafd78ddc 100644 --- a/src/qml/qml/v8/qv8contextwrapper.cpp +++ b/src/qml/qml/v8/qv8contextwrapper.cpp @@ -170,16 +170,16 @@ void QV8ContextWrapper::init(QV8Engine *engine) } } -v8::Handle<v8::Object> QV8ContextWrapper::qmlScope(QQmlContextData *ctxt, QObject *scope) +QV4::Value QV8ContextWrapper::qmlScope(QQmlContextData *ctxt, QObject *scope) { // XXX NewInstance() should be optimized v8::Handle<v8::Object> rv = m_constructor.value().asFunctionObject()->newInstance(); QV8ContextResource *r = new QV8ContextResource(m_engine, ctxt, scope); rv->SetExternalResource(r); - return rv; + return rv->v4Value(); } -v8::Handle<v8::Object> QV8ContextWrapper::urlScope(const QUrl &url) +QV4::Value QV8ContextWrapper::urlScope(const QUrl &url) { QQmlContextData *context = new QQmlContextData; context->url = url; @@ -190,7 +190,7 @@ v8::Handle<v8::Object> QV8ContextWrapper::urlScope(const QUrl &url) v8::Handle<v8::Object> rv = m_urlConstructor.value().asFunctionObject()->newInstance(); QV8ContextResource *r = new QV8ContextResource(m_engine, context, 0, true); rv->SetExternalResource(r); - return rv; + return rv->v4Value(); } void QV8ContextWrapper::setReadOnly(v8::Handle<v8::Object> qmlglobal, bool readOnly) diff --git a/src/qml/qml/v8/qv8contextwrapper_p.h b/src/qml/qml/v8/qv8contextwrapper_p.h index 57eb46de44..8a72489e6e 100644 --- a/src/qml/qml/v8/qv8contextwrapper_p.h +++ b/src/qml/qml/v8/qv8contextwrapper_p.h @@ -74,8 +74,8 @@ public: void init(QV8Engine *); void destroy(); - v8::Handle<v8::Object> qmlScope(QQmlContextData *ctxt, QObject *scope); - v8::Handle<v8::Object> urlScope(const QUrl &); + QV4::Value qmlScope(QQmlContextData *ctxt, QObject *scope); + QV4::Value urlScope(const QUrl &); void setReadOnly(v8::Handle<v8::Object>, bool); diff --git a/src/qml/qml/v8/qv8engine_p.h b/src/qml/qml/v8/qv8engine_p.h index 24096b7f68..619cce4fcd 100644 --- a/src/qml/qml/v8/qv8engine_p.h +++ b/src/qml/qml/v8/qv8engine_p.h @@ -293,7 +293,7 @@ public: QV4::Value fromVariant(const QVariant &); // Return the QML global "scope" object for the \a ctxt context and \a scope object. - inline v8::Handle<v8::Object> qmlScope(QQmlContextData *ctxt, QObject *scope); + inline QV4::Value qmlScope(QQmlContextData *ctxt, QObject *scope); // Return a JS wrapper for the given QObject \a object inline QV4::Value newQObject(QObject *object); @@ -313,9 +313,6 @@ public: // Create a new sequence type object inline QV4::Value newSequence(int sequenceType, QObject *, int coreIndex, bool *succeeded); - // Return the JS string key for the "function is a binding" flag - inline QV4::Value bindingFlagKey() const; - // Return the network access manager for this engine. By default this returns the network // access manager of the QQmlEngine. It is overridden in the case of a threaded v8 // instance (like in WorkerScript). @@ -442,7 +439,7 @@ private: Q_DISABLE_COPY(QV8Engine) }; -v8::Handle<v8::Object> QV8Engine::qmlScope(QQmlContextData *ctxt, QObject *scope) +QV4::Value QV8Engine::qmlScope(QQmlContextData *ctxt, QObject *scope) { return m_contextWrapper.qmlScope(ctxt, scope); } @@ -501,11 +498,6 @@ QV4::Value QV8Engine::newSequence(int sequenceType, QObject *object, int propert return QV4::SequencePrototype::newSequence(m_v4Engine, sequenceType, object, property, succeeded); } -QV4::Value QV8Engine::bindingFlagKey() const -{ - return m_bindingFlagKey; -} - QV8Engine::Deletable *QV8Engine::extensionData(int index) const { if (index < m_extensionData.count()) diff --git a/src/qml/qml/v8/qv8qobjectwrapper.cpp b/src/qml/qml/v8/qv8qobjectwrapper.cpp index 173c71acd0..36d4b1c528 100644 --- a/src/qml/qml/v8/qv8qobjectwrapper.cpp +++ b/src/qml/qml/v8/qv8qobjectwrapper.cpp @@ -727,7 +727,8 @@ static inline void StoreProperty(QV8Engine *engine, QObject *object, QQmlPropert { QQmlBinding *newBinding = 0; if (value->IsFunction()) { - if (value->ToObject()->GetHiddenValue(v8::Value::fromV4Value(engine->bindingFlagKey())).IsEmpty()) { + QV4::FunctionObject *f = value->v4Value().asFunctionObject(); + if (!f->bindingKeyFlag) { 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 "); @@ -746,7 +747,7 @@ static inline void StoreProperty(QV8Engine *engine, QObject *object, QQmlPropert QV4::ExecutionEngine *v4 = QV8Engine::getV4(engine); QV4::ExecutionEngine::StackFrame frame = v4->currentStackFrame(); - newBinding = new QQmlBinding(&function, object, context, frame.source.url(), + newBinding = new QQmlBinding(function->v4Value(), object, context, frame.source.url(), qmlSourceCoordinate(frame.line), qmlSourceCoordinate(frame.column)); newBinding->setTarget(object, *property, context); newBinding->setEvaluateFlags(newBinding->evaluateFlags() | diff --git a/src/qml/qml/v8/qv8valuetypewrapper.cpp b/src/qml/qml/v8/qv8valuetypewrapper.cpp index 9297df3d17..3218da4e38 100644 --- a/src/qml/qml/v8/qv8valuetypewrapper.cpp +++ b/src/qml/qml/v8/qv8valuetypewrapper.cpp @@ -373,7 +373,8 @@ v8::Handle<v8::Value> QV8ValueTypeWrapper::Setter(v8::Handle<v8::String> propert QQmlBinding *newBinding = 0; if (value->IsFunction()) { - if (value->ToObject()->GetHiddenValue(v8::Value::fromV4Value(r->engine->bindingFlagKey())).IsEmpty()) { + QV4::FunctionObject *f = value->v4Value().asFunctionObject(); + if (f->bindingKeyFlag) { // assigning a JS function to a non-var-property is not allowed. QString error = QLatin1String("Cannot assign JavaScript function to value-type property"); v8::ThrowException(v8::Exception::Error(r->engine->toString(error))); @@ -395,7 +396,7 @@ v8::Handle<v8::Value> QV8ValueTypeWrapper::Setter(v8::Handle<v8::String> propert QV4::ExecutionEngine *v4 = QV8Engine::getV4(r->engine); QV4::ExecutionEngine::StackFrame frame = v4->currentStackFrame(); - newBinding = new QQmlBinding(&function, reference->object, context, + newBinding = new QQmlBinding(function->v4Value(), reference->object, context, frame.source.url(), qmlSourceCoordinate(frame.line), qmlSourceCoordinate(frame.column)); newBinding->setTarget(reference->object, cacheData, context); newBinding->setEvaluateFlags(newBinding->evaluateFlags() | |