2012-10-02 09:12:39 +02:00
|
|
|
/****************************************************************************
|
2010-01-18 16:15:23 +01:00
|
|
|
**
|
2016-01-15 14:58:39 +01:00
|
|
|
** Copyright (C) 2016 The Qt Company Ltd.
|
|
|
|
** Contact: https://www.qt.io/licensing/
|
2010-01-18 16:15:23 +01:00
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
** This file is part of Qt Creator.
|
2010-01-18 16:15:23 +01:00
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
** Commercial License Usage
|
|
|
|
** Licensees holding valid commercial Qt licenses may use this file in
|
|
|
|
** accordance with the commercial license agreement provided with the
|
|
|
|
** Software or, alternatively, in accordance with the terms contained in
|
2016-01-15 14:58:39 +01:00
|
|
|
** a written agreement between you and The Qt Company. For licensing terms
|
|
|
|
** and conditions see https://www.qt.io/terms-conditions. For further
|
|
|
|
** information use the contact form at https://www.qt.io/contact-us.
|
2010-01-18 16:15:23 +01:00
|
|
|
**
|
2016-01-15 14:58:39 +01:00
|
|
|
** GNU General Public License Usage
|
|
|
|
** Alternatively, this file may be used under the terms of the GNU
|
|
|
|
** General Public License version 3 as published by the Free Software
|
|
|
|
** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
|
|
|
|
** included in the packaging of this file. Please review the following
|
|
|
|
** information to ensure the GNU General Public License requirements will
|
|
|
|
** be met: https://www.gnu.org/licenses/gpl-3.0.html.
|
2010-12-17 16:01:08 +01:00
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
****************************************************************************/
|
2010-01-18 16:15:23 +01:00
|
|
|
|
2010-01-26 14:50:52 +01:00
|
|
|
#include "qmljsbind.h"
|
2013-03-12 12:09:22 +01:00
|
|
|
#include "parser/qmljsast_p.h"
|
2011-10-07 14:04:06 +02:00
|
|
|
#include "qmljsutils.h"
|
2010-02-03 15:59:15 +01:00
|
|
|
#include "qmljsdocument.h"
|
2012-12-06 17:20:58 +01:00
|
|
|
#include "qmljsmodelmanagerinterface.h"
|
2010-02-01 17:04:31 +01:00
|
|
|
|
2018-06-20 11:32:47 +02:00
|
|
|
#include <utils/algorithm.h>
|
|
|
|
|
2010-12-03 11:17:25 +01:00
|
|
|
using namespace LanguageUtils;
|
2010-01-18 16:15:23 +01:00
|
|
|
using namespace QmlJS;
|
2010-01-26 14:50:52 +01:00
|
|
|
using namespace QmlJS::AST;
|
2010-01-18 16:15:23 +01:00
|
|
|
|
2010-09-15 15:25:59 +02:00
|
|
|
/*!
|
|
|
|
\class QmlJS::Bind
|
2013-06-05 14:29:24 +02:00
|
|
|
\brief The Bind class collects information about a single Document.
|
2011-11-09 16:02:59 +01:00
|
|
|
\sa Document Context
|
2010-09-15 15:25:59 +02:00
|
|
|
|
2011-11-09 16:02:59 +01:00
|
|
|
Each Document owns an instance of Bind. It provides access to data
|
2010-09-15 15:25:59 +02:00
|
|
|
that can be derived by looking at the document in isolation. If you need
|
2011-11-09 16:02:59 +01:00
|
|
|
information that goes beyond that, you need to use a Context.
|
2010-09-15 15:25:59 +02:00
|
|
|
|
2010-09-16 09:40:19 +02:00
|
|
|
The document's imports are classified and available through imports().
|
2010-09-15 15:25:59 +02:00
|
|
|
|
2011-11-01 14:01:07 +01:00
|
|
|
This class makes the structural information found in the AST available
|
2011-11-09 16:02:59 +01:00
|
|
|
for analysis through Value instances. See findQmlObject(),
|
2011-11-01 14:01:07 +01:00
|
|
|
idEnvironment(), rootObjectValue() and findAttachedJSScope().
|
2010-09-15 15:25:59 +02:00
|
|
|
*/
|
|
|
|
|
2011-09-27 15:12:22 +02:00
|
|
|
Bind::Bind(Document *doc, QList<DiagnosticMessage> *messages, bool isJsLibrary, const QList<ImportInfo> &jsImports)
|
2010-01-26 16:21:03 +01:00
|
|
|
: _doc(doc),
|
2010-01-26 15:51:31 +01:00
|
|
|
_currentObjectValue(0),
|
|
|
|
_idEnvironment(0),
|
2010-09-16 15:29:37 +02:00
|
|
|
_rootObjectValue(0),
|
2011-09-27 15:12:22 +02:00
|
|
|
_isJsLibrary(isJsLibrary),
|
|
|
|
_imports(jsImports),
|
2010-09-16 15:29:37 +02:00
|
|
|
_diagnosticMessages(messages)
|
2010-01-18 16:15:23 +01:00
|
|
|
{
|
2010-02-03 14:31:03 +01:00
|
|
|
if (_doc)
|
|
|
|
accept(_doc->ast());
|
2010-01-18 16:15:23 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
Bind::~Bind()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2011-09-27 15:12:22 +02:00
|
|
|
bool Bind::isJsLibrary() const
|
|
|
|
{
|
|
|
|
return _isJsLibrary;
|
|
|
|
}
|
|
|
|
|
2010-09-16 15:29:37 +02:00
|
|
|
QList<ImportInfo> Bind::imports() const
|
2010-02-01 17:20:46 +01:00
|
|
|
{
|
2010-09-16 09:40:19 +02:00
|
|
|
return _imports;
|
2010-04-06 09:52:29 +02:00
|
|
|
}
|
|
|
|
|
2011-08-08 12:47:49 +02:00
|
|
|
ObjectValue *Bind::idEnvironment() const
|
2010-02-10 17:05:45 +01:00
|
|
|
{
|
|
|
|
return _idEnvironment;
|
|
|
|
}
|
|
|
|
|
2011-08-08 12:47:49 +02:00
|
|
|
ObjectValue *Bind::rootObjectValue() const
|
2010-02-10 17:05:45 +01:00
|
|
|
{
|
|
|
|
return _rootObjectValue;
|
|
|
|
}
|
|
|
|
|
2011-08-08 12:47:49 +02:00
|
|
|
ObjectValue *Bind::findQmlObject(AST::Node *node) const
|
2010-02-10 17:05:45 +01:00
|
|
|
{
|
|
|
|
return _qmlObjects.value(node);
|
|
|
|
}
|
|
|
|
|
2010-02-11 18:58:17 +01:00
|
|
|
bool Bind::usesQmlPrototype(ObjectValue *prototype,
|
2011-07-13 15:04:27 +02:00
|
|
|
const ContextPtr &context) const
|
2010-02-11 18:58:17 +01:00
|
|
|
{
|
2010-11-23 12:57:48 +01:00
|
|
|
if (!prototype)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
const QString componentName = prototype->className();
|
|
|
|
|
|
|
|
// all component objects have classname set
|
|
|
|
if (componentName.isEmpty())
|
|
|
|
return false;
|
|
|
|
|
2011-09-13 10:09:14 +02:00
|
|
|
foreach (const ObjectValue *object, _qmlObjectsByPrototypeName.values(componentName)) {
|
2010-11-23 12:57:48 +01:00
|
|
|
// resolve and check the prototype
|
2010-02-11 18:58:17 +01:00
|
|
|
const ObjectValue *resolvedPrototype = object->prototype(context);
|
|
|
|
if (resolvedPrototype == prototype)
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2011-08-08 12:47:49 +02:00
|
|
|
ObjectValue *Bind::findAttachedJSScope(AST::Node *node) const
|
2010-04-20 15:19:37 +02:00
|
|
|
{
|
2011-06-06 14:13:50 +02:00
|
|
|
return _attachedJSScopes.value(node);
|
2010-04-20 15:19:37 +02:00
|
|
|
}
|
|
|
|
|
2010-05-12 13:58:23 +02:00
|
|
|
bool Bind::isGroupedPropertyBinding(AST::Node *node) const
|
|
|
|
{
|
|
|
|
return _groupedPropertyBindings.contains(node);
|
|
|
|
}
|
|
|
|
|
2010-02-01 12:26:40 +01:00
|
|
|
ObjectValue *Bind::switchObjectValue(ObjectValue *newObjectValue)
|
2010-01-18 16:15:23 +01:00
|
|
|
{
|
2010-02-01 12:26:40 +01:00
|
|
|
ObjectValue *oldObjectValue = _currentObjectValue;
|
|
|
|
_currentObjectValue = newObjectValue;
|
|
|
|
return oldObjectValue;
|
2010-01-28 14:53:53 +01:00
|
|
|
}
|
2010-01-26 14:50:52 +01:00
|
|
|
|
2010-02-01 12:26:40 +01:00
|
|
|
ObjectValue *Bind::bindObject(UiQualifiedId *qualifiedTypeNameId, UiObjectInitializer *initializer)
|
2010-01-18 16:15:23 +01:00
|
|
|
{
|
2010-02-01 17:04:31 +01:00
|
|
|
ObjectValue *parentObjectValue = 0;
|
2010-01-18 16:15:23 +01:00
|
|
|
|
2010-02-01 17:04:31 +01:00
|
|
|
// normal component instance
|
2011-07-01 12:11:02 +02:00
|
|
|
ASTObjectValue *objectValue = new ASTObjectValue(qualifiedTypeNameId, initializer, _doc, &_valueOwner);
|
2010-02-04 09:44:43 +01:00
|
|
|
QmlPrototypeReference *prototypeReference =
|
2011-07-01 12:11:02 +02:00
|
|
|
new QmlPrototypeReference(qualifiedTypeNameId, _doc, &_valueOwner);
|
2010-02-03 15:39:57 +01:00
|
|
|
objectValue->setPrototype(prototypeReference);
|
|
|
|
|
2011-09-13 10:09:14 +02:00
|
|
|
// add the prototype name to the prototypes hash
|
|
|
|
for (UiQualifiedId *it = qualifiedTypeNameId; it; it = it->next) {
|
|
|
|
if (!it->next && !it->name.isEmpty())
|
|
|
|
_qmlObjectsByPrototypeName.insert(it->name.toString(), objectValue);
|
|
|
|
}
|
|
|
|
|
2010-02-01 17:04:31 +01:00
|
|
|
parentObjectValue = switchObjectValue(objectValue);
|
|
|
|
|
2013-07-17 00:01:45 +03:00
|
|
|
if (parentObjectValue) {
|
2011-05-24 11:50:10 +02:00
|
|
|
objectValue->setMember(QLatin1String("parent"), parentObjectValue);
|
2013-07-17 00:01:45 +03:00
|
|
|
} else if (!_rootObjectValue) {
|
2010-02-01 17:04:31 +01:00
|
|
|
_rootObjectValue = objectValue;
|
2010-04-22 15:44:42 +02:00
|
|
|
_rootObjectValue->setClassName(_doc->componentName());
|
|
|
|
}
|
2010-02-01 17:04:31 +01:00
|
|
|
|
2010-02-01 12:26:40 +01:00
|
|
|
accept(initializer);
|
|
|
|
|
|
|
|
return switchObjectValue(parentObjectValue);
|
2010-01-18 16:15:23 +01:00
|
|
|
}
|
|
|
|
|
2010-02-01 12:26:40 +01:00
|
|
|
void Bind::accept(Node *node)
|
2010-01-18 16:15:23 +01:00
|
|
|
{
|
2010-02-01 12:26:40 +01:00
|
|
|
Node::accept(node, this);
|
2010-01-18 16:15:23 +01:00
|
|
|
}
|
|
|
|
|
2010-02-03 14:31:03 +01:00
|
|
|
bool Bind::visit(AST::UiProgram *)
|
|
|
|
{
|
2011-07-01 12:11:02 +02:00
|
|
|
_idEnvironment = _valueOwner.newObject(/*prototype =*/ 0);
|
2010-02-03 14:31:03 +01:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool Bind::visit(AST::Program *)
|
|
|
|
{
|
2011-07-01 12:11:02 +02:00
|
|
|
_currentObjectValue = _valueOwner.newObject(/*prototype =*/ 0);
|
2010-02-11 18:58:17 +01:00
|
|
|
_rootObjectValue = _currentObjectValue;
|
2010-02-03 14:31:03 +01:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2018-06-20 11:32:47 +02:00
|
|
|
void Bind::endVisit(UiProgram *)
|
|
|
|
{
|
|
|
|
if (_doc->language() == Dialect::QmlQbs) {
|
|
|
|
static const QString qbsBaseImport = QStringLiteral("qbs");
|
|
|
|
static auto isQbsBaseImport = [] (const ImportInfo &ii) {
|
|
|
|
return ii.name() == qbsBaseImport; };
|
|
|
|
if (!Utils::anyOf(_imports, isQbsBaseImport))
|
|
|
|
_imports += ImportInfo::moduleImport(qbsBaseImport, ComponentVersion(), QString());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-04-06 09:52:29 +02:00
|
|
|
bool Bind::visit(UiImport *ast)
|
2010-01-18 16:15:23 +01:00
|
|
|
{
|
2010-09-16 15:29:37 +02:00
|
|
|
ComponentVersion version;
|
2010-05-20 15:19:42 +02:00
|
|
|
if (ast->versionToken.isValid()) {
|
|
|
|
const QString versionString = _doc->source().mid(ast->versionToken.offset, ast->versionToken.length);
|
2011-02-08 11:01:37 +01:00
|
|
|
version = ComponentVersion(versionString);
|
|
|
|
if (!version.isValid()) {
|
2010-09-16 15:29:37 +02:00
|
|
|
_diagnosticMessages->append(
|
|
|
|
errorMessage(ast->versionToken, tr("expected two numbers separated by a dot")));
|
2010-05-20 15:19:42 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-04-06 09:52:29 +02:00
|
|
|
if (ast->importUri) {
|
2010-09-16 15:29:37 +02:00
|
|
|
if (!version.isValid()) {
|
|
|
|
_diagnosticMessages->append(
|
|
|
|
errorMessage(ast, tr("package import requires a version number")));
|
|
|
|
}
|
2013-08-29 10:56:58 +02:00
|
|
|
const QString importId = ast->importId.toString();
|
2012-12-06 17:20:58 +01:00
|
|
|
ImportInfo import = ImportInfo::moduleImport(toString(ast->importUri), version,
|
2013-08-29 10:56:58 +02:00
|
|
|
importId, ast);
|
2014-07-22 19:06:44 +02:00
|
|
|
if (_doc->language() == Dialect::Qml) {
|
2013-08-29 10:56:58 +02:00
|
|
|
const QString importStr = import.name() + importId;
|
2013-11-21 19:42:59 +01:00
|
|
|
if (ModelManagerInterface::instance()) {
|
|
|
|
QmlLanguageBundles langBundles = ModelManagerInterface::instance()->extendedBundles();
|
2014-07-22 19:06:44 +02:00
|
|
|
QmlBundle qq2 = langBundles.bundleForLanguage(Dialect::QmlQtQuick2);
|
2013-11-21 19:42:59 +01:00
|
|
|
bool isQQ2 = qq2.supportedImports().contains(importStr);
|
2018-01-08 11:14:05 +01:00
|
|
|
if (isQQ2)
|
2014-07-22 19:06:44 +02:00
|
|
|
_doc->setLanguage(Dialect::QmlQtQuick2);
|
2013-11-21 19:42:59 +01:00
|
|
|
}
|
2012-12-06 17:20:58 +01:00
|
|
|
}
|
|
|
|
_imports += import;
|
2011-09-13 09:57:24 +02:00
|
|
|
} else if (!ast->fileName.isEmpty()) {
|
2011-09-27 15:12:22 +02:00
|
|
|
_imports += ImportInfo::pathImport(_doc->path(), ast->fileName.toString(),
|
|
|
|
version, ast->importId.toString(), ast);
|
|
|
|
} else {
|
|
|
|
_imports += ImportInfo::invalidImport(ast);
|
2010-04-06 09:52:29 +02:00
|
|
|
}
|
2010-01-26 14:50:52 +01:00
|
|
|
return false;
|
2010-01-18 16:15:23 +01:00
|
|
|
}
|
|
|
|
|
2011-06-06 14:13:50 +02:00
|
|
|
bool Bind::visit(UiPublicMember *ast)
|
2010-01-18 16:15:23 +01:00
|
|
|
{
|
2011-06-06 14:13:50 +02:00
|
|
|
const Block *block = AST::cast<const Block*>(ast->statement);
|
|
|
|
if (block) {
|
|
|
|
// build block scope
|
2011-07-01 12:11:02 +02:00
|
|
|
ObjectValue *blockScope = _valueOwner.newObject(/*prototype=*/0);
|
2011-06-06 14:13:50 +02:00
|
|
|
_attachedJSScopes.insert(ast, blockScope); // associated with the UiPublicMember, not with the block
|
|
|
|
ObjectValue *parent = switchObjectValue(blockScope);
|
|
|
|
accept(ast->statement);
|
|
|
|
switchObjectValue(parent);
|
|
|
|
return false;
|
|
|
|
}
|
2010-09-28 15:50:42 +02:00
|
|
|
return true;
|
2010-01-18 16:15:23 +01:00
|
|
|
}
|
|
|
|
|
2010-01-26 14:50:52 +01:00
|
|
|
bool Bind::visit(UiObjectDefinition *ast)
|
|
|
|
{
|
2010-05-12 13:58:23 +02:00
|
|
|
// an UiObjectDefinition may be used to group property bindings
|
|
|
|
// think anchors { ... }
|
2011-06-23 10:25:43 +02:00
|
|
|
bool isGroupedBinding = ast->qualifiedTypeNameId
|
2011-09-13 09:57:24 +02:00
|
|
|
&& !ast->qualifiedTypeNameId->name.isEmpty()
|
|
|
|
&& ast->qualifiedTypeNameId->name.at(0).isLower();
|
2010-05-12 13:58:23 +02:00
|
|
|
|
|
|
|
if (!isGroupedBinding) {
|
|
|
|
ObjectValue *value = bindObject(ast->qualifiedTypeNameId, ast->initializer);
|
|
|
|
_qmlObjects.insert(ast, value);
|
|
|
|
} else {
|
|
|
|
_groupedPropertyBindings.insert(ast);
|
2011-08-08 12:47:49 +02:00
|
|
|
ObjectValue *oldObjectValue = switchObjectValue(0);
|
2011-06-23 10:25:43 +02:00
|
|
|
accept(ast->initializer);
|
|
|
|
switchObjectValue(oldObjectValue);
|
2010-05-12 13:58:23 +02:00
|
|
|
}
|
2010-01-26 14:50:52 +01:00
|
|
|
|
|
|
|
return false;
|
2010-01-18 16:15:23 +01:00
|
|
|
}
|
|
|
|
|
2010-01-26 14:50:52 +01:00
|
|
|
bool Bind::visit(UiObjectBinding *ast)
|
|
|
|
{
|
|
|
|
// const QString name = serialize(ast->qualifiedId);
|
|
|
|
ObjectValue *value = bindObject(ast->qualifiedTypeNameId, ast->initializer);
|
2010-02-02 17:06:48 +01:00
|
|
|
_qmlObjects.insert(ast, value);
|
2010-01-26 14:50:52 +01:00
|
|
|
// ### FIXME: we don't handle dot-properties correctly (i.e. font.size)
|
|
|
|
// _currentObjectValue->setProperty(name, value);
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool Bind::visit(UiScriptBinding *ast)
|
|
|
|
{
|
2011-06-23 10:25:43 +02:00
|
|
|
if (_currentObjectValue && toString(ast->qualifiedId) == QLatin1String("id")) {
|
2010-01-26 14:50:52 +01:00
|
|
|
if (ExpressionStatement *e = cast<ExpressionStatement*>(ast->statement))
|
|
|
|
if (IdentifierExpression *i = cast<IdentifierExpression*>(e->expression))
|
2011-09-13 09:57:24 +02:00
|
|
|
if (!i->name.isEmpty())
|
|
|
|
_idEnvironment->setMember(i->name.toString(), _currentObjectValue);
|
2010-02-01 12:17:39 +01:00
|
|
|
}
|
2011-06-06 14:13:50 +02:00
|
|
|
const Block *block = AST::cast<const Block*>(ast->statement);
|
|
|
|
if (block) {
|
|
|
|
// build block scope
|
2011-07-01 12:11:02 +02:00
|
|
|
ObjectValue *blockScope = _valueOwner.newObject(/*prototype=*/0);
|
2011-06-06 14:13:50 +02:00
|
|
|
_attachedJSScopes.insert(ast, blockScope); // associated with the UiScriptBinding, not with the block
|
|
|
|
ObjectValue *parent = switchObjectValue(blockScope);
|
|
|
|
accept(ast->statement);
|
|
|
|
switchObjectValue(parent);
|
|
|
|
return false;
|
|
|
|
}
|
2010-11-16 13:53:39 +01:00
|
|
|
return true;
|
2010-01-26 14:50:52 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
bool Bind::visit(UiArrayBinding *)
|
2010-01-18 16:15:23 +01:00
|
|
|
{
|
2010-01-26 14:50:52 +01:00
|
|
|
// ### FIXME: do we need to store the members into the property? Or, maybe the property type is an JS Array?
|
|
|
|
|
2010-01-18 16:15:23 +01:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2018-10-16 15:32:58 +02:00
|
|
|
bool Bind::visit(PatternElement *ast)
|
2010-02-03 14:31:03 +01:00
|
|
|
{
|
2018-10-16 15:32:58 +02:00
|
|
|
if (ast->bindingIdentifier.isEmpty() || !ast->isVariableDeclaration())
|
2010-02-03 14:31:03 +01:00
|
|
|
return false;
|
|
|
|
|
2011-07-12 14:55:27 +02:00
|
|
|
ASTVariableReference *ref = new ASTVariableReference(ast, _doc, &_valueOwner);
|
2011-06-23 10:25:43 +02:00
|
|
|
if (_currentObjectValue)
|
2018-10-16 15:32:58 +02:00
|
|
|
_currentObjectValue->setMember(ast->bindingIdentifier, ref);
|
2010-11-24 14:42:10 +01:00
|
|
|
return true;
|
2010-02-03 14:31:03 +01:00
|
|
|
}
|
|
|
|
|
2010-11-16 13:53:39 +01:00
|
|
|
bool Bind::visit(FunctionExpression *ast)
|
2010-01-18 16:15:23 +01:00
|
|
|
{
|
2010-02-03 15:39:57 +01:00
|
|
|
// ### FIXME: the first declaration counts
|
|
|
|
//if (_currentObjectValue->property(ast->name->asString(), 0))
|
|
|
|
// return false;
|
2010-01-26 18:07:35 +01:00
|
|
|
|
2011-07-01 12:11:02 +02:00
|
|
|
ASTFunctionValue *function = new ASTFunctionValue(ast, _doc, &_valueOwner);
|
2011-09-13 09:57:24 +02:00
|
|
|
if (_currentObjectValue && !ast->name.isEmpty() && cast<FunctionDeclaration *>(ast))
|
|
|
|
_currentObjectValue->setMember(ast->name.toString(), function);
|
2010-02-02 16:36:14 +01:00
|
|
|
|
2010-04-20 15:19:37 +02:00
|
|
|
// build function scope
|
2011-07-01 12:11:02 +02:00
|
|
|
ObjectValue *functionScope = _valueOwner.newObject(/*prototype=*/0);
|
2011-06-06 14:13:50 +02:00
|
|
|
_attachedJSScopes.insert(ast, functionScope);
|
2010-04-20 15:19:37 +02:00
|
|
|
ObjectValue *parent = switchObjectValue(functionScope);
|
|
|
|
|
|
|
|
// The order of the following is important. Example: A function with name "arguments"
|
|
|
|
// overrides the arguments object, a variable doesn't.
|
|
|
|
|
|
|
|
// 1. Function formal arguments
|
|
|
|
for (FormalParameterList *it = ast->formals; it; it = it->next) {
|
2018-10-16 15:32:58 +02:00
|
|
|
if (!it->element->bindingIdentifier.isEmpty())
|
|
|
|
functionScope->setMember(it->element->bindingIdentifier, _valueOwner.unknownValue());
|
2010-04-20 15:19:37 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// 2. Functions defined inside the function body
|
|
|
|
// ### TODO, currently covered by the accept(body)
|
|
|
|
|
|
|
|
// 3. Arguments object
|
2011-07-01 12:11:02 +02:00
|
|
|
ObjectValue *arguments = _valueOwner.newObject(/*prototype=*/0);
|
2011-05-24 11:50:10 +02:00
|
|
|
arguments->setMember(QLatin1String("callee"), function);
|
2011-07-01 12:11:02 +02:00
|
|
|
arguments->setMember(QLatin1String("length"), _valueOwner.numberValue());
|
2011-05-24 11:50:10 +02:00
|
|
|
functionScope->setMember(QLatin1String("arguments"), arguments);
|
2010-04-20 15:19:37 +02:00
|
|
|
|
|
|
|
// 4. Variables defined inside the function body
|
|
|
|
// ### TODO, currently covered by the accept(body)
|
|
|
|
|
|
|
|
// visit body
|
|
|
|
accept(ast->body);
|
|
|
|
switchObjectValue(parent);
|
|
|
|
|
|
|
|
return false;
|
2010-01-18 16:15:23 +01:00
|
|
|
}
|
2010-11-16 13:53:39 +01:00
|
|
|
|
|
|
|
bool Bind::visit(FunctionDeclaration *ast)
|
|
|
|
{
|
|
|
|
return visit(static_cast<FunctionExpression *>(ast));
|
|
|
|
}
|