• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1// 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
7var test_y = false;
8
9function foo(a = 1) {
10  var x = 2;
11  debugger;
12  eval("var y = 3");
13  test_y = true;
14  debugger;
15}
16
17var exception = null;
18var break_count = 0;
19var Debug = debug.Debug;
20var ScopeType = debug.ScopeType;
21
22function listener(event, exec_state) {
23  if (event != Debug.DebugEvent.Break) return;
24  try {
25    var scopes = exec_state.frame(0).allScopes();
26    var expectation = [ ScopeType.Block,
27                        ScopeType.Local,
28                        ScopeType.Script,
29                        ScopeType.Global ];
30    assertEquals(expectation, scopes.map(x => x.scopeType()));
31    assertEquals(2, scopes[0].scopeObject().value().x);
32    if (test_y) assertEquals(3, scopes[0].scopeObject().value().y);
33    assertEquals(1, scopes[1].scopeObject().value().a);
34    break_count++;
35  } catch (e) {
36    print(e);
37    exception = e;
38  }
39}
40Debug.setListener(listener);
41foo();
42
43assertNull(exception);
44assertEquals(2, break_count);
45