summaryrefslogtreecommitdiffstats
path: root/devtools/client/debugger/new/panel.js
blob: 62d4a9f4f6dc5da25cbe0f66b5759e6644049922 (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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
/* 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/. */
"use strict";

const { Task } = require("devtools/shared/task");
var {LocalizationHelper} = require("devtools/shared/l10n");

const DBG_STRINGS_URI = "devtools/client/locales/debugger.properties";
var L10N = new LocalizationHelper(DBG_STRINGS_URI);

function DebuggerPanel(iframeWindow, toolbox) {
  this.panelWin = iframeWindow;
  this.panelWin.L10N = L10N;
  this.toolbox = toolbox;
}

DebuggerPanel.prototype = {
  open: Task.async(function* () {
    if (!this.toolbox.target.isRemote) {
      yield this.toolbox.target.makeRemote();
    }

    yield this.panelWin.Debugger.bootstrap({
      threadClient: this.toolbox.threadClient,
      tabTarget: this.toolbox.target
    });

    this.isReady = true;
    return this;
  }),

  _store: function () {
    return this.panelWin.Debugger.store;
  },

  _getState: function () {
    return this._store().getState();
  },

  _actions: function () {
    return this.panelWin.Debugger.actions;
  },

  _selectors: function () {
    return this.panelWin.Debugger.selectors;
  },

  getFrames: function () {
    let frames = this._selectors().getFrames(this._getState());

    // Frames is null when the debugger is not paused.
    if (!frames) {
      return {
        frames: [],
        selected: -1
      };
    }

    frames = frames.toJS();
    const selectedFrame = this._selectors().getSelectedFrame(this._getState());
    const selected = frames.findIndex(frame => frame.id == selectedFrame.id);

    frames.forEach(frame => {
      frame.actor = frame.id;
    });

    return { frames, selected };
  },

  destroy: function () {
    this.panelWin.Debugger.destroy();
    this.emit("destroyed");
  }
};

exports.DebuggerPanel = DebuggerPanel;