summaryrefslogtreecommitdiff
path: root/deps/v8/test/debugger/debug/debug-live-edit-recursion.js
blob: 6328a9b6def5d5f17b5644a05a2a7812d8e1ebba (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
// Copyright 2018 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.

// Flags: --allow-natives-syntax

Debug = debug.Debug;

function test(i) {
  if (i == 3) {
    return (function* gen() { yield test(i - 1); })().next().value;
  } else if (i > 1) {
    return test(i - 1);
  } else {
    debugger;
    return 5;
  }
}

let patch = null, exception = null;

Debug.setListener(listener);
patch = ['return 5', 'return 3'];
assertEquals(3, test(2)); // no running generator
patch = ['return 3', 'return -1'];
assertEquals(3, test(3)); // there is running generator
assertEquals(exception,
    'LiveEdit failed: BLOCKED_BY_FUNCTION_BELOW_NON_DROPPABLE_FRAME');
Debug.setListener(null);

function listener(event) {
  if (event != Debug.DebugEvent.Break || !patch) return;
  try {
    %LiveEditPatchScript(test,
        Debug.scriptSource(test).replace(patch[0], patch[1]));
  } catch (e) {
    exception = e;
  }
  patch = null;
}