Implement the lexical scoping (#285)

This patch introduces the let and const keyword and all the related lexical scoping rules.

Signed-off-by: Robert Fancsik frobert@inf.u-szeged.hu
This commit is contained in:
Robert Fancsik 2019-07-05 06:38:11 +02:00 committed by Hyukwoo Park
commit ef59096112
32 changed files with 1026 additions and 94 deletions

View file

@ -137,12 +137,12 @@ InterpretedCodeBlock* ScriptParser::generateCodeBlockTreeFromAST(Context* ctx, S
return generateCodeBlockTreeFromASTWalker(ctx, source, script, program->scopeContext(), nullptr);
}
void ScriptParser::generateCodeBlockTreeFromASTWalkerPostProcess(InterpretedCodeBlock* cb)
void ScriptParser::generateCodeBlockTreeFromASTWalkerPostProcess(InterpretedCodeBlock* cb, bool propagateLexicalBlock)
{
for (size_t i = 0; i < cb->m_childBlocks.size(); i++) {
generateCodeBlockTreeFromASTWalkerPostProcess(cb->m_childBlocks[i]);
generateCodeBlockTreeFromASTWalkerPostProcess(cb->m_childBlocks[i], propagateLexicalBlock);
}
cb->computeVariables();
cb->computeVariables(propagateLexicalBlock);
if (cb->m_identifierOnStackCount > VARIABLE_LIMIT || cb->m_identifierOnHeapCount > VARIABLE_LIMIT) {
auto err = new esprima::Error(new ASCIIString("variable limit exceeded"));
err->errorCode = ErrorObject::SyntaxError;
@ -189,7 +189,7 @@ void ScriptParser::generateProgramCodeBlock(ExecutionState& state, StringView sc
}
topCodeBlock->m_isEvalCodeInFunction = isEvalCodeInFunction;
generateCodeBlockTreeFromASTWalkerPostProcess(topCodeBlock);
generateCodeBlockTreeFromASTWalkerPostProcess(topCodeBlock, topCodeBlock->needsLexicalBlock());
script->m_topCodeBlock = topCodeBlock;