Changeset 60725 in webkit
- Timestamp:
- Jun 4, 2010 5:23:07 PM (14 years ago)
- Location:
- trunk/JavaScriptCore
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/JavaScriptCore/ChangeLog
r60720 r60725 1 2010-06-04 Jedrzej Nowacki <jedrzej.nowacki@nokia.com> 2 3 Reviewed by Kenneth Rohde Christiansen. 4 5 New QtScript API; QScriptValue::instanceOf. 6 7 New function create an easy way to check value's prototype hierarchy. 8 9 [Qt] QScriptValue should have an instanceOf method 10 https://bugs.webkit.org/show_bug.cgi?id=40120 11 12 * qt/api/qscriptvalue.cpp: 13 (QScriptValue::instanceOf): 14 * qt/api/qscriptvalue.h: 15 * qt/api/qscriptvalue_p.h: 16 (QScriptValuePrivate::instanceOf): 17 * qt/tests/qscriptvalue/tst_qscriptvalue.h: 18 * qt/tests/qscriptvalue/tst_qscriptvalue_generated_comparison.cpp: 19 (tst_QScriptValue::instanceOf_initData): 20 (tst_QScriptValue::instanceOf_makeData): 21 (tst_QScriptValue::instanceOf_test): 22 1 23 2010-06-04 Gavin Barraclough <barraclough@apple.com> 2 24 -
trunk/JavaScriptCore/qt/api/qscriptvalue.cpp
r60661 r60725 586 586 return d_ptr->strictlyEquals(QScriptValuePrivate::get(other)); 587 587 } 588 589 /*! 590 Returns true if this QScriptValue is an instance of 591 \a other; otherwise returns false. 592 593 This QScriptValue is considered to be an instance of \a other if 594 \a other is a function and the value of the \c{prototype} 595 property of \a other is in the prototype chain of this 596 QScriptValue. 597 */ 598 bool QScriptValue::instanceOf(const QScriptValue& other) const 599 { 600 return d_ptr->instanceOf(QScriptValuePrivate::get(other)); 601 } -
trunk/JavaScriptCore/qt/api/qscriptvalue.h
r59503 r60725 62 62 bool equals(const QScriptValue& other) const; 63 63 bool strictlyEquals(const QScriptValue& other) const; 64 bool instanceOf(const QScriptValue& other) const; 64 65 65 66 QScriptEngine* engine() const; -
trunk/JavaScriptCore/qt/api/qscriptvalue_p.h
r60661 r60725 110 110 inline bool equals(QScriptValuePrivate* other); 111 111 inline bool strictlyEquals(QScriptValuePrivate* other); 112 inline bool instanceOf(QScriptValuePrivate* other); 112 113 inline bool assignEngine(QScriptEnginePrivate* engine); 113 114 … … 671 672 } 672 673 674 inline bool QScriptValuePrivate::instanceOf(QScriptValuePrivate* other) 675 { 676 if (!isJSBased() || !other->isObject()) 677 return false; 678 return JSValueIsInstanceOfConstructor(context(), value(), other->object(), /* exception */ 0); 679 } 680 673 681 /*! 674 682 Tries to assign \a engine to this value. Returns true on success; otherwise returns false. -
trunk/JavaScriptCore/qt/tests/qscriptvalue/tst_qscriptvalue.h
r60661 r60725 110 110 void strictlyEquals(); 111 111 112 void instanceOf_data(); 113 void instanceOf(); 114 112 115 private: 113 116 typedef void (tst_QScriptValue::*InitDataFunction)(); … … 199 202 void strictlyEquals_test(const char*, const QScriptValue&); 200 203 204 void instanceOf_initData(); 205 void instanceOf_makeData(const char*); 206 void instanceOf_test(const char*, const QScriptValue&); 207 201 208 private: 202 209 QScriptEngine* engine; -
trunk/JavaScriptCore/qt/tests/qscriptvalue/tst_qscriptvalue_generated_comparison.cpp
r60661 r60725 1678 1678 1679 1679 DEFINE_TEST_FUNCTION(strictlyEquals) 1680 1681 1682 void tst_QScriptValue::instanceOf_initData() 1683 { 1684 QTest::addColumn<QScriptValue>("other"); 1685 QTest::addColumn<bool>("expected"); 1686 initScriptValues(); 1687 } 1688 1689 static QString instanceOf_array[] = { 1690 "engine->evaluate(\"[]\") <=> engine->evaluate(\"Object\")", 1691 "engine->evaluate(\"[]\") <=> engine->evaluate(\"Array\")", 1692 "engine->evaluate(\"Date.prototype\") <=> engine->evaluate(\"Object\")", 1693 "engine->evaluate(\"Array.prototype\") <=> engine->evaluate(\"Object\")", 1694 "engine->evaluate(\"Function.prototype\") <=> engine->evaluate(\"Object\")", 1695 "engine->evaluate(\"Error.prototype\") <=> engine->evaluate(\"Object\")", 1696 "engine->evaluate(\"Object\") <=> engine->evaluate(\"Object\")", 1697 "engine->evaluate(\"Object\") <=> engine->evaluate(\"Function\")", 1698 "engine->evaluate(\"Array\") <=> engine->evaluate(\"Object\")", 1699 "engine->evaluate(\"Array\") <=> engine->evaluate(\"Function\")", 1700 "engine->evaluate(\"Number\") <=> engine->evaluate(\"Object\")", 1701 "engine->evaluate(\"Number\") <=> engine->evaluate(\"Function\")", 1702 "engine->evaluate(\"Function\") <=> engine->evaluate(\"Object\")", 1703 "engine->evaluate(\"Function\") <=> engine->evaluate(\"Function\")", 1704 "engine->evaluate(\"(function() { return 1; })\") <=> engine->evaluate(\"Object\")", 1705 "engine->evaluate(\"(function() { return 1; })\") <=> engine->evaluate(\"Function\")", 1706 "engine->evaluate(\"(function() { return 'ciao'; })\") <=> engine->evaluate(\"Object\")", 1707 "engine->evaluate(\"(function() { return 'ciao'; })\") <=> engine->evaluate(\"Function\")", 1708 "engine->evaluate(\"(function() { throw new Error('foo' })\") <=> engine->evaluate(\"Object\")", 1709 "engine->evaluate(\"/foo/\") <=> engine->evaluate(\"Object\")", 1710 "engine->evaluate(\"new Object()\") <=> engine->evaluate(\"Object\")", 1711 "engine->evaluate(\"new Array()\") <=> engine->evaluate(\"Object\")", 1712 "engine->evaluate(\"new Array()\") <=> engine->evaluate(\"Array\")", 1713 "engine->evaluate(\"new Error()\") <=> engine->evaluate(\"Object\")", 1714 "engine->evaluate(\"a = new Object( a.foo = 22; a.foo\") <=> engine->evaluate(\"Object\")", 1715 "engine->evaluate(\"Undefined\") <=> engine->evaluate(\"Object\")", 1716 "engine->evaluate(\"Null\") <=> engine->evaluate(\"Object\")", 1717 "engine->evaluate(\"True\") <=> engine->evaluate(\"Object\")", 1718 "engine->evaluate(\"False\") <=> engine->evaluate(\"Object\")"}; 1719 1720 void tst_QScriptValue::instanceOf_makeData(const char *expr) 1721 { 1722 static QSet<QString> equals; 1723 if (equals.isEmpty()) { 1724 equals.reserve(29); 1725 for (unsigned i = 0; i < 29; ++i) 1726 equals.insert(instanceOf_array[i]); 1727 } 1728 QHash<QString, QScriptValue>::const_iterator it; 1729 for (it = m_values.constBegin(); it != m_values.constEnd(); ++it) { 1730 QString tag = QString::fromLatin1("%20 <=> %21").arg(expr).arg(it.key()); 1731 newRow(tag.toLatin1()) << it.value() << equals.contains(tag); 1732 } 1733 } 1734 1735 void tst_QScriptValue::instanceOf_test(const char *, const QScriptValue& value) 1736 { 1737 QFETCH(QScriptValue, other); 1738 QFETCH(bool, expected); 1739 QCOMPARE(value.instanceOf(other), expected); 1740 } 1741 1742 DEFINE_TEST_FUNCTION(instanceOf)
Note: See TracChangeset
for help on using the changeset viewer.