Commit 05831a8e authored by Christian Kamm's avatar Christian Kamm
Browse files

QmlJS: Fix binding and scoping function expressions.

Reviewed-by: Erik Verbruggen
parent 5dd92328
......@@ -346,19 +346,18 @@ bool Bind::visit(VariableDeclaration *ast)
ASTVariableReference *ref = new ASTVariableReference(ast, &_engine);
_currentObjectValue->setProperty(ast->name->asString(), ref);
return false;
return true;
}
bool Bind::visit(FunctionExpression *ast)
{
if (!ast->name)
return false;
// ### FIXME: the first declaration counts
//if (_currentObjectValue->property(ast->name->asString(), 0))
// return false;
ASTFunctionValue *function = new ASTFunctionValue(ast, _doc, &_engine);
_currentObjectValue->setProperty(ast->name->asString(), function);
if (ast->name && cast<FunctionDeclaration *>(ast))
_currentObjectValue->setProperty(ast->name->asString(), function);
// build function scope
ObjectValue *functionScope = _engine.newObject(/*prototype=*/0);
......
......@@ -61,8 +61,8 @@ void ScopeBuilder::push(AST::Node *node)
if (qmlObject)
setQmlScopeObject(qmlObject);
// JS scopes
if (FunctionDeclaration *fun = cast<FunctionDeclaration *>(node)) {
// JS scopes (catch both, FunctionExpression and FunctionDeclaration)
if (FunctionExpression *fun = dynamic_cast<FunctionExpression *>(node)) {
ObjectValue *functionScope = _doc->bind()->findFunctionScope(fun);
if (functionScope)
_context->scopeChain().jsScopes += functionScope;
......@@ -83,8 +83,10 @@ void ScopeBuilder::pop()
_nodes.removeLast();
// JS scopes
if (cast<FunctionDeclaration *>(toRemove))
_context->scopeChain().jsScopes.removeLast();
if (FunctionExpression *fun = dynamic_cast<FunctionExpression *>(toRemove)) {
if (_doc->bind()->findFunctionScope(fun))
_context->scopeChain().jsScopes.removeLast();
}
// QML scope object
if (! _nodes.isEmpty()
......
......@@ -201,6 +201,11 @@ protected:
}
virtual bool visit(AST::FunctionDeclaration *node)
{
return visit(static_cast<FunctionExpression *>(node));
}
virtual bool visit(AST::FunctionExpression *node)
{
if (node->name && node->name->asString() == _name) {
if (checkLookup())
......@@ -328,6 +333,11 @@ protected:
}
virtual bool visit(AST::FunctionDeclaration *node)
{
return visit(static_cast<FunctionExpression *>(node));
}
virtual bool visit(AST::FunctionExpression *node)
{
Node::accept(node->formals, this);
_result.append(node);
......@@ -422,9 +432,12 @@ protected:
return true;
}
// ### Misses function declaration, var declaration
virtual bool visit(FunctionDeclaration *node)
{
return visit(static_cast<FunctionExpression *>(node));
}
virtual bool visit(FunctionExpression *node)
{
if (containsOffset(node->identifierToken)) {
_result.second = node->name->asString();
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment