Changeset 62007 in webkit for trunk/JavaScriptCore
- Timestamp:
- Jun 28, 2010, 8:19:59 AM (15 years ago)
- Location:
- trunk/JavaScriptCore
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/JavaScriptCore/ChangeLog
r62001 r62007 1 2010-06-28 Caio Marcelo de Oliveira Filho <[email protected]> 2 3 Reviewed by Kenneth Rohde Christiansen. 4 5 [Qt] QScriptValue should have API for accessing object properties 6 https://bugs.webkit.org/show_bug.cgi?id=40903 7 8 Make possible to access properties inside QScriptValues. While this 9 still doesn't support the ResolveLocal parameter, it is already useful 10 for testing the API. 11 12 The tests from upstream QtScript weren't imported since most of them 13 depend on the setProperty() function as well. A simple test was created. 14 15 * qt/api/qscriptvalue.cpp: 16 (QScriptValue::property): 17 * qt/api/qscriptvalue.h: 18 (QScriptValue::): 19 * qt/api/qscriptvalue_p.h: 20 (QScriptValuePrivate::property): 21 * qt/tests/qscriptvalue/tst_qscriptvalue.cpp: 22 (tst_QScriptValue::propertySimple): 23 * qt/tests/qscriptvalue/tst_qscriptvalue.h: 24 1 25 2010-06-28 Xan Lopez <[email protected]> 2 26 -
trunk/JavaScriptCore/qt/api/qscriptvalue.cpp
r61860 r62007 628 628 return d_ptr->instanceOf(QScriptValuePrivate::get(other)); 629 629 } 630 631 /*! 632 Returns the value of this QScriptValue's property with the given \a name, 633 using the given \a mode to resolve the property. 634 635 If no such property exists, an invalid QScriptValue is returned. 636 637 If the property is implemented using a getter function (i.e. has the 638 PropertyGetter flag set), calling property() has side-effects on the 639 script engine, since the getter function will be called (possibly 640 resulting in an uncaught script exception). If an exception 641 occurred, property() returns the value that was thrown (typically 642 an \c{Error} object). 643 644 \sa setProperty(), propertyFlags(), QScriptValueIterator 645 */ 646 QScriptValue QScriptValue::property(const QString& name, const ResolveFlags& mode) const 647 { 648 return QScriptValuePrivate::get(d_ptr->property(name, mode)); 649 } 650 651 /*! 652 \overload 653 654 Returns the property at the given \a arrayIndex, using the given \a 655 mode to resolve the property. 656 657 This function is provided for convenience and performance when 658 working with array objects. 659 660 If this QScriptValue is not an Array object, this function behaves 661 as if property() was called with the string representation of \a 662 arrayIndex. 663 */ 664 QScriptValue QScriptValue::property(quint32 arrayIndex, const ResolveFlags& mode) const 665 { 666 return QScriptValuePrivate::get(d_ptr->property(arrayIndex, mode)); 667 } -
trunk/JavaScriptCore/qt/api/qscriptvalue.h
r61860 r62007 33 33 34 34 class QScriptValue { 35 public: 35 public: 36 enum ResolveFlag { 37 ResolveLocal = 0x00, 38 ResolvePrototype = 0x01 39 }; 40 41 Q_DECLARE_FLAGS(ResolveFlags, ResolveFlag) 42 36 43 enum SpecialValue { 37 44 NullValue, … … 67 74 bool strictlyEquals(const QScriptValue& other) const; 68 75 bool instanceOf(const QScriptValue& other) const; 76 77 QScriptValue property(const QString& name, const ResolveFlags& mode = ResolvePrototype) const; 78 QScriptValue property(quint32 arrayIndex, const ResolveFlags& mode = ResolvePrototype) const; 69 79 70 80 QScriptEngine* engine() const; -
trunk/JavaScriptCore/qt/api/qscriptvalue_p.h
r61860 r62007 120 120 inline bool instanceOf(QScriptValuePrivate* other); 121 121 inline bool assignEngine(QScriptEnginePrivate* engine); 122 123 inline QScriptValuePrivate* property(const QString& name, const QScriptValue::ResolveFlags& mode); 124 inline QScriptValuePrivate* property(quint32 arrayIndex, const QScriptValue::ResolveFlags& mode); 122 125 123 126 inline QScriptValuePrivate* call(const QScriptValuePrivate* , const QScriptValueList& args); … … 757 760 } 758 761 762 inline QScriptValuePrivate* QScriptValuePrivate::property(const QString& name, const QScriptValue::ResolveFlags& mode) 763 { 764 if (!isObject()) 765 return new QScriptValuePrivate; 766 767 if (mode & QScriptValue::ResolveLocal) { 768 qWarning("QScriptValue::property(): ResolveLocal not supported yet."); 769 return new QScriptValuePrivate; 770 } 771 772 JSRetainPtr<JSStringRef> nameRef(Adopt, QScriptConverter::toString(name)); 773 QScriptValuePrivate* result = new QScriptValuePrivate(m_engine.constData(), JSObjectGetProperty(*m_engine, *this, nameRef.get(), /* exception */ 0)); 774 775 return result; 776 } 777 778 inline QScriptValuePrivate* QScriptValuePrivate::property(quint32 arrayIndex, const QScriptValue::ResolveFlags& mode) 779 { 780 if (!isObject()) 781 return new QScriptValuePrivate; 782 783 if (mode & QScriptValue::ResolveLocal) { 784 qWarning("QScriptValue::property(): ResolveLocal not supported yet."); 785 return new QScriptValuePrivate; 786 } 787 788 return new QScriptValuePrivate(m_engine.constData(), JSObjectGetPropertyAtIndex(*m_engine, *this, arrayIndex, /* exception */ 0)); 789 } 790 759 791 QScriptValuePrivate* QScriptValuePrivate::call(const QScriptValuePrivate*, const QScriptValueList& args) 760 792 { -
trunk/JavaScriptCore/qt/tests/qscriptvalue/tst_qscriptvalue.cpp
r61860 r62007 581 581 } 582 582 583 void tst_QScriptValue::propertySimple() 584 { 585 QScriptEngine eng; 586 587 QScriptValue simpleObject(eng.evaluate("new Object({ test: 1, other: 2 })")); 588 QCOMPARE(simpleObject.property("test").toUInt32(), quint32(1)); 589 QCOMPARE(simpleObject.property("other").toUInt32(), quint32(2)); 590 591 QScriptValue simpleArray(eng.evaluate("new Array(7, 8, 9)")); 592 QCOMPARE(simpleArray.property("length").toUInt32(), quint32(3)); 593 QCOMPARE(simpleArray.property(2).toUInt32(), quint32(9)); 594 } 595 583 596 QTEST_MAIN(tst_QScriptValue) -
trunk/JavaScriptCore/qt/tests/qscriptvalue/tst_qscriptvalue.h
r61860 r62007 52 52 void ctor(); 53 53 void toObjectSimple(); 54 void propertySimple(); 54 55 55 56 // Generated test functions.
Note:
See TracChangeset
for help on using the changeset viewer.