Commit a128e38f authored by Toon Verwaest's avatar Toon Verwaest Committed by Commit Bot

[interpreter/runtime] Hole script let/const requiring initialization in NewScriptContext

That way we don't need to generate bytecode for it.

Change-Id: Ie7e17f283cf5a096ab98c4fd01fd346b56b83576
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2004611Reviewed-by: 's avatarLeszek Swirski <leszeks@chromium.org>
Commit-Queue: Toon Verwaest <verwaest@chromium.org>
Cr-Commit-Position: refs/heads/master@{#65832}
parent f66ffd54
......@@ -222,6 +222,13 @@ MaybeHandle<Context> NewScriptContext(Isolate* isolate,
Handle<Context> result =
isolate->factory()->NewScriptContext(native_context, scope_info);
int header = scope_info->ContextHeaderLength();
for (int var = 0; var < scope_info->ContextLocalCount(); var++) {
if (scope_info->ContextLocalInitFlag(var) == kNeedsInitialization) {
result->set(header + var, ReadOnlyRoots(isolate).the_hole_value());
}
}
Handle<ScriptContextTable> new_script_context_table =
ScriptContextTable::Extend(script_context, result);
native_context->set_script_context_table(*new_script_context_table);
......
......@@ -1320,8 +1320,7 @@ void BytecodeGenerator::VisitVariableDeclaration(VariableDeclaration* decl) {
switch (variable->location()) {
case VariableLocation::UNALLOCATED:
globals_builder()->record_global_declaration();
break;
UNREACHABLE();
case VariableLocation::LOCAL:
if (variable->binding_needs_init()) {
Register destination(builder()->Local(variable->index()));
......@@ -1376,9 +1375,7 @@ void BytecodeGenerator::VisitFunctionDeclaration(FunctionDeclaration* decl) {
switch (variable->location()) {
case VariableLocation::UNALLOCATED:
AddToEagerLiteralsIfEager(decl->fun());
globals_builder()->record_global_declaration();
break;
UNREACHABLE();
case VariableLocation::PARAMETER:
case VariableLocation::LOCAL: {
VisitFunctionLiteral(decl->fun());
......@@ -1435,9 +1432,26 @@ void BytecodeGenerator::VisitModuleNamespaceImports() {
void BytecodeGenerator::VisitGlobalDeclarations(Declaration::List* decls) {
RegisterAllocationScope register_scope(this);
VisitDeclarations(decls);
bool has_global_declaration = false;
for (Declaration* decl : *decls) {
Variable* var = decl->var();
DCHECK(var->is_used());
if (var->location() == VariableLocation::UNALLOCATED) {
// var or function.
has_global_declaration = true;
if (decl->IsFunctionDeclaration()) {
FunctionDeclaration* f = static_cast<FunctionDeclaration*>(decl);
AddToEagerLiteralsIfEager(f->fun());
}
} else {
// let or const. Handled in NewScriptContext.
DCHECK(decl->IsVariableDeclaration());
DCHECK(IsLexicalVariableMode(var->mode()));
}
}
if (!globals_builder()->has_global_declaration()) return;
if (!has_global_declaration) return;
globals_builder()->record_global_declaration();
DCHECK(!globals_builder()->processed());
globals_builder()->set_constant_pool_entry(
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment