tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

StackTrace.js (2476B)


      1 /* This Source Code Form is subject to the terms of the Mozilla Public
      2 * License, v. 2.0. If a copy of the MPL was not distributed with this file,
      3 * You can obtain one at http://mozilla.org/MPL/2.0/. */
      4 
      5 "use strict";
      6 
      7 const {
      8  Component,
      9  createFactory,
     10 } = require("resource://devtools/client/shared/vendor/react.mjs");
     11 const PropTypes = require("resource://devtools/client/shared/vendor/react-prop-types.mjs");
     12 const dom = require("resource://devtools/client/shared/vendor/react-dom-factories.js");
     13 const { LocalizationHelper } = require("resource://devtools/shared/l10n.js");
     14 const Frame = createFactory(
     15  require("resource://devtools/client/shared/components/Frame.js")
     16 );
     17 
     18 const l10n = new LocalizationHelper(
     19  "devtools/client/locales/webconsole.properties"
     20 );
     21 
     22 class AsyncFrameClass extends Component {
     23  static get propTypes() {
     24    return {
     25      asyncCause: PropTypes.string.isRequired,
     26    };
     27  }
     28 
     29  render() {
     30    const { asyncCause } = this.props;
     31 
     32    return dom.span(
     33      { className: "frame-link-async-cause" },
     34      l10n.getFormatStr("stacktrace.asyncStack", asyncCause)
     35    );
     36  }
     37 }
     38 
     39 class StackTrace extends Component {
     40  static get propTypes() {
     41    return {
     42      stacktrace: PropTypes.array.isRequired,
     43      onViewSourceInDebugger: PropTypes.func.isRequired,
     44      // Service to enable the source map feature.
     45      sourceMapURLService: PropTypes.object,
     46    };
     47  }
     48 
     49  render() {
     50    const { stacktrace, onViewSourceInDebugger, sourceMapURLService } =
     51      this.props;
     52 
     53    if (!stacktrace || !stacktrace.length) {
     54      return null;
     55    }
     56 
     57    const frames = [];
     58    stacktrace.forEach((s, i) => {
     59      if (s.asyncCause) {
     60        frames.push(
     61          "\t",
     62          AsyncFrame({
     63            key: `${i}-asyncframe`,
     64            asyncCause: s.asyncCause,
     65          }),
     66          "\n"
     67        );
     68      }
     69 
     70      frames.push(
     71        "\t",
     72        Frame({
     73          key: `${i}-frame`,
     74          frame: {
     75            functionDisplayName: s.functionName,
     76            source: s.filename,
     77            line: s.lineNumber,
     78            column: s.columnNumber,
     79          },
     80          showFunctionName: true,
     81          showAnonymousFunctionName: true,
     82          showFullSourceUrl: true,
     83          onClick: onViewSourceInDebugger,
     84          sourceMapURLService,
     85        }),
     86        "\n"
     87      );
     88    });
     89 
     90    return dom.div({ className: "stack-trace" }, frames);
     91  }
     92 }
     93 
     94 const AsyncFrame = createFactory(AsyncFrameClass);
     95 
     96 module.exports = StackTrace;