blob: d4dc93f2c50e1c6fb21228b08483ed71625500ad [file] [log] [blame]
Ben Murdochc5610432016-08-08 18:44:38 +01001// Copyright 2016 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 the parameter initialization block scope set up for
8// sloppy eval is visible to the debugger.
9
10var Debug = debug.Debug;
11var exception = null;
12var break_count = 0;
13
14function call_for_break() {
15 return 5;
16}
17
18function test(x = eval("var y = 7; debugger; y") + call_for_break()) {
19 return x;
20}
21
22function listener(event, exec_state, event_data, data) {
23 if (event != Debug.DebugEvent.Break) return;
24 try {
25 var frame = exec_state.frame(0);
26 var block_scope;
27 if (break_count++ == 0) {
28 // Inside eval.
29 assertEquals([ debug.ScopeType.Eval,
30 debug.ScopeType.Block,
31 debug.ScopeType.Closure,
32 debug.ScopeType.Script,
33 debug.ScopeType.Global ],
34 frame.allScopes().map(s => s.scopeType()));
35 exec_state.prepareStep(Debug.StepAction.StepOut);
36 block_scope = frame.scope(1);
37 } else {
38 // Outside of eval.
39 assertEquals([ debug.ScopeType.Block,
40 debug.ScopeType.Local,
41 debug.ScopeType.Script,
42 debug.ScopeType.Global ],
43 frame.allScopes().map(s => s.scopeType()));
44 block_scope = frame.scope(0);
45 }
46 assertTrue(block_scope.scopeObject().propertyNames().includes('y'));
47 assertEquals(7, block_scope.scopeObject().property('y').value().value());
48 } catch (e) {
49 print(e);
50 exception = e;
51 }
52}
53
54Debug.setListener(listener);
55
56assertEquals(12, test());
57
58Debug.setListener(null);
59
60assertNull(exception);
61assertEquals(2, break_count);