diff options
author | Kent Hansen <kent.hansen@nokia.com> | 2012-01-17 15:23:01 +0100 |
---|---|---|
committer | Qt by Nokia <qt-info@nokia.com> | 2012-02-02 08:10:24 +0100 |
commit | 54c51c89e21800b3a455127b3c19a3c5b30ee319 (patch) | |
tree | 9781a998567abf4513919cc08e928a3df03eecbf /src/declarative/qml | |
parent | ed84a6ee63ac7a53f37efad3eb4a7e4eaa047242 (diff) |
Remove QJSValue::propertyFlags() function
Rationale: The API is incomplete. There is no way to set/update the
flags; adding a third (optional) argument to setProperty() is ugly.
If necessary, a QJSPropertyDescriptor API should be added, to enable
complete setting/querying of properties.
The flags were moved to QJSValuePrivate, and the propertyFlags()
implementation kept, because there is one place the read-only flag
is checked internally (in qv8typewrapper).
Task-number: QTBUG-23604
Change-Id: I089dce28dbda428662aac7c8d1536987fe6d855c
Reviewed-by: Jędrzej Nowacki <jedrzej.nowacki@nokia.com>
Diffstat (limited to 'src/declarative/qml')
-rw-r--r-- | src/declarative/qml/v8/qjsconverter_impl_p.h | 8 | ||||
-rw-r--r-- | src/declarative/qml/v8/qjsconverter_p.h | 4 | ||||
-rw-r--r-- | src/declarative/qml/v8/qjsvalue.cpp | 33 | ||||
-rw-r--r-- | src/declarative/qml/v8/qjsvalue.h | 15 | ||||
-rw-r--r-- | src/declarative/qml/v8/qjsvalue_impl_p.h | 8 | ||||
-rw-r--r-- | src/declarative/qml/v8/qjsvalue_p.h | 13 | ||||
-rw-r--r-- | src/declarative/qml/v8/qscriptoriginalglobalobject_p.h | 14 | ||||
-rw-r--r-- | src/declarative/qml/v8/qv8engine_impl_p.h | 4 | ||||
-rw-r--r-- | src/declarative/qml/v8/qv8engine_p.h | 2 | ||||
-rw-r--r-- | src/declarative/qml/v8/qv8typewrapper.cpp | 2 |
10 files changed, 32 insertions, 71 deletions
diff --git a/src/declarative/qml/v8/qjsconverter_impl_p.h b/src/declarative/qml/v8/qjsconverter_impl_p.h index 0e2b6ba519..018c0441a2 100644 --- a/src/declarative/qml/v8/qjsconverter_impl_p.h +++ b/src/declarative/qml/v8/qjsconverter_impl_p.h @@ -143,14 +143,14 @@ QString QJSConverter::toString(double value) } // return a mask of v8::PropertyAttribute that may also contains QScriptValue::PropertyGetter or QScriptValue::PropertySetter -uint QJSConverter::toPropertyAttributes(const QFlags<QJSValue::PropertyFlag>& flags) +uint QJSConverter::toPropertyAttributes(const QFlags<QJSValuePrivate::PropertyFlag>& flags) { uint attr = 0; - if (flags.testFlag(QJSValue::ReadOnly)) + if (flags.testFlag(QJSValuePrivate::ReadOnly)) attr |= v8::ReadOnly; - if (flags.testFlag(QJSValue::Undeletable)) + if (flags.testFlag(QJSValuePrivate::Undeletable)) attr |= v8::DontDelete; - if (flags.testFlag(QJSValue::SkipInEnumeration)) + if (flags.testFlag(QJSValuePrivate::SkipInEnumeration)) attr |= v8::DontEnum; // if (flags.testFlag(QScriptValue::PropertyGetter)) // attr |= QScriptValue::PropertyGetter; diff --git a/src/declarative/qml/v8/qjsconverter_p.h b/src/declarative/qml/v8/qjsconverter_p.h index 1e35928609..29fef3c700 100644 --- a/src/declarative/qml/v8/qjsconverter_p.h +++ b/src/declarative/qml/v8/qjsconverter_p.h @@ -24,7 +24,7 @@ #ifndef QJSCONVERTER_P_H #define QJSCONVERTER_P_H -#include "qjsvalue.h" +#include "qjsvalue_p.h" #include <QtCore/qglobal.h> #include <QtCore/qnumeric.h> #include <QtCore/qstring.h> @@ -57,7 +57,7 @@ public: PropertyAttributeMask = v8::ReadOnly | v8::DontDelete | v8::DontEnum, }; // return a mask of v8::PropertyAttribute that may also contains QScriptValue::PropertyGetter or QScriptValue::PropertySetter - static inline uint toPropertyAttributes(const QFlags<QJSValue::PropertyFlag>& flags); + static inline uint toPropertyAttributes(const QFlags<QJSValuePrivate::PropertyFlag>& flags); // Converts a JS RegExp to a QRegExp. // The conversion is not 100% exact since ECMA regexp and QRegExp diff --git a/src/declarative/qml/v8/qjsvalue.cpp b/src/declarative/qml/v8/qjsvalue.cpp index 73b7e4f9c7..5387f843f0 100644 --- a/src/declarative/qml/v8/qjsvalue.cpp +++ b/src/declarative/qml/v8/qjsvalue.cpp @@ -61,9 +61,6 @@ \snippet doc/src/snippets/code/src_script_qjsvalue.cpp 0 - The attributes of a property can be queried by calling the - propertyFlags() function. - If you want to iterate over the properties of a script object, use the QJSValueIterator class. @@ -96,18 +93,6 @@ \value NullValue A null value. */ -/*! - \enum QJSValue::PropertyFlag - - This enum describes the attributes of a property. - - \value ReadOnly The property is read-only. Attempts by Qt Script code to write to the property will be ignored. - - \value Undeletable Attempts by Qt Script code to \c{delete} the property will be ignored. - - \value SkipInEnumeration The property is not to be enumerated by a \c{for-in} enumeration. -*/ - QT_BEGIN_NAMESPACE /*! @@ -995,24 +980,6 @@ bool QJSValue::hasOwnProperty(const QString &name) const return d->hasOwnProperty(name); } -#ifdef QT_DEPRECATED - -/*! - \obsolete - - Returns the flags of the property with the given \a name. - - \sa property() -*/ -QJSValue::PropertyFlags QJSValue::propertyFlags(const QString& name) const -{ - Q_D(const QJSValue); - QScriptIsolate api(d->engine()); - return d->propertyFlags(name); -} - -#endif // QT_DEPRECATED - /*! * If this QJSValue is a QObject, returns the QObject pointer * that the QJSValue represents; otherwise, returns 0. diff --git a/src/declarative/qml/v8/qjsvalue.h b/src/declarative/qml/v8/qjsvalue.h index 8ec2932dc3..897ccb1e39 100644 --- a/src/declarative/qml/v8/qjsvalue.h +++ b/src/declarative/qml/v8/qjsvalue.h @@ -51,15 +51,6 @@ template <class T> class QScriptPassPointer; class Q_DECLARATIVE_EXPORT QJSValue { public: -#ifdef QT_DEPRECATED - enum PropertyFlag { - ReadOnly = 0x00000001, - Undeletable = 0x00000002, - SkipInEnumeration = 0x00000004 - }; - Q_DECLARE_FLAGS(PropertyFlags, PropertyFlag) -#endif - enum SpecialValue { NullValue, UndefinedValue @@ -140,8 +131,6 @@ public: QT_DEPRECATED qint32 toInt32() const; QT_DEPRECATED quint32 toUInt32() const; - QT_DEPRECATED QJSValue::PropertyFlags propertyFlags(const QString &name) const; - QT_DEPRECATED QJSValue call(const QJSValue &thisObject = QJSValue(), const QJSValueList &args = QJSValueList()); QT_DEPRECATED QJSValue construct(const QJSValueList &args = QJSValueList()); @@ -165,10 +154,6 @@ private: Q_DECLARE_PRIVATE(QJSValue) }; -#ifdef QT_DEPRECATED -Q_DECLARE_OPERATORS_FOR_FLAGS(QJSValue::PropertyFlags) -#endif - QT_END_NAMESPACE QT_END_HEADER diff --git a/src/declarative/qml/v8/qjsvalue_impl_p.h b/src/declarative/qml/v8/qjsvalue_impl_p.h index b4e66ed093..69ec70beed 100644 --- a/src/declarative/qml/v8/qjsvalue_impl_p.h +++ b/src/declarative/qml/v8/qjsvalue_impl_p.h @@ -714,19 +714,19 @@ inline bool QJSValuePrivate::hasOwnProperty(const QString &name) const return self->HasOwnProperty(QJSConverter::toString(name)); } -inline QJSValue::PropertyFlags QJSValuePrivate::propertyFlags(const QString& name) const +inline QJSValuePrivate::PropertyFlags QJSValuePrivate::propertyFlags(const QString& name) const { if (!isObject()) - return QJSValue::PropertyFlags(0); + return QJSValuePrivate::PropertyFlags(0); v8::HandleScope handleScope; return engine()->getPropertyFlags(v8::Handle<v8::Object>::Cast(m_value), QJSConverter::toString(name)); } -inline QJSValue::PropertyFlags QJSValuePrivate::propertyFlags(v8::Handle<v8::String> name) const +inline QJSValuePrivate::PropertyFlags QJSValuePrivate::propertyFlags(v8::Handle<v8::String> name) const { if (!isObject()) - return QJSValue::PropertyFlags(0); + return QJSValuePrivate::PropertyFlags(0); v8::HandleScope handleScope; return engine()->getPropertyFlags(v8::Handle<v8::Object>::Cast(m_value), name); diff --git a/src/declarative/qml/v8/qjsvalue_p.h b/src/declarative/qml/v8/qjsvalue_p.h index 02ffc8108e..3eccba64bd 100644 --- a/src/declarative/qml/v8/qjsvalue_p.h +++ b/src/declarative/qml/v8/qjsvalue_p.h @@ -59,6 +59,13 @@ class QJSValuePrivate : public QSharedData { public: + enum PropertyFlag { + ReadOnly = 0x00000001, + Undeletable = 0x00000002, + SkipInEnumeration = 0x00000004 + }; + Q_DECLARE_FLAGS(PropertyFlags, PropertyFlag) + inline static QJSValuePrivate* get(const QJSValue& q); inline static QJSValue get(const QJSValuePrivate* d); inline static QJSValue get(QJSValuePrivate* d); @@ -125,8 +132,8 @@ public: inline bool deleteProperty(const QString& name); inline bool hasProperty(const QString &name) const; inline bool hasOwnProperty(const QString &name) const; - inline QJSValue::PropertyFlags propertyFlags(const QString& name) const; - inline QJSValue::PropertyFlags propertyFlags(v8::Handle<v8::String> name) const; + inline PropertyFlags propertyFlags(const QString& name) const; + inline PropertyFlags propertyFlags(v8::Handle<v8::String> name) const; inline QScriptPassPointer<QJSValuePrivate> call(QJSValuePrivate* thisObject, const QJSValueList& args); inline QScriptPassPointer<QJSValuePrivate> call(QJSValuePrivate* thisObject, const QJSValue& arguments); @@ -181,6 +188,8 @@ private: friend class QV8Engine; }; +Q_DECLARE_OPERATORS_FOR_FLAGS(QJSValuePrivate::PropertyFlags) + QT_END_NAMESPACE #endif diff --git a/src/declarative/qml/v8/qscriptoriginalglobalobject_p.h b/src/declarative/qml/v8/qscriptoriginalglobalobject_p.h index 4fd47fbde0..12321cc71a 100644 --- a/src/declarative/qml/v8/qscriptoriginalglobalobject_p.h +++ b/src/declarative/qml/v8/qscriptoriginalglobalobject_p.h @@ -25,7 +25,7 @@ #define QSCRIPTORIGINALGLOBALOBJECT_P_H #include "QtCore/qglobal.h" -#include "qjsvalue.h" +#include "qjsvalue_p.h" #include <private/qv8_p.h> @@ -53,7 +53,7 @@ public: inline void init(v8::Handle<v8::Context> context); inline void destroy(); - inline QJSValue::PropertyFlags getPropertyFlags(v8::Handle<v8::Object> object, v8::Handle<v8::Value> property); + inline QJSValuePrivate::PropertyFlags getPropertyFlags(v8::Handle<v8::Object> object, v8::Handle<v8::Value> property); inline v8::Local<v8::Object> getOwnPropertyDescriptor(v8::Handle<v8::Object> object, v8::Handle<v8::Value> property) const; inline bool strictlyEquals(v8::Handle<v8::Object> object); private: @@ -96,7 +96,7 @@ inline void QScriptOriginalGlobalObject::destroy() // After this line this instance is unusable. } -inline QJSValue::PropertyFlags QScriptOriginalGlobalObject::getPropertyFlags(v8::Handle<v8::Object> object, v8::Handle<v8::Value> property) +inline QJSValuePrivate::PropertyFlags QScriptOriginalGlobalObject::getPropertyFlags(v8::Handle<v8::Object> object, v8::Handle<v8::Value> property) { Q_ASSERT(object->IsObject()); Q_ASSERT(!property.IsEmpty()); @@ -119,14 +119,14 @@ inline QJSValue::PropertyFlags QScriptOriginalGlobalObject::getPropertyFlags(v8: unsigned flags = 0; if (!descriptor->Get(configurableName)->BooleanValue()) - flags |= QJSValue::Undeletable; + flags |= QJSValuePrivate::Undeletable; if (!descriptor->Get(enumerableName)->BooleanValue()) - flags |= QJSValue::SkipInEnumeration; + flags |= QJSValuePrivate::SkipInEnumeration; //"writable" is only a property of the descriptor if it is not an accessor if (descriptor->Has(writableName)) { if (!descriptor->Get(writableName)->BooleanValue()) - flags |= QJSValue::ReadOnly; + flags |= QJSValuePrivate::ReadOnly; } else { // if (descriptor->Get(getName)->IsObject()) // flags |= QScriptValue::PropertyGetter; @@ -134,7 +134,7 @@ inline QJSValue::PropertyFlags QScriptOriginalGlobalObject::getPropertyFlags(v8: // flags |= QScriptValue::PropertySetter; } - return QJSValue::PropertyFlag(flags); + return QJSValuePrivate::PropertyFlag(flags); } inline v8::Local<v8::Object> QScriptOriginalGlobalObject::getOwnPropertyDescriptor(v8::Handle<v8::Object> object, v8::Handle<v8::Value> property) const diff --git a/src/declarative/qml/v8/qv8engine_impl_p.h b/src/declarative/qml/v8/qv8engine_impl_p.h index 30ca3a029a..349589680a 100644 --- a/src/declarative/qml/v8/qv8engine_impl_p.h +++ b/src/declarative/qml/v8/qv8engine_impl_p.h @@ -128,9 +128,9 @@ inline void QV8Engine::invalidateAllIterators() \note property can be index (v8::Integer) or a property (v8::String) name, according to ECMA script property would be converted to a string. */ -inline QJSValue::PropertyFlags QV8Engine::getPropertyFlags(v8::Handle<v8::Object> object, v8::Handle<v8::Value> property) +inline QJSValuePrivate::PropertyFlags QV8Engine::getPropertyFlags(v8::Handle<v8::Object> object, v8::Handle<v8::Value> property) { - QJSValue::PropertyFlags flags = m_originalGlobalObject.getPropertyFlags(object, property); + QJSValuePrivate::PropertyFlags flags = m_originalGlobalObject.getPropertyFlags(object, property); return flags; } diff --git a/src/declarative/qml/v8/qv8engine_p.h b/src/declarative/qml/v8/qv8engine_p.h index d9cc9fc6f4..ecfc33d85a 100644 --- a/src/declarative/qml/v8/qv8engine_p.h +++ b/src/declarative/qml/v8/qv8engine_p.h @@ -315,7 +315,7 @@ public: QDeclarativeContextData *callingContext(); v8::Local<v8::Array> getOwnPropertyNames(v8::Handle<v8::Object>); - inline QJSValue::PropertyFlags getPropertyFlags(v8::Handle<v8::Object> object, v8::Handle<v8::Value> property); + inline QJSValuePrivate::PropertyFlags getPropertyFlags(v8::Handle<v8::Object> object, v8::Handle<v8::Value> property); void freezeObject(v8::Handle<v8::Value>); inline QString toString(v8::Handle<v8::Value> string); diff --git a/src/declarative/qml/v8/qv8typewrapper.cpp b/src/declarative/qml/v8/qv8typewrapper.cpp index 0a4c390814..d9060be309 100644 --- a/src/declarative/qml/v8/qv8typewrapper.cpp +++ b/src/declarative/qml/v8/qv8typewrapper.cpp @@ -297,7 +297,7 @@ v8::Handle<v8::Value> QV8TypeWrapper::Setter(v8::Local<v8::String> property, } else if (!moduleApi->scriptApi.isUndefined()) { QScopedPointer<QJSValuePrivate> setvalp(new QJSValuePrivate(v8engine, value)); QJSValuePrivate *apiprivate = QJSValuePrivate::get(moduleApi->scriptApi); - if (apiprivate->propertyFlags(property) & QJSValue::ReadOnly) { + if (apiprivate->propertyFlags(property) & QJSValuePrivate::ReadOnly) { QString error = QLatin1String("Cannot assign to read-only property \"") + v8engine->toString(property) + QLatin1Char('\"'); v8::ThrowException(v8::Exception::Error(v8engine->toString(error))); |