Each InterpretedCodeBlock has its children in a vector

* reduce the whole size of InterpretedCodeBlock instances
* iterate fastly on children

Signed-off-by: HyukWoo Park <hyukwoo.park@samsung.com>
This commit is contained in:
HyukWoo Park 2020-07-16 20:21:29 +09:00 committed by Boram Bae
commit 773007bec6
13 changed files with 205 additions and 193 deletions

View file

@ -265,14 +265,16 @@ static bool canDeclareGlobalFunction(ExecutionState& state, Object* globalObject
static void testDeclareGlobalFunctions(ExecutionState& state, InterpretedCodeBlock* topCodeBlock, Object* globalObject)
{
auto c = topCodeBlock->firstChild();
while (c) {
if (c->isFunctionDeclaration() && c->lexicalBlockIndexFunctionLocatedIn() == 0) {
if (!canDeclareGlobalFunction(state, globalObject, c->functionName())) {
ErrorObject::throwBuiltinError(state, ErrorObject::TypeError, "Identifier '%s' has already been declared", c->functionName());
if (topCodeBlock->hasChildren()) {
InterpretedCodeBlockVector& childrenVector = topCodeBlock->children();
for (size_t i = 0; i < childrenVector.size(); i++) {
auto c = childrenVector[i];
if (c->isFunctionDeclaration() && c->lexicalBlockIndexFunctionLocatedIn() == 0) {
if (!canDeclareGlobalFunction(state, globalObject, c->functionName())) {
ErrorObject::throwBuiltinError(state, ErrorObject::TypeError, "Identifier '%s' has already been declared", c->functionName());
}
}
}
c = c->nextSibling();
}
}
@ -338,14 +340,16 @@ Value Script::execute(ExecutionState& state, bool isExecuteOnEvalFunction, bool
size_t globalLexicalVectorLen = globalLexicalVector.size();
if (!isExecuteOnEvalFunction) {
InterpretedCodeBlock* child = m_topCodeBlock->firstChild();
while (child) {
if (child->isFunctionDeclaration()) {
if (child->lexicalBlockIndexFunctionLocatedIn() == 0 && !state.context()->globalObject()->defineOwnProperty(state, child->functionName(), ObjectPropertyDescriptor(Value(), (ObjectPropertyDescriptor::PresentAttribute)(ObjectPropertyDescriptor::WritablePresent | ObjectStructurePropertyDescriptor::EnumerablePresent)))) {
ErrorObject::throwBuiltinError(state, ErrorObject::Code::SyntaxError, "Identifier '%s' has already been declared", child->functionName());
if (m_topCodeBlock->hasChildren()) {
InterpretedCodeBlockVector& childrenVector = m_topCodeBlock->children();
for (size_t i = 0; i < childrenVector.size(); i++) {
InterpretedCodeBlock* child = childrenVector[i];
if (child->isFunctionDeclaration()) {
if (child->lexicalBlockIndexFunctionLocatedIn() == 0 && !state.context()->globalObject()->defineOwnProperty(state, child->functionName(), ObjectPropertyDescriptor(Value(), (ObjectPropertyDescriptor::PresentAttribute)(ObjectPropertyDescriptor::WritablePresent | ObjectStructurePropertyDescriptor::EnumerablePresent)))) {
ErrorObject::throwBuiltinError(state, ErrorObject::Code::SyntaxError, "Identifier '%s' has already been declared", child->functionName());
}
}
}
child = child->nextSibling();
}
// https://www.ecma-international.org/ecma-262/#sec-globaldeclarationinstantiation