| Index: src/hydrogen.cc
|
| diff --git a/src/hydrogen.cc b/src/hydrogen.cc
|
| index 4cbcafebe78a289e36a0a7674c10b48b58f79a8d..0717a8e5456ce8d29cec9ce361aab3400a0211e9 100644
|
| --- a/src/hydrogen.cc
|
| +++ b/src/hydrogen.cc
|
| @@ -4474,11 +4474,12 @@ bool HGraphBuilder::TryInline(Call* expr) {
|
| return false;
|
| }
|
|
|
| - // No context change required.
|
| CompilationInfo* outer_info = info();
|
| - if (target->context() != outer_info->closure()->context() ||
|
| - outer_info->scope()->contains_with() ||
|
| - outer_info->scope()->num_heap_slots() > 0) {
|
| + bool context_changed = target->context() != outer_info->closure()->context()
|
| + || outer_info->scope()->contains_with()
|
| + || outer_info->scope()->num_heap_slots() > 0;
|
| +
|
| + if (context_changed && !kInlineContextChangeAllowed) {
|
| TraceInline(target, caller, "target requires context change");
|
| return false;
|
| }
|
| @@ -4601,15 +4602,20 @@ bool HGraphBuilder::TryInline(Call* expr) {
|
| environment()->CopyForInlining(target,
|
| function,
|
| undefined,
|
| - call_kind);
|
| + call_kind,
|
| + context_changed);
|
| HBasicBlock* body_entry = CreateBasicBlock(inner_env);
|
| current_block()->Goto(body_entry);
|
| body_entry->SetJoinId(expr->ReturnId());
|
| set_current_block(body_entry);
|
| AddInstruction(new(zone()) HEnterInlined(target,
|
| function,
|
| - call_kind));
|
| + call_kind,
|
| + context_changed));
|
| VisitDeclarations(target_info.scope()->declarations());
|
| + if (context_changed) {
|
| + AddInstruction(HInstruction::cast(inner_env->LookupContext()));
|
| + }
|
| VisitStatements(function->body());
|
| if (HasStackOverflow()) {
|
| // Bail out if the inline function did, as we cannot residualize a call
|
| @@ -6458,7 +6464,8 @@ HEnvironment* HEnvironment::CopyForInlining(
|
| Handle<JSFunction> target,
|
| FunctionLiteral* function,
|
| HConstant* undefined,
|
| - CallKind call_kind) const {
|
| + CallKind call_kind,
|
| + bool context_changed) const {
|
| // Outer environment is a copy of this one without the arguments.
|
| int arity = function->scope()->num_parameters();
|
| HEnvironment* outer = Copy();
|
| @@ -6479,7 +6486,12 @@ HEnvironment* HEnvironment::CopyForInlining(
|
| call_kind == CALL_AS_FUNCTION) {
|
| inner->SetValueAt(0, undefined);
|
| }
|
| - inner->SetValueAt(arity + 1, outer->LookupContext());
|
| + if (context_changed) {
|
| + HInlinedContext* context = new(zone) HInlinedContext(target);
|
| + inner->SetValueAt(arity + 1, context);
|
| + } else {
|
| + inner->SetValueAt(arity + 1, LookupContext());
|
| + }
|
| for (int i = arity + 2; i < inner->length(); ++i) {
|
| inner->SetValueAt(i, undefined);
|
| }
|
|
|