summaryrefslogtreecommitdiffstats
path: root/devtools/shared/tests/xpcshell/test_stack.js
blob: a95d28c57d96413c53aec8827ac881efe81d9f90 (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
/* Any copyright is dedicated to the Public Domain.
   http://creativecommons.org/publicdomain/zero/1.0/ */

"use strict";

// Test stack.js.

function run_test() {
  const loader = new DevToolsLoader();
  const require = loader.require;

  const {
    StackFrameCache,
  } = require("resource://devtools/server/actors/utils/stack.js");

  const cache = new StackFrameCache();
  cache.initFrames();
  const baseFrame = {
    line: 23,
    column: 77,
    source: "nowhere",
    functionDisplayName: "nobody",
    parent: null,
    asyncParent: null,
    asyncCause: null,
  };
  cache.addFrame(baseFrame);

  let event = cache.makeEvent();
  Assert.equal(event[0], null);
  Assert.equal(event[1].functionDisplayName, "nobody");
  Assert.equal(event.length, 2);

  cache.addFrame({
    line: 24,
    column: 78,
    source: "nowhere",
    functionDisplayName: "still nobody",
    parent: null,
    asyncParent: baseFrame,
    asyncCause: "async",
  });

  event = cache.makeEvent();
  Assert.equal(event[0].functionDisplayName, "still nobody");
  Assert.equal(event[0].parent, 0);
  Assert.equal(event[0].asyncParent, 1);
  Assert.equal(event.length, 1);
}