diff options
author | Jedrzej Nowacki <jedrzej.nowacki@nokia.com> | 2009-07-10 14:23:10 (GMT) |
---|---|---|
committer | Jedrzej Nowacki <jedrzej.nowacki@nokia.com> | 2009-07-13 08:10:06 (GMT) |
commit | f3355474c05a29c05deb3de989387213de2485f0 (patch) | |
tree | 5b03cb547487db6799a82860c0672507c6f42c2b | |
parent | 0579f4be2e79bb95c963a7e2368b6ee797c25e90 (diff) | |
download | Qt-f3355474c05a29c05deb3de989387213de2485f0.zip Qt-f3355474c05a29c05deb3de989387213de2485f0.tar.gz Qt-f3355474c05a29c05deb3de989387213de2485f0.tar.bz2 |
fix autotest canEvaluate.
-rw-r--r-- | src/script/api/qscriptengine.cpp | 84 | ||||
-rw-r--r-- | src/script/api/qscriptengine_p.h | 3 | ||||
-rw-r--r-- | src/script/parser/parser.pri | 15 | ||||
-rw-r--r-- | src/script/parser/qscriptlexer.cpp | 12 | ||||
-rw-r--r-- | tests/auto/qscriptengine/tst_qscriptengine.cpp | 1 |
5 files changed, 101 insertions, 14 deletions
diff --git a/src/script/api/qscriptengine.cpp b/src/script/api/qscriptengine.cpp index 74ec042..b64844e 100644 --- a/src/script/api/qscriptengine.cpp +++ b/src/script/api/qscriptengine.cpp @@ -10,6 +10,8 @@ ****************************************************************************/ #include "qscriptengine.h" +#include "qscriptsyntaxchecker_p.h" +#include "qnumeric.h" #ifndef QT_NO_SCRIPT @@ -294,6 +296,75 @@ public: namespace QScript { +static int toDigit(char c) +{ + if ((c >= '0') && (c <= '9')) + return c - '0'; + else if ((c >= 'a') && (c <= 'z')) + return 10 + c - 'a'; + else if ((c >= 'A') && (c <= 'Z')) + return 10 + c - 'A'; + return -1; +} + +qsreal integerFromString(const char *buf, int size, int radix) +{ + if (size == 0) + return qSNaN(); + + qsreal sign = 1.0; + int i = 0; + if (buf[0] == '+') { + ++i; + } else if (buf[0] == '-') { + sign = -1.0; + ++i; + } + + if (((size-i) >= 2) && (buf[i] == '0')) { + if (((buf[i+1] == 'x') || (buf[i+1] == 'X')) + && (radix < 34)) { + if ((radix != 0) && (radix != 16)) + return 0; + radix = 16; + i += 2; + } else { + if (radix == 0) { + radix = 8; + ++i; + } + } + } else if (radix == 0) { + radix = 10; + } + + int j = i; + for ( ; i < size; ++i) { + int d = toDigit(buf[i]); + if ((d == -1) || (d >= radix)) + break; + } + qsreal result; + if (j == i) { + if (!qstrcmp(buf, "Infinity")) + result = qInf(); + else + result = qSNaN(); + } else { + result = 0; + qsreal multiplier = 1; + for (--i ; i >= j; --i, multiplier *= radix) + result += toDigit(buf[i]) * multiplier; + } + result *= sign; + return result; +} + +qsreal integerFromString(const QString &str, int radix) +{ + QByteArray ba = str.trimmed().toUtf8(); + return integerFromString(ba.constData(), ba.size(), radix); +} JSC::UString qtStringToJSCUString(const QString &str) { @@ -1871,10 +1942,15 @@ QScriptValue QScriptEngine::newQMetaObject( */ bool QScriptEngine::canEvaluate(const QString &program) const { - qWarning("QScriptEngine::canEvaluate() not implemented"); - // ### use our own parser or JSC::Interpreter::checkSyntax() - Q_UNUSED(program); - return true; + return QScriptEnginePrivate::canEvaluate(program); +} + + +bool QScriptEnginePrivate::canEvaluate(const QString &program) +{ + QScript::SyntaxChecker checker; + QScript::SyntaxChecker::Result result = checker.checkSyntax(program); + return (result.state != QScript::SyntaxChecker::Intermediate); } /*! diff --git a/src/script/api/qscriptengine_p.h b/src/script/api/qscriptengine_p.h index c601922..6062e76 100644 --- a/src/script/api/qscriptengine_p.h +++ b/src/script/api/qscriptengine_p.h @@ -115,7 +115,8 @@ public: const QScriptEngine:: QObjectWrapOptions &options = 0); JSC::JSValue newQMetaObject(const QMetaObject *metaObject, JSC::JSValue ctor); - + + static bool canEvaluate(const QString &program); static bool convertToNativeQObject(const QScriptValue &value, const QByteArray &targetType, void **result); diff --git a/src/script/parser/parser.pri b/src/script/parser/parser.pri index 7f2e30a..4839ed2 100644 --- a/src/script/parser/parser.pri +++ b/src/script/parser/parser.pri @@ -2,15 +2,18 @@ SOURCES += \ $$PWD/qscriptast.cpp \ $$PWD/qscriptastvisitor.cpp \ $$PWD/qscriptgrammar.cpp \ -# $$PWD/qscriptlexer.cpp \ -# $$PWD/qscriptparser.cpp \ -# $$PWD/qscriptsyntaxchecker.cpp + $$PWD/qscriptsyntaxchecker.cpp \ + $$PWD/qscriptlexer.cpp \ + #$$PWD/qscriptparser.cpp HEADERS += \ $$PWD/qscriptastfwd_p.h \ $$PWD/qscriptast_p.h \ $$PWD/qscriptastvisitor_p.h \ $$PWD/qscriptgrammar_p.h \ -# $$PWD/qscriptlexer_p.h \ -# $$PWD/qscriptparser_p.h \ -# $$PWD/qscriptsyntaxchecker_p.h + $$PWD/qscriptsyntaxchecker_p.h \ + $$PWD/qscriptlexer_p.h \ + #$$PWD/qscriptparser_p.h + +INCLUDEPATH += \ + $$PWD diff --git a/src/script/parser/qscriptlexer.cpp b/src/script/parser/qscriptlexer.cpp index 5a0da36..04a3ac3 100644 --- a/src/script/parser/qscriptlexer.cpp +++ b/src/script/parser/qscriptlexer.cpp @@ -1074,8 +1074,16 @@ bool QScript::Lexer::scanRegExp(RegExpBodyPrefix prefix) flags = 0; while (isIdentLetter(current)) { - Q_ASSERT_X(false, Q_FUNC_INFO, "not implemented"); - int flag = 0; // QScript::Ecma::RegExp::flagFromChar(current); + // current version was remade from this line: + //int flag = QScript::Ecma::RegExp::flagFromChar(current); + //code was "inlined" because it was only one call to this function + int flag; + switch (current) { + case 'g': flag = 0x01; break; + case 'm': flag = 0x02; break; + case 'i': flag = 0x04; break; + default: flag = 0; + } if (flag == 0) { errmsg = QString::fromLatin1("Invalid regular expression flag '%0'") .arg(QChar(current)); diff --git a/tests/auto/qscriptengine/tst_qscriptengine.cpp b/tests/auto/qscriptengine/tst_qscriptengine.cpp index e29e834..8152732 100644 --- a/tests/auto/qscriptengine/tst_qscriptengine.cpp +++ b/tests/auto/qscriptengine/tst_qscriptengine.cpp @@ -1027,7 +1027,6 @@ void tst_QScriptEngine::canEvaluate_data() void tst_QScriptEngine::canEvaluate() { - QSKIP("Not implemented", SkipAll); QFETCH(QString, code); QFETCH(bool, expectSuccess); |