• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1// Copyright 2014 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 --debug-eval-readonly-locals
6
7Debug = debug.Debug;
8
9var step = 0;
10var exception = null;
11
12function listener(event, exec_state, event_data, data) {
13  if (event != Debug.DebugEvent.Break) return;
14  try {
15    if (step == 0) {
16      assertEquals("error", exec_state.frame(0).evaluate("e").value());
17      exec_state.frame(0).evaluate("write_0('foo')");
18      exec_state.frame(0).evaluate("write_1('modified')");
19    } else {
20      assertEquals("argument", exec_state.frame(0).evaluate("e").value());
21      exec_state.frame(0).evaluate("write_2('bar')");
22    }
23    step++;
24  } catch (e) {
25    print(e + e.stack);
26    exception = e;
27  }
28}
29
30Debug.setListener(listener);
31
32function f(e, x) {
33  try {
34    throw "error";
35  } catch(e) {
36    // In ES2015 hoisting semantics, 'x' binds to the argument
37    // and 'e' binds to the exception.
38    function write_0(v) { e = v }
39    function write_1(v) { x = v }
40    debugger;
41    assertEquals("foo", e);  // overwritten by the debugger
42  }
43  assertEquals("argument", e);  // debugger did not overwrite
44  function write_2(v) { e = v }
45  debugger;
46  assertEquals("bar", e);
47  assertEquals("modified", x);
48}
49
50f("argument")
51assertNull(exception);
52assertEquals(2, step);
53