summaryrefslogtreecommitdiffstats
path: root/devtools/client/debugger/test/mochitest/browser_dbg-merge-scopes.js
blob: 48dfd26a48a9b5c23983d79b7073885bebbf6bbe (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
/* This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at <http://mozilla.org/MPL/2.0/>. */

// Test that adjacent scopes are merged together as expected.

"use strict";

add_task(async function () {
  const dbg = await initDebugger("doc-merge-scopes.html");

  invokeInTab("run");
  await waitForPaused(dbg, "doc-merge-scopes.html");

  // Function body and function lexical scopes are merged together.
  expectLabels(dbg, ["first", "<this>", "arguments", "x", "y", "z"]);

  await resume(dbg);
  await waitForPaused(dbg);

  // Function body and inner lexical scopes are not merged together.
  await toggleScopeNode(dbg, 4);
  expectLabels(dbg, ["Block", "<this>", "y", "second", "arguments", "x"]);

  await resume(dbg);
  await waitForPaused(dbg);

  // When there is a function body, function lexical, and inner lexical scope,
  // the first two are merged together.
  await toggleScopeNode(dbg, 4);
  expectLabels(dbg, [
    "Block",
    "<this>",
    "z",
    "third",
    "arguments",
    "v",
    "x",
    "y",
  ]);
});

function expectLabels(dbg, array) {
  for (let i = 0; i < array.length; i++) {
    is(
      getScopeNodeLabel(dbg, i + 1),
      array[i],
      `Correct label ${array[i]} for index ${i + 1}`
    );
  }
}