Ignore:
Timestamp:
Jul 6, 2010, 6:55:34 AM (15 years ago)
Author:
[email protected]
Message:

2010-07-06 Jedrzej Nowacki <[email protected]>

Reviewed by Kenneth Rohde Christiansen.

Implementation of QScriptValue properties accessors.

The patch contains implementation of the QScriptValue::property() and
the QScriptValue::setProperty(). It is not full functionality, as these
method are too complex for one patch, but it is enough to cover about
95% of use cases.

Missing functionality:

  • Few of the PropertyFlags are ignored.
  • Only a public part of the ResolveFlags can be used (ResolveLocal, ResolvePrototype).

A lot of new test cases were added.

[Qt] QScriptValue should have API for accessing object properties
https://bugs.webkit.org/show_bug.cgi?id=40903

  • api/qscriptconverter_p.h: (QScriptConverter::toPropertyFlags):
  • api/qscriptstring_p.h: (QScriptStringPrivate::operator JSStringRef):
  • api/qscriptvalue.cpp: (QScriptValue::property): (QScriptValue::setProperty):
  • api/qscriptvalue.h: (QScriptValue::):
  • api/qscriptvalue_p.h: (QScriptValuePrivate::assignEngine): (QScriptValuePrivate::property): (QScriptValuePrivate::hasOwnProperty): (QScriptValuePrivate::setProperty): (QScriptValuePrivate::deleteProperty):
  • tests/qscriptvalue/tst_qscriptvalue.cpp: (tst_QScriptValue::getPropertySimple_data): (tst_QScriptValue::getPropertySimple): (tst_QScriptValue::setPropertySimple): (tst_QScriptValue::getPropertyResolveFlag): (tst_QScriptValue::getSetProperty): (tst_QScriptValue::setProperty_data): (tst_QScriptValue::setProperty):
  • tests/qscriptvalue/tst_qscriptvalue.h:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/JavaScriptCore/qt/api/qscriptvalue.cpp

    r62007 r62547  
    652652  \overload
    653653
     654  Returns the value of this QScriptValue's property with the given \a name,
     655  using the given \a mode to resolve the property.
     656
     657  This overload of property() is useful when you need to look up the
     658  same property repeatedly, since the lookup can be performed faster
     659  when the name is represented as an interned string.
     660
     661  \sa QScriptEngine::toStringHandle(), setProperty()
     662*/
     663QScriptValue QScriptValue::property(const QScriptString& name, const ResolveFlags& mode) const
     664{
     665    return QScriptValuePrivate::get(d_ptr->property(QScriptStringPrivate::get(name).constData(), mode));
     666}
     667
     668/*!
     669  \overload
     670
    654671  Returns the property at the given \a arrayIndex, using the given \a
    655672  mode to resolve the property.
     
    666683    return QScriptValuePrivate::get(d_ptr->property(arrayIndex, mode));
    667684}
     685
     686/*!
     687  Sets the value of this QScriptValue's property with the given \a name to
     688  the given \a value.
     689
     690  If this QScriptValue is not an object, this function does nothing.
     691
     692  If this QScriptValue does not already have a property with name \a name,
     693  a new property is created; the given \a flags then specify how this
     694  property may be accessed by script code.
     695
     696  If \a value is invalid, the property is removed.
     697
     698  If the property is implemented using a setter function (i.e. has the
     699  PropertySetter flag set), calling setProperty() has side-effects on
     700  the script engine, since the setter function will be called with the
     701  given \a value as argument (possibly resulting in an uncaught script
     702  exception).
     703
     704  Note that you cannot specify custom getter or setter functions for
     705  built-in properties, such as the \c{length} property of Array objects
     706  or meta properties of QObject objects.
     707
     708  \sa property()
     709*/
     710void QScriptValue::setProperty(const QString& name, const QScriptValue& value, const PropertyFlags& flags)
     711{
     712    d_ptr->setProperty(name, QScriptValuePrivate::get(value), flags);
     713}
     714
     715/*!
     716  \overload
     717
     718  Sets the property at the given \a arrayIndex to the given \a value.
     719
     720  This function is provided for convenience and performance when
     721  working with array objects.
     722
     723  If this QScriptValue is not an Array object, this function behaves
     724  as if setProperty() was called with the string representation of \a
     725  arrayIndex.
     726*/
     727void QScriptValue::setProperty(quint32 arrayIndex, const QScriptValue& value, const PropertyFlags& flags)
     728{
     729    d_ptr->setProperty(arrayIndex, QScriptValuePrivate::get(value), flags);
     730}
     731
     732/*!
     733  Sets the value of this QScriptValue's property with the given \a
     734  name to the given \a value. The given \a flags specify how this
     735  property may be accessed by script code.
     736
     737  This overload of setProperty() is useful when you need to set the
     738  same property repeatedly, since the operation can be performed
     739  faster when the name is represented as an interned string.
     740
     741  \sa QScriptEngine::toStringHandle()
     742*/
     743void QScriptValue::setProperty(const QScriptString& name, const QScriptValue& value, const PropertyFlags& flags)
     744{
     745    d_ptr->setProperty(QScriptStringPrivate::get(name).constData(), QScriptValuePrivate::get(value), flags);
     746}
Note: See TracChangeset for help on using the changeset viewer.