Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(659)

Side by Side Diff: test/mjsunit/debug-evaluate-shadowed-context.js

Issue 1500933002: [debugger] fix debug-evaluate wrt shadowed context var. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: add TODO Created 5 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
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
12 Debug = debug.Debug
13
14 var exception = null;
15 function 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 exec_state.frame(0).evaluate("y = 'Y'");
33 exec_state.frame(0).evaluate("a = 'A'");
34 assertThrows(() => exec_state.frame(0).evaluate("z"), ReferenceError);
35 } catch (e) {
36 exception = e;
37 print(e + e.stack);
38 }
39 }
40
41 Debug.setListener(listener);
42
43 var a = "a";
44 assertEquals("Y", (function() {
45 var x = 1; // context allocate x
46 (() => x);
47 var y = "y";
48 var z = "z";
49 (function() {
50 var x = 2; // stack allocate shadowing x
51 (function() {
52 y; // access y
53 debugger; // ReferenceError
54 })(); // 2
55 })(); // 1
56 return y;
57 })());
58
59 assertEquals("A", a);
60 a = "a";
61
62 assertEquals("Y", (function() {
63 var x = 1; // context allocate x
64 (() => x);
65 var y = "y";
66 var z = "z";
67 (function() {
68 var x = 2; // stack allocate shadowing x
69 (() => {
70 y;
71 a;
72 this; // context allocate receiver
73 debugger; // ReferenceError
74 })(); // 2
75 })(); // 1
76 return y;
77 })());
78
79 assertEquals("A", a);
80
81 Debug.setListener(null);
82 assertNull(exception);
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698