From 74f4065caa7254b0e30afa955aa59092024decdb Mon Sep 17 00:00:00 2001 From: Yulong Bai Date: Fri, 15 Jun 2018 14:44:19 +0200 Subject: Add basic support for EcmaScript classes Most of the class creation is done inside the runtime in the CreateClass method. Added a corresponding instruction to the interpreter and jit. The compiled data now contains an array of classes containing the compile time generated layout of the class. Currently, classes without an explicit constructor and classes with inheritance are not supported. Done-with: Yulong Bai Change-Id: I0185dcc1e3b0b8f44deff74e44a8262fc646aa9e Reviewed-by: Simon Hausmann --- src/qml/compiler/qv4compilerscanfunctions.cpp | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) (limited to 'src/qml/compiler/qv4compilerscanfunctions.cpp') diff --git a/src/qml/compiler/qv4compilerscanfunctions.cpp b/src/qml/compiler/qv4compilerscanfunctions.cpp index f3c1694b79..eda0102844 100644 --- a/src/qml/compiler/qv4compilerscanfunctions.cpp +++ b/src/qml/compiler/qv4compilerscanfunctions.cpp @@ -224,6 +224,24 @@ bool ScanFunctions::visit(FunctionExpression *ast) return enterFunction(ast, /*enterName*/ false); } +bool ScanFunctions::visit(ClassExpression *ast) +{ + if (!ast->name.isEmpty()) + _context->addLocalVar(ast->name.toString(), Context::VariableDeclaration, AST::VariableScope::Let); + + enterEnvironment(ast, ContextType::Block, QStringLiteral("%Class")); + _context->isStrict = true; + _context->hasNestedFunctions = true; + if (!ast->name.isEmpty()) + _context->addLocalVar(ast->name.toString(), Context::VariableDeclaration, AST::VariableScope::Let); + return true; +} + +void ScanFunctions::endVisit(ClassExpression *) +{ + leaveEnvironment(); +} + bool ScanFunctions::visit(TemplateLiteral *ast) { while (ast) { @@ -590,12 +608,12 @@ void ScanFunctions::calcEscapingVariables() if (showEscapingVars) { qDebug() << "==== escaping variables ===="; for (Context *c : qAsConst(m->contextMap)) { - qDebug() << "Context" << c << c->name << "requiresExecutionContext" << c->requiresExecutionContext; + qDebug() << "Context" << c << c->name << "requiresExecutionContext" << c->requiresExecutionContext << "isStrict" << c->isStrict; qDebug() << " parent:" << c->parent; if (c->argumentsCanEscape) qDebug() << " Arguments escape"; for (auto it = c->members.constBegin(); it != c->members.constEnd(); ++it) { - qDebug() << " " << it.key() << it.value().canEscape << "isLexicallyScoped:" << it.value().isLexicallyScoped(); + qDebug() << " " << it.key() << it.value().index << it.value().canEscape << "isLexicallyScoped:" << it.value().isLexicallyScoped(); } } } -- cgit v1.2.3