summaryrefslogtreecommitdiff
path: root/deps/v8/test/inspector/debugger/get-possible-breakpoints-after-gc.js
blob: 097d0b99af1c998445b6bc80738ce1f466e4cc40 (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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
// Copyright 2021 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

let {session, contextGroup, Protocol} = InspectorTest.start(
    'Checks if we keep alive breakpoint information for top-level functions when calling getPossibleBreakpoints.');

session.setupScriptMap();
var executionContextId;

const callGarbageCollector = `
  %CollectGarbage("");
  %CollectGarbage("");
  %CollectGarbage("");
  %CollectGarbage("");
`;

const topLevelFunction = `console.log('This is a top level function')`;
const moduleFunction =
    `function testFunc() { console.log('This is a module function') }`;
let mixedFunctions = ` function A() {}
  console.log('This is a top level function');
`;

Protocol.Debugger.enable().then(onDebuggerEnabled);

function onDebuggerEnabled() {
  Protocol.Runtime.enable();
  Protocol.Runtime.onExecutionContextCreated(onExecutionContextCreated);
}

async function onExecutionContextCreated(messageObject) {
  executionContextId = messageObject.params.context.id;
  await testGetPossibleBreakpoints(
      executionContextId, topLevelFunction, 'topLevel.js');
  await testGetPossibleBreakpoints(
      executionContextId, moduleFunction, 'moduleFunc.js');
  await testGetPossibleBreakpoints(
      executionContextId, mixedFunctions, 'mixedFunctions.js');
  InspectorTest.completeTest();
}

async function testGetPossibleBreakpoints(executionContextId, func, url) {
  const obj = await Protocol.Runtime.compileScript({
    expression: func,
    sourceURL: url,
    persistScript: true,
    executionContextId: executionContextId
  });
  const scriptId = obj.result.scriptId;
  const location = {start: {lineNumber: 0, columnNumber: 0, scriptId}};
  await Protocol.Runtime.runScript({scriptId});
  await Protocol.Runtime.evaluate({expression: `${callGarbageCollector}`});
  const {result: {locations}} =
      await Protocol.Debugger.getPossibleBreakpoints(location);
  InspectorTest.log(`Result of get possible breakpoints in ${url}`);
  InspectorTest.log(JSON.stringify(locations));
}