debug-liveedit-replace-code.js 741 Bytes
Newer Older
1 2 3 4
// Copyright 2017 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.

5 6
// Flags: --allow-natives-syntax

7 8 9 10 11 12 13
Debug = debug.Debug
var counter = 0;
var exception = null;
function f() {
  if (++counter > 5) return;
  debugger;
  return counter;
14
};
15 16 17 18 19 20

function listener(event, exec_state, event_data, data) {
  if (event != Debug.DebugEvent.Break) return;
  try {
    var original = 'debugger;';
    var patch = 'debugger;\n';
21
    %LiveEditPatchScript(f, Debug.scriptSource(f).replace(original, patch));
22 23 24 25 26 27 28 29
  } catch (e) {
    exception = e;
  }
}

Debug.setListener(listener);
f();
Debug.setListener(null);
30
assertNull(exception);
31
assertEquals(6, counter);