OSDN Git Service

QmlJS checks: Add warning about 'eval'.
authorChristian Kamm <christian.d.kamm@nokia.com>
Fri, 30 Sep 2011 09:15:15 +0000 (11:15 +0200)
committerChristian Kamm <christian.d.kamm@nokia.com>
Mon, 10 Oct 2011 12:40:10 +0000 (14:40 +0200)
Migrated from QtChecker.

Change-Id: I4b3e8993c7b9f697497d2199b24bf49379dbc1b4
Reviewed-on: http://codereview.qt-project.org/5860
Sanity-Review: Qt Sanity Bot <qt_sanity_bot@ovi.com>
Reviewed-by: Fawzi Mohamed <fawzi.mohamed@nokia.com>
src/libs/qmljs/qmljscheck.cpp
tests/auto/qml/codemodel/check/avoid-eval.qml [new file with mode: 0644]

index 3c56387..da9c5cf 100644 (file)
@@ -1160,6 +1160,8 @@ bool Check::visit(CallExpression *ast)
     if (!name.isEmpty() && name.at(0).isUpper()) {
         addMessage(WarnExpectedNewWithUppercaseFunction, location);
     }
+    if (cast<IdentifierExpression *>(ast->base) && name == QLatin1String("eval"))
+        addMessage(WarnEval, location);
     return true;
 }
 
diff --git a/tests/auto/qml/codemodel/check/avoid-eval.qml b/tests/auto/qml/codemodel/check/avoid-eval.qml
new file mode 100644 (file)
index 0000000..6155d50
--- /dev/null
@@ -0,0 +1,9 @@
+import QtQuick 1.0
+
+Item {
+    function foo() {
+        eval("a + b") // 23 9 12
+        var a = { eval: function (string) { return string; } }
+        a.eval("a + b")
+    }
+}