diff --git a/src/interpreter/bytecode-generator.cc b/src/interpreter/bytecode-generator.cc index 76af2f415c..3c0511ff5c 100644 --- a/src/interpreter/bytecode-generator.cc +++ b/src/interpreter/bytecode-generator.cc @@ -2370,7 +2370,7 @@ void BytecodeGenerator::BuildVariableLoad(Variable* variable, } case DYNAMIC_GLOBAL: { int depth = - closure_scope()->ContextChainLengthUntilOutermostSloppyEval(); + current_scope()->ContextChainLengthUntilOutermostSloppyEval(); FeedbackSlot slot = GetCachedLoadGlobalICSlot(typeof_mode, variable); builder()->LoadLookupGlobalSlot(variable->raw_name(), typeof_mode, feedback_index(slot), depth); diff --git a/test/cctest/interpreter/bytecode_expectations/ForOfLoop.golden b/test/cctest/interpreter/bytecode_expectations/ForOfLoop.golden index 42c8bda0f3..25ba73ff57 100644 --- a/test/cctest/interpreter/bytecode_expectations/ForOfLoop.golden +++ b/test/cctest/interpreter/bytecode_expectations/ForOfLoop.golden @@ -208,7 +208,7 @@ bytecodes: [ B(StaCurrentContextSlot), U8(4), B(Ldar), R(4), B(StaCurrentContextSlot), U8(4), - /* 41 S> */ B(LdaLookupGlobalSlot), U8(6), U8(12), U8(1), + /* 41 S> */ B(LdaLookupGlobalSlot), U8(6), U8(12), U8(3), B(Star), R(15), B(LdaConstant), U8(7), B(Star), R(16), diff --git a/test/cctest/interpreter/bytecode_expectations/StandardForLoop.golden b/test/cctest/interpreter/bytecode_expectations/StandardForLoop.golden index c1d24a80f0..66c6a1a868 100644 --- a/test/cctest/interpreter/bytecode_expectations/StandardForLoop.golden +++ b/test/cctest/interpreter/bytecode_expectations/StandardForLoop.golden @@ -99,7 +99,7 @@ bytecodes: [ B(TestEqual), R(2), U8(3), B(JumpIfFalse), U8(54), /* 17 E> */ B(StackCheck), - /* 48 S> */ B(LdaLookupGlobalSlot), U8(2), U8(4), U8(1), + /* 48 S> */ B(LdaLookupGlobalSlot), U8(2), U8(4), U8(3), B(Star), R(7), B(LdaConstant), U8(3), B(Star), R(8), diff --git a/test/mjsunit/ignition/dynamic-global-inside-block.js b/test/mjsunit/ignition/dynamic-global-inside-block.js new file mode 100644 index 0000000000..028ad49ae6 --- /dev/null +++ b/test/mjsunit/ignition/dynamic-global-inside-block.js @@ -0,0 +1,11 @@ +// Copyright 2017 the V8 project authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Verifies that DYNAMIC_GLOBAL variables walk the correct context-chain length +// to reach the sloppy-eval calling function context, including block contexts. +function test() { + return eval('var x = 100; { function z() {z}; x }') +} + +test();