1// Copyright 2015 the V8 project authors. All rights reserved. 2// Use of this source code is governed by a BSD-style license that can be 3// found in the LICENSE file. 4 5// Flags: --expose-debug-as debug 6 7// Test that debug-evaluate only resolves variables that are used by 8// the function inside which we debug-evaluate. This is to avoid 9// incorrect variable resolution when a context-allocated variable is 10// shadowed by a stack-allocated variable. 11 12"use strict"; 13 14var Debug = debug.Debug 15 16var exception = null; 17function listener(event, exec_state, event_data, data) { 18 if (event != Debug.DebugEvent.Break) return; 19 try { 20 exec_state.frame(0).evaluate("var x = 2"); 21 exec_state.frame(0).evaluate("'use strict'; let y = 3"); 22 exec_state.frame(0).evaluate("var z = 4"); 23 exec_state.frame(0).evaluate("function bar() { return 5; }"); 24 } catch (e) { 25 exception = e; 26 print(e + e.stack); 27 } 28} 29 30Debug.setListener(listener); 31 32var z = 1; 33 34(function() { 35 debugger; 36})(); 37 38assertEquals(2, x); // declaration 39assertThrows(() => y, ReferenceError); // let-declaration does not stick 40assertEquals(4, z); // re-declaration 41assertEquals(5, bar()); // function declaration 42 43Debug.setListener(null); 44assertNull(exception); 45