From e04fc16d0a3584c1d55544ca97dcf0e29dc546ee Mon Sep 17 00:00:00 2001 From: Kent Hansen Date: Thu, 25 Jun 2009 14:11:36 +0200 Subject: port some fixes from the "old" qtscript backend to the JSC backend Makes more tests pass. --- src/script/bridge/qscriptqobject.cpp | 52 +++++++++++++++++++++++++----------- 1 file changed, 37 insertions(+), 15 deletions(-) diff --git a/src/script/bridge/qscriptqobject.cpp b/src/script/bridge/qscriptqobject.cpp index 183c915..9e2347b 100644 --- a/src/script/bridge/qscriptqobject.cpp +++ b/src/script/bridge/qscriptqobject.cpp @@ -144,7 +144,7 @@ static int indexOfMetaEnum(const QMetaObject *meta, const QByteArray &str) { QByteArray scope; QByteArray name; - int scopeIdx = str.indexOf("::"); + int scopeIdx = str.lastIndexOf("::"); if (scopeIdx != -1) { scope = str.left(scopeIdx); name = str.mid(scopeIdx + 2); @@ -153,7 +153,7 @@ static int indexOfMetaEnum(const QMetaObject *meta, const QByteArray &str) } for (int i = meta->enumeratorCount() - 1; i >= 0; --i) { QMetaEnum m = meta->enumerator(i); - if ((m.name() == name)/* && (scope.isEmpty() || (m.scope() == scope))*/) + if ((m.name() == name) && (scope.isEmpty() || (m.scope() == scope))) return i; } return -1; @@ -305,6 +305,11 @@ public: inline int enumeratorIndex() const { Q_ASSERT(isMetaEnum()); return m_typeId; } + inline bool operator==(const QScriptMetaType &other) const + { + return (m_kind == other.m_kind) && (m_typeId == other.m_typeId); + } + static inline QScriptMetaType variant() { return QScriptMetaType(Variant); } @@ -388,6 +393,9 @@ public: inline QScriptMetaType type(int index) const { return m_types.at(index); } + inline QVector types() const + { return m_types; } + private: QByteArray m_name; QVector m_types; @@ -541,9 +549,8 @@ JSC::JSValue QtFunction::call(JSC::ExecState *exec, JSC::JSValue thisValue, tid = argType.typeId(); v = QVariant(tid, (void *)0); converted = QScriptEnginePrivate::convert(actual, tid, v.data(), engine); - // ### -// if (engine->hasUncaughtException()) -// return; + if (exec->hadException()) + return exec->exception(); } if (!converted) { @@ -726,17 +733,32 @@ JSC::JSValue QtFunction::call(JSC::ExecState *exec, JSC::JSValue thisValue, chosenIndex = index; break; } else { - QScriptMetaArguments metaArgs(matchDistance, index, mtd, args); - if (candidates.isEmpty()) { - candidates.append(metaArgs); - } else { - QScriptMetaArguments otherArgs = candidates.at(0); - if ((args.count() > otherArgs.args.count()) - || ((args.count() == otherArgs.args.count()) - && (matchDistance <= otherArgs.matchDistance))) { - candidates.prepend(metaArgs); - } else { + bool redundant = false; + if (/*(callType != QMetaMethod::Constructor) + &&*/ (index < meta->methodOffset())) { + // it is possible that a virtual method is redeclared in a subclass, + // in which case we want to ignore the superclass declaration + for (int i = 0; i < candidates.size(); ++i) { + const QScriptMetaArguments &other = candidates.at(i); + if (mtd.types() == other.method.types()) { + redundant = true; + break; + } + } + } + if (!redundant) { + QScriptMetaArguments metaArgs(matchDistance, index, mtd, args); + if (candidates.isEmpty()) { candidates.append(metaArgs); + } else { + const QScriptMetaArguments &otherArgs = candidates.at(0); + if ((args.count() > otherArgs.args.count()) + || ((args.count() == otherArgs.args.count()) + && (matchDistance <= otherArgs.matchDistance))) { + candidates.prepend(metaArgs); + } else { + candidates.append(metaArgs); + } } } } -- cgit v0.12