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 --no-analyze-environment-liveness 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 12Debug = debug.Debug 13 14var exception = null; 15function listener(event, exec_state, event_data, data) { 16 if (event != Debug.DebugEvent.Break) return; 17 try { 18 for (var i = 0; i < exec_state.frameCount() - 1; i++) { 19 var frame = exec_state.frame(i); 20 var value; 21 try { 22 value = frame.evaluate("x").value(); 23 } catch (e) { 24 value = e.name; 25 } 26 print(frame.sourceLineText()); 27 var expected = frame.sourceLineText().match(/\/\/ (.*$)/)[1]; 28 assertEquals(String(expected), String(value)); 29 } 30 assertEquals("[object global]", 31 String(exec_state.frame(0).evaluate("this").value())); 32 assertEquals("y", exec_state.frame(0).evaluate("y").value()); 33 assertEquals("a", exec_state.frame(0).evaluate("a").value()); 34 exec_state.frame(0).evaluate("a = 'A'"); 35 assertThrows(() => exec_state.frame(0).evaluate("z"), ReferenceError); 36 } catch (e) { 37 exception = e; 38 print(e + e.stack); 39 } 40} 41 42Debug.setListener(listener); 43 44var a = "a"; 45(function() { 46 var x = 1; // context allocate x 47 (() => x); 48 var y = "y"; 49 var z = "z"; 50 (function() { 51 var x = 2; // stack allocate shadowing x 52 (function() { 53 y; // access y 54 debugger; // ReferenceError 55 })(); // 2 56 })(); // 1 57 return y; 58})(); 59 60assertEquals("A", a); 61a = "a"; 62 63(function() { 64 var x = 1; // context allocate x 65 (() => x); 66 var y = "y"; 67 var z = "z"; 68 (function() { 69 var x = 2; // stack allocate shadowing x 70 (() => { 71 y; 72 a; 73 this; // context allocate receiver 74 debugger; // ReferenceError 75 })(); // 2 76 })(); // 1 77 return y; 78})(); 79 80assertEquals("A", a); 81 82Debug.setListener(null); 83assertNull(exception); 84