default-parameters-debug.js 1.8 KB
Newer Older
1 2 3
// Copyright 2015 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
4 5
//
// Flags: --noanalyze-environment-liveness
6 7 8 9 10 11


Debug = debug.Debug

listenerComplete = false;
breakPointCount = 0;
12
exception = null;
13 14

function listener(event, exec_state, event_data, data) {
15 16
  if (event != Debug.DebugEvent.Break) return;
  try {
17 18 19 20
    breakPointCount++;
    if (breakPointCount == 1) {
      // Break point in initializer for parameter `a`, invoked by
      // initializer for parameter `b`
21 22 23
      assertEquals('default', exec_state.frame(0).evaluate('mode').value());
      assertTrue(exec_state.frame(1).evaluate('b').isUndefined());
      assertTrue(exec_state.frame(1).evaluate('c').isUndefined());
24 25 26 27
    } else if (breakPointCount == 2) {
      // Break point in IIFE initializer for parameter `c`
      assertEquals('modeFn', exec_state.frame(1).evaluate('a.name').value());
      assertEquals('default', exec_state.frame(1).evaluate('b').value());
28
      assertTrue(exec_state.frame(1).evaluate('c').isUndefined());
29 30 31 32 33 34
    } else if (breakPointCount == 3) {
      // Break point in function body --- `c` parameter is shadowed
      assertEquals('modeFn', exec_state.frame(0).evaluate('a.name').value());
      assertEquals('default', exec_state.frame(0).evaluate('b').value());
      assertEquals('local', exec_state.frame(0).evaluate('d').value());
    }
35 36
  } catch (e) {
    exception = e;
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53
  }
};

// Add the debug event listener.
Debug.setListener(listener);

function f(a = function modeFn(mode) { debugger; return mode; },
           b = a("default"),
           c = (function() { debugger; })()) {
  var d = 'local';
  debugger;
};

f();

// Make sure that the debug event listener vas invoked.
assertEquals(3, breakPointCount);
54
assertNull(exception);