mirror of
https://github.com/Samsung/escargot.git
synced 2026-06-22 10:01:50 +00:00
Implement Arrow Function[ES6] (#162)
Signed-off-by: HyukWoo Park <hyukwoo.park@samsung.com>
This commit is contained in:
parent
661b124ee2
commit
42eee4e35b
19 changed files with 713 additions and 264 deletions
|
|
@ -45,7 +45,7 @@ InterpretedCodeBlock* ScriptParser::generateCodeBlockTreeFromASTWalker(Context*
|
|||
| (scopeCtx->m_hasCatch ? CodeBlock::CodeBlockHasCatch : 0)
|
||||
| (scopeCtx->m_hasYield ? CodeBlock::CodeBlockHasYield : 0)));
|
||||
} else {
|
||||
bool isFE = scopeCtx->m_nodeType == FunctionExpression;
|
||||
bool isFE = scopeCtx->m_nodeType == FunctionExpression || scopeCtx->m_nodeType == ArrowFunctionExpression;
|
||||
bool isFD = scopeCtx->m_nodeType == FunctionDeclaration;
|
||||
|
||||
if (scopeCtx->m_needsSpecialInitialize)
|
||||
|
|
@ -63,6 +63,7 @@ InterpretedCodeBlock* ScriptParser::generateCodeBlockTreeFromASTWalker(Context*
|
|||
| (scopeCtx->m_inWith ? CodeBlock::CodeBlockInWith : 0)
|
||||
| (isFE ? CodeBlock::CodeBlockIsFunctionExpression : 0)
|
||||
| (isFD ? CodeBlock::CodeBlockIsFunctionDeclaration : 0)
|
||||
| (scopeCtx->m_isArrowFunctionExpression ? CodeBlock::CodeBlockIsArrowFunctionExpression : 0)
|
||||
| (scopeCtx->m_needsSpecialInitialize ? CodeBlock::CodeBlockIsFunctionDeclarationWithSpecialBinding : 0)));
|
||||
}
|
||||
|
||||
|
|
@ -91,42 +92,40 @@ InterpretedCodeBlock* ScriptParser::generateCodeBlockTreeFromASTWalker(Context*
|
|||
|
||||
bool hasCapturedIdentifier = false;
|
||||
AtomicString arguments = ctx->staticStrings().arguments;
|
||||
AtomicString stringThis = ctx->staticStrings().stringThis;
|
||||
for (size_t i = 0; i < scopeCtx->m_usingNames.size(); i++) {
|
||||
AtomicString uname = scopeCtx->m_usingNames[i];
|
||||
if (uname == arguments) {
|
||||
const InterpretedCodeBlock::FunctionParametersInfoVector& pv = codeBlock->parametersInfomation();
|
||||
bool hasArgumentsParameter = false;
|
||||
for (size_t i = 0; i < pv.size(); i++) {
|
||||
if (pv[i].m_name == arguments) {
|
||||
hasArgumentsParameter = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!hasArgumentsParameter) {
|
||||
codeBlock->m_usesArgumentsObject = true;
|
||||
if (!codeBlock->hasName(arguments)) {
|
||||
CodeBlock::IdentifierInfo info;
|
||||
info.m_indexForIndexedStorage = SIZE_MAX;
|
||||
info.m_name = arguments;
|
||||
info.m_needToAllocateOnStack = true;
|
||||
info.m_isMutable = true;
|
||||
codeBlock->m_identifierInfos.pushBack(info);
|
||||
}
|
||||
|
||||
InterpretedCodeBlock* b = codeBlock;
|
||||
if (b->parameterCount()) {
|
||||
b->m_canAllocateEnvironmentOnStack = false;
|
||||
for (size_t j = 0; j < b->parametersInfomation().size(); j++) {
|
||||
for (size_t k = 0; k < b->identifierInfos().size(); k++) {
|
||||
if (b->identifierInfos()[k].m_name == b->parametersInfomation()[j].m_name) {
|
||||
b->m_identifierInfos[k].m_needToAllocateOnStack = false;
|
||||
break;
|
||||
}
|
||||
if (UNLIKELY(codeBlock->hasParameter(arguments))) {
|
||||
continue;
|
||||
} else {
|
||||
if (LIKELY(!codeBlock->isArrowFunctionExpression())) {
|
||||
codeBlock->captureArguments();
|
||||
continue;
|
||||
} else {
|
||||
InterpretedCodeBlock* c = codeBlock->parentCodeBlock();
|
||||
while (c && !c->isGlobalScopeCodeBlock()) {
|
||||
if (c->hasParameter(arguments)) {
|
||||
break;
|
||||
} else if (!c->isArrowFunctionExpression()) {
|
||||
c->captureArguments();
|
||||
break;
|
||||
}
|
||||
c = c->parentCodeBlock();
|
||||
}
|
||||
}
|
||||
}
|
||||
} else if (!codeBlock->hasName(uname)) {
|
||||
} else if (uname == stringThis) {
|
||||
ASSERT(codeBlock->isArrowFunctionExpression());
|
||||
if (!codeBlock->parentCodeBlock()->isGlobalScopeCodeBlock()) {
|
||||
codeBlock->parentCodeBlock()->captureThis();
|
||||
codeBlock->setNeedToLoadThisValue();
|
||||
hasCapturedIdentifier = true;
|
||||
}
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!codeBlock->hasName(uname)) {
|
||||
InterpretedCodeBlock* c = codeBlock->parentCodeBlock();
|
||||
while (c) {
|
||||
if (c->tryCaptureIdentifiersFromChildCodeBlock(uname)) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue