diff options
author | Jedrzej Nowacki <jedrzej.nowacki@nokia.com> | 2009-07-10 15:09:58 (GMT) |
---|---|---|
committer | Jedrzej Nowacki <jedrzej.nowacki@nokia.com> | 2009-07-13 08:10:14 (GMT) |
commit | f6304c909b074a951dc33c39bc2b9d75536b1c22 (patch) | |
tree | 523e04ca570f4ad6cfa1da64b55c5b7232de576f /src/script/api | |
parent | f3355474c05a29c05deb3de989387213de2485f0 (diff) | |
download | Qt-f6304c909b074a951dc33c39bc2b9d75536b1c22.zip Qt-f6304c909b074a951dc33c39bc2b9d75536b1c22.tar.gz Qt-f6304c909b074a951dc33c39bc2b9d75536b1c22.tar.bz2 |
fix checkSyntax autotest.
Diffstat (limited to 'src/script/api')
-rw-r--r-- | src/script/api/qscriptengine.cpp | 55 | ||||
-rw-r--r-- | src/script/api/qscriptengine.h | 1 | ||||
-rw-r--r-- | src/script/api/qscriptengine_p.h | 3 |
3 files changed, 42 insertions, 17 deletions
diff --git a/src/script/api/qscriptengine.cpp b/src/script/api/qscriptengine.cpp index b64844e..97a1c61 100644 --- a/src/script/api/qscriptengine.cpp +++ b/src/script/api/qscriptengine.cpp @@ -282,6 +282,19 @@ QT_BEGIN_NAMESPACE \value SkipMethodsInEnumeration Don't include methods (signals and slots) when enumerating the object's properties. */ +class QScriptSyntaxCheckResultPrivate +{ +public: + QScriptSyntaxCheckResultPrivate() { ref = 0; } + ~QScriptSyntaxCheckResultPrivate() {} + + QScriptSyntaxCheckResult::State state; + int errorColumnNumber; + int errorLineNumber; + QString errorMessage; + QBasicAtomicInt ref; +}; + class QScriptTypeInfo { public: @@ -1961,12 +1974,33 @@ bool QScriptEnginePrivate::canEvaluate(const QString &program) */ QScriptSyntaxCheckResult QScriptEngine::checkSyntax(const QString &program) { - qWarning("QScriptEngine::checkSyntax() not implemented"); - // use our own parser or JSC::Interpreter::checkSyntax() - Q_UNUSED(program); - return QScriptSyntaxCheckResult(); + return QScriptEnginePrivate::checkSyntax(program); +} + +QScriptSyntaxCheckResult QScriptEnginePrivate::checkSyntax(const QString &program) +{ + QScript::SyntaxChecker checker; + QScript::SyntaxChecker::Result result = checker.checkSyntax(program); + QScriptSyntaxCheckResultPrivate *p = new QScriptSyntaxCheckResultPrivate(); + switch (result.state) { + case QScript::SyntaxChecker::Error: + p->state = QScriptSyntaxCheckResult::Error; + break; + case QScript::SyntaxChecker::Intermediate: + p->state = QScriptSyntaxCheckResult::Intermediate; + break; + case QScript::SyntaxChecker::Valid: + p->state = QScriptSyntaxCheckResult::Valid; + break; + } + p->errorLineNumber = result.errorLineNumber; + p->errorColumnNumber = result.errorColumnNumber; + p->errorMessage = result.errorMessage; + return QScriptSyntaxCheckResult(p); } + + /*! Evaluates \a program, using \a lineNumber as the base line number, and returns the result of the evaluation. @@ -3444,19 +3478,6 @@ QScriptValue QScriptEngine::objectById(qint64 id) const \value Valid The program is a syntactically correct Qt Script program. */ -class QScriptSyntaxCheckResultPrivate -{ -public: - QScriptSyntaxCheckResultPrivate() { ref = 0; } - ~QScriptSyntaxCheckResultPrivate() {} - - QScriptSyntaxCheckResult::State state; - int errorColumnNumber; - int errorLineNumber; - QString errorMessage; - QBasicAtomicInt ref; -}; - /*! Constructs a new QScriptSyntaxCheckResult from the \a other result. */ diff --git a/src/script/api/qscriptengine.h b/src/script/api/qscriptengine.h index 3b6ed33..da443c0 100644 --- a/src/script/api/qscriptengine.h +++ b/src/script/api/qscriptengine.h @@ -118,6 +118,7 @@ private: Q_DECLARE_PRIVATE(QScriptSyntaxCheckResult) friend class QScriptEngine; + friend class QScriptEnginePrivate; }; class Q_SCRIPT_EXPORT QScriptEngine diff --git a/src/script/api/qscriptengine_p.h b/src/script/api/qscriptengine_p.h index 6062e76..545a8c8 100644 --- a/src/script/api/qscriptengine_p.h +++ b/src/script/api/qscriptengine_p.h @@ -64,6 +64,8 @@ class QScriptValuePrivate; class QScriptTypeInfo; class QScriptEngineAgent; +class QScriptSyntaxCheckResult; + class QScriptEngine; class QScriptEnginePrivate #ifndef QT_NO_QOBJECT @@ -116,6 +118,7 @@ public: JSC::JSValue newQMetaObject(const QMetaObject *metaObject, JSC::JSValue ctor); + static QScriptSyntaxCheckResult checkSyntax(const QString &program); static bool canEvaluate(const QString &program); static bool convertToNativeQObject(const QScriptValue &value, const QByteArray &targetType, |