OSDN Git Service

QmlJS: Also bind FunctionExpressions.
authorChristian Kamm <christian.d.kamm@nokia.com>
Tue, 16 Nov 2010 12:53:39 +0000 (13:53 +0100)
committerChristian Kamm <christian.d.kamm@nokia.com>
Tue, 16 Nov 2010 14:27:26 +0000 (15:27 +0100)
Reviewed-by: Erik Verbruggen
src/libs/qmljs/qmljsbind.cpp
src/libs/qmljs/qmljsbind.h
src/libs/qmljs/qmljsinterpreter.cpp
src/libs/qmljs/qmljsinterpreter.h

index 7657295..fda4b8c 100644 (file)
@@ -106,7 +106,7 @@ bool Bind::usesQmlPrototype(ObjectValue *prototype,
     return false;
 }
 
-Interpreter::ObjectValue *Bind::findFunctionScope(AST::FunctionDeclaration *node) const
+Interpreter::ObjectValue *Bind::findFunctionScope(AST::FunctionExpression *node) const
 {
     return _functionScopes.value(node);
 }
@@ -278,7 +278,7 @@ bool Bind::visit(UiScriptBinding *ast)
                     _idEnvironment->setProperty(i->name->asString(), _currentObjectValue);
     }
 
-    return false;
+    return true;
 }
 
 bool Bind::visit(UiArrayBinding *)
@@ -298,7 +298,7 @@ bool Bind::visit(VariableDeclaration *ast)
     return false;
 }
 
-bool Bind::visit(FunctionDeclaration *ast)
+bool Bind::visit(FunctionExpression *ast)
 {
     if (!ast->name)
         return false;
@@ -341,3 +341,8 @@ bool Bind::visit(FunctionDeclaration *ast)
 
     return false;
 }
+
+bool Bind::visit(FunctionDeclaration *ast)
+{
+    return visit(static_cast<FunctionExpression *>(ast));
+}
index b5e7796..0ca726e 100644 (file)
@@ -62,7 +62,7 @@ public:
     bool usesQmlPrototype(Interpreter::ObjectValue *prototype,
                           const Interpreter::Context *context) const;
 
-    Interpreter::ObjectValue *findFunctionScope(AST::FunctionDeclaration *node) const;
+    Interpreter::ObjectValue *findFunctionScope(AST::FunctionExpression *node) const;
     bool isGroupedPropertyBinding(AST::Node *node) const;
 
     static QString toString(AST::UiQualifiedId *qualifiedId, QChar delimiter = QChar('.'));
@@ -85,6 +85,7 @@ protected:
 
     // QML/JS
     virtual bool visit(AST::FunctionDeclaration *ast);
+    virtual bool visit(AST::FunctionExpression *ast);
     virtual bool visit(AST::VariableDeclaration *ast);
 
     Interpreter::ObjectValue *switchObjectValue(Interpreter::ObjectValue *newObjectValue);
@@ -102,7 +103,7 @@ private:
 
     QHash<AST::Node *, Interpreter::ObjectValue *> _qmlObjects;
     QSet<AST::Node *> _groupedPropertyBindings;
-    QHash<AST::FunctionDeclaration *, Interpreter::ObjectValue *> _functionScopes;
+    QHash<AST::FunctionExpression *, Interpreter::ObjectValue *> _functionScopes;
     QStringList _includedScripts;
 
     QList<Interpreter::ImportInfo> _imports;
index a715c69..c4767c3 100644 (file)
@@ -3309,7 +3309,7 @@ const Value *ASTVariableReference::value(const Context *context) const
     return check(_ast->expression);
 }
 
-ASTFunctionValue::ASTFunctionValue(FunctionDeclaration *ast, const QmlJS::Document *doc, Engine *engine)
+ASTFunctionValue::ASTFunctionValue(FunctionExpression *ast, const QmlJS::Document *doc, Engine *engine)
     : FunctionValue(engine), _ast(ast), _doc(doc)
 {
     setPrototype(engine->functionPrototype());
@@ -3322,7 +3322,7 @@ ASTFunctionValue::~ASTFunctionValue()
 {
 }
 
-FunctionDeclaration *ASTFunctionValue::ast() const
+FunctionExpression *ASTFunctionValue::ast() const
 {
     return _ast;
 }
index 27f0d4f..482d9c7 100644 (file)
@@ -866,15 +866,15 @@ private:
 
 class QMLJS_EXPORT ASTFunctionValue: public FunctionValue
 {
-    AST::FunctionDeclaration *_ast;
+    AST::FunctionExpression *_ast;
     const Document *_doc;
     QList<NameId *> _argumentNames;
 
 public:
-    ASTFunctionValue(AST::FunctionDeclaration *ast, const Document *doc, Engine *engine);
+    ASTFunctionValue(AST::FunctionExpression *ast, const Document *doc, Engine *engine);
     virtual ~ASTFunctionValue();
 
-    AST::FunctionDeclaration *ast() const;
+    AST::FunctionExpression *ast() const;
 
     virtual const Value *returnValue() const;
     virtual int argumentCount() const;