diff --git a/src/compiler/ast-graph-builder.cc b/src/compiler/ast-graph-builder.cc index fd8a56aa21..4023d1d352 100644 --- a/src/compiler/ast-graph-builder.cc +++ b/src/compiler/ast-graph-builder.cc @@ -933,6 +933,7 @@ void AstGraphBuilder::VisitVariableDeclaration(VariableDeclaration* decl) { DCHECK(!slot.IsInvalid()); globals()->push_back(handle(Smi::FromInt(slot.ToInt()), isolate())); globals()->push_back(isolate()->factory()->undefined_value()); + globals()->push_back(isolate()->factory()->undefined_value()); break; } case VariableLocation::PARAMETER: @@ -968,6 +969,12 @@ void AstGraphBuilder::VisitFunctionDeclaration(FunctionDeclaration* decl) { FeedbackVectorSlot slot = decl->proxy()->VariableFeedbackSlot(); DCHECK(!slot.IsInvalid()); globals()->push_back(handle(Smi::FromInt(slot.ToInt()), isolate())); + + // We need the slot where the literals array lives, too. + slot = decl->fun()->LiteralFeedbackSlot(); + DCHECK(!slot.IsInvalid()); + globals()->push_back(handle(Smi::FromInt(slot.ToInt()), isolate())); + globals()->push_back(function); break; } diff --git a/src/crankshaft/hydrogen.cc b/src/crankshaft/hydrogen.cc index 1ddc4a80b6..925039f260 100644 --- a/src/crankshaft/hydrogen.cc +++ b/src/crankshaft/hydrogen.cc @@ -11848,6 +11848,7 @@ void HOptimizedGraphBuilder::VisitVariableDeclaration( DCHECK(!slot.IsInvalid()); globals_.Add(handle(Smi::FromInt(slot.ToInt()), isolate()), zone()); globals_.Add(isolate()->factory()->undefined_value(), zone()); + globals_.Add(isolate()->factory()->undefined_value(), zone()); return; } case VariableLocation::PARAMETER: @@ -11886,6 +11887,12 @@ void HOptimizedGraphBuilder::VisitFunctionDeclaration( FeedbackVectorSlot slot = proxy->VariableFeedbackSlot(); DCHECK(!slot.IsInvalid()); globals_.Add(handle(Smi::FromInt(slot.ToInt()), isolate()), zone()); + + // We need the slot where the literals array lives, too. + slot = declaration->fun()->LiteralFeedbackSlot(); + DCHECK(!slot.IsInvalid()); + globals_.Add(handle(Smi::FromInt(slot.ToInt()), isolate()), zone()); + Handle function = Compiler::GetSharedFunctionInfo( declaration->fun(), current_info()->script(), top_info()); // Check for stack-overflow exception. diff --git a/src/full-codegen/arm/full-codegen-arm.cc b/src/full-codegen/arm/full-codegen-arm.cc index 4b61bf9ab8..878c812789 100644 --- a/src/full-codegen/arm/full-codegen-arm.cc +++ b/src/full-codegen/arm/full-codegen-arm.cc @@ -761,6 +761,7 @@ void FullCodeGenerator::VisitVariableDeclaration( DCHECK(!slot.IsInvalid()); globals_->Add(handle(Smi::FromInt(slot.ToInt()), isolate()), zone()); globals_->Add(isolate()->factory()->undefined_value(), zone()); + globals_->Add(isolate()->factory()->undefined_value(), zone()); break; } case VariableLocation::PARAMETER: @@ -800,6 +801,12 @@ void FullCodeGenerator::VisitFunctionDeclaration( FeedbackVectorSlot slot = proxy->VariableFeedbackSlot(); DCHECK(!slot.IsInvalid()); globals_->Add(handle(Smi::FromInt(slot.ToInt()), isolate()), zone()); + + // We need the slot where the literals array lives, too. + slot = declaration->fun()->LiteralFeedbackSlot(); + DCHECK(!slot.IsInvalid()); + globals_->Add(handle(Smi::FromInt(slot.ToInt()), isolate()), zone()); + Handle function = Compiler::GetSharedFunctionInfo(declaration->fun(), script(), info_); // Check for stack-overflow exception. diff --git a/src/full-codegen/arm64/full-codegen-arm64.cc b/src/full-codegen/arm64/full-codegen-arm64.cc index ae1fab14b9..1758e024cf 100644 --- a/src/full-codegen/arm64/full-codegen-arm64.cc +++ b/src/full-codegen/arm64/full-codegen-arm64.cc @@ -756,6 +756,7 @@ void FullCodeGenerator::VisitVariableDeclaration( DCHECK(!slot.IsInvalid()); globals_->Add(handle(Smi::FromInt(slot.ToInt()), isolate()), zone()); globals_->Add(isolate()->factory()->undefined_value(), zone()); + globals_->Add(isolate()->factory()->undefined_value(), zone()); break; } case VariableLocation::PARAMETER: @@ -795,6 +796,12 @@ void FullCodeGenerator::VisitFunctionDeclaration( FeedbackVectorSlot slot = proxy->VariableFeedbackSlot(); DCHECK(!slot.IsInvalid()); globals_->Add(handle(Smi::FromInt(slot.ToInt()), isolate()), zone()); + + // We need the slot where the literals array lives, too. + slot = declaration->fun()->LiteralFeedbackSlot(); + DCHECK(!slot.IsInvalid()); + globals_->Add(handle(Smi::FromInt(slot.ToInt()), isolate()), zone()); + Handle function = Compiler::GetSharedFunctionInfo(declaration->fun(), script(), info_); // Check for stack overflow exception. diff --git a/src/full-codegen/ia32/full-codegen-ia32.cc b/src/full-codegen/ia32/full-codegen-ia32.cc index 28e2616ac6..d55ce85e60 100644 --- a/src/full-codegen/ia32/full-codegen-ia32.cc +++ b/src/full-codegen/ia32/full-codegen-ia32.cc @@ -709,6 +709,7 @@ void FullCodeGenerator::VisitVariableDeclaration( DCHECK(!slot.IsInvalid()); globals_->Add(handle(Smi::FromInt(slot.ToInt()), isolate()), zone()); globals_->Add(isolate()->factory()->undefined_value(), zone()); + globals_->Add(isolate()->factory()->undefined_value(), zone()); break; } case VariableLocation::PARAMETER: @@ -748,6 +749,12 @@ void FullCodeGenerator::VisitFunctionDeclaration( FeedbackVectorSlot slot = proxy->VariableFeedbackSlot(); DCHECK(!slot.IsInvalid()); globals_->Add(handle(Smi::FromInt(slot.ToInt()), isolate()), zone()); + + // We need the slot where the literals array lives, too. + slot = declaration->fun()->LiteralFeedbackSlot(); + DCHECK(!slot.IsInvalid()); + globals_->Add(handle(Smi::FromInt(slot.ToInt()), isolate()), zone()); + Handle function = Compiler::GetSharedFunctionInfo(declaration->fun(), script(), info_); // Check for stack-overflow exception. diff --git a/src/full-codegen/mips/full-codegen-mips.cc b/src/full-codegen/mips/full-codegen-mips.cc index 4599439c81..5a15fc9201 100644 --- a/src/full-codegen/mips/full-codegen-mips.cc +++ b/src/full-codegen/mips/full-codegen-mips.cc @@ -760,6 +760,7 @@ void FullCodeGenerator::VisitVariableDeclaration( DCHECK(!slot.IsInvalid()); globals_->Add(handle(Smi::FromInt(slot.ToInt()), isolate()), zone()); globals_->Add(isolate()->factory()->undefined_value(), zone()); + globals_->Add(isolate()->factory()->undefined_value(), zone()); break; } case VariableLocation::PARAMETER: @@ -799,6 +800,12 @@ void FullCodeGenerator::VisitFunctionDeclaration( FeedbackVectorSlot slot = proxy->VariableFeedbackSlot(); DCHECK(!slot.IsInvalid()); globals_->Add(handle(Smi::FromInt(slot.ToInt()), isolate()), zone()); + + // We need the slot where the literals array lives, too. + slot = declaration->fun()->LiteralFeedbackSlot(); + DCHECK(!slot.IsInvalid()); + globals_->Add(handle(Smi::FromInt(slot.ToInt()), isolate()), zone()); + Handle function = Compiler::GetSharedFunctionInfo(declaration->fun(), script(), info_); // Check for stack-overflow exception. diff --git a/src/full-codegen/mips64/full-codegen-mips64.cc b/src/full-codegen/mips64/full-codegen-mips64.cc index f6bda9a401..57d234c08d 100644 --- a/src/full-codegen/mips64/full-codegen-mips64.cc +++ b/src/full-codegen/mips64/full-codegen-mips64.cc @@ -760,6 +760,7 @@ void FullCodeGenerator::VisitVariableDeclaration( DCHECK(!slot.IsInvalid()); globals_->Add(handle(Smi::FromInt(slot.ToInt()), isolate()), zone()); globals_->Add(isolate()->factory()->undefined_value(), zone()); + globals_->Add(isolate()->factory()->undefined_value(), zone()); break; } case VariableLocation::PARAMETER: @@ -799,6 +800,12 @@ void FullCodeGenerator::VisitFunctionDeclaration( FeedbackVectorSlot slot = proxy->VariableFeedbackSlot(); DCHECK(!slot.IsInvalid()); globals_->Add(handle(Smi::FromInt(slot.ToInt()), isolate()), zone()); + + // We need the slot where the literals array lives, too. + slot = declaration->fun()->LiteralFeedbackSlot(); + DCHECK(!slot.IsInvalid()); + globals_->Add(handle(Smi::FromInt(slot.ToInt()), isolate()), zone()); + Handle function = Compiler::GetSharedFunctionInfo(declaration->fun(), script(), info_); // Check for stack-overflow exception. diff --git a/src/full-codegen/x64/full-codegen-x64.cc b/src/full-codegen/x64/full-codegen-x64.cc index 02f93f9807..f72bc49789 100644 --- a/src/full-codegen/x64/full-codegen-x64.cc +++ b/src/full-codegen/x64/full-codegen-x64.cc @@ -723,6 +723,7 @@ void FullCodeGenerator::VisitVariableDeclaration( DCHECK(!slot.IsInvalid()); globals_->Add(handle(Smi::FromInt(slot.ToInt()), isolate()), zone()); globals_->Add(isolate()->factory()->undefined_value(), zone()); + globals_->Add(isolate()->factory()->undefined_value(), zone()); break; } case VariableLocation::PARAMETER: @@ -762,6 +763,12 @@ void FullCodeGenerator::VisitFunctionDeclaration( FeedbackVectorSlot slot = proxy->VariableFeedbackSlot(); DCHECK(!slot.IsInvalid()); globals_->Add(handle(Smi::FromInt(slot.ToInt()), isolate()), zone()); + + // We need the slot where the literals array lives, too. + slot = declaration->fun()->LiteralFeedbackSlot(); + DCHECK(!slot.IsInvalid()); + globals_->Add(handle(Smi::FromInt(slot.ToInt()), isolate()), zone()); + Handle function = Compiler::GetSharedFunctionInfo(declaration->fun(), script(), info_); // Check for stack-overflow exception. diff --git a/src/interpreter/bytecode-generator.cc b/src/interpreter/bytecode-generator.cc index a21e978965..56fa636d30 100644 --- a/src/interpreter/bytecode-generator.cc +++ b/src/interpreter/bytecode-generator.cc @@ -498,9 +498,10 @@ class BytecodeGenerator::GlobalDeclarationsBuilder final : public ZoneObject { has_constant_pool_entry_(false) {} void AddFunctionDeclaration(Handle name, FeedbackVectorSlot slot, + FeedbackVectorSlot literal_slot, FunctionLiteral* func) { DCHECK(!slot.IsInvalid()); - declarations_.push_back(Declaration(name, slot, func)); + declarations_.push_back(Declaration(name, slot, literal_slot, func)); } void AddUndefinedDeclaration(Handle name, FeedbackVectorSlot slot) { @@ -512,7 +513,7 @@ class BytecodeGenerator::GlobalDeclarationsBuilder final : public ZoneObject { DCHECK(has_constant_pool_entry_); int array_index = 0; Handle data = info->isolate()->factory()->NewFixedArray( - static_cast(declarations_.size() * 3), TENURED); + static_cast(declarations_.size() * 4), TENURED); for (const Declaration& declaration : declarations_) { FunctionLiteral* func = declaration.func; Handle initial_value; @@ -529,6 +530,14 @@ class BytecodeGenerator::GlobalDeclarationsBuilder final : public ZoneObject { data->set(array_index++, *declaration.name); data->set(array_index++, Smi::FromInt(declaration.slot.ToInt())); + Object* undefined_or_literal_slot; + if (declaration.literal_slot.IsInvalid()) { + undefined_or_literal_slot = info->isolate()->heap()->undefined_value(); + } else { + undefined_or_literal_slot = + Smi::FromInt(declaration.literal_slot.ToInt()); + } + data->set(array_index++, undefined_or_literal_slot); data->set(array_index++, *initial_value); } return data; @@ -551,12 +560,19 @@ class BytecodeGenerator::GlobalDeclarationsBuilder final : public ZoneObject { private: struct Declaration { Declaration() : slot(FeedbackVectorSlot::Invalid()), func(nullptr) {} + Declaration(Handle name, FeedbackVectorSlot slot, + FeedbackVectorSlot literal_slot, FunctionLiteral* func) + : name(name), slot(slot), literal_slot(literal_slot), func(func) {} Declaration(Handle name, FeedbackVectorSlot slot, FunctionLiteral* func) - : name(name), slot(slot), func(func) {} + : name(name), + slot(slot), + literal_slot(FeedbackVectorSlot::Invalid()), + func(func) {} Handle name; FeedbackVectorSlot slot; + FeedbackVectorSlot literal_slot; FunctionLiteral* func; }; ZoneVector declarations_; @@ -889,8 +905,9 @@ void BytecodeGenerator::VisitFunctionDeclaration(FunctionDeclaration* decl) { switch (variable->location()) { case VariableLocation::UNALLOCATED: { FeedbackVectorSlot slot = decl->proxy()->VariableFeedbackSlot(); - globals_builder()->AddFunctionDeclaration(variable->name(), slot, - decl->fun()); + globals_builder()->AddFunctionDeclaration( + variable->name(), slot, decl->fun()->LiteralFeedbackSlot(), + decl->fun()); break; } case VariableLocation::PARAMETER: diff --git a/src/runtime/runtime-scopes.cc b/src/runtime/runtime-scopes.cc index 6dae7dd609..2e349f00d3 100644 --- a/src/runtime/runtime-scopes.cc +++ b/src/runtime/runtime-scopes.cc @@ -137,10 +137,10 @@ Object* DeclareGlobals(Isolate* isolate, Handle declarations, // Traverse the name/value pairs and set the properties. int length = declarations->length(); - FOR_WITH_HANDLE_SCOPE(isolate, int, i = 0, i, i < length, i += 3, { + FOR_WITH_HANDLE_SCOPE(isolate, int, i = 0, i, i < length, i += 4, { Handle name(String::cast(declarations->get(i)), isolate); FeedbackVectorSlot slot(Smi::cast(declarations->get(i + 1))->value()); - Handle initial_value(declarations->get(i + 2), isolate); + Handle initial_value(declarations->get(i + 3), isolate); bool is_var = initial_value->IsUndefined(isolate); bool is_function = initial_value->IsSharedFunctionInfo();