stack-trace.js 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  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. "use strict";
  5. const React = require("devtools/client/shared/vendor/react");
  6. const { DOM: dom, createClass, createFactory, PropTypes } = React;
  7. const { LocalizationHelper } = require("devtools/shared/l10n");
  8. const Frame = createFactory(require("./frame"));
  9. const l10n = new LocalizationHelper("devtools/client/locales/webconsole.properties");
  10. const AsyncFrame = createFactory(createClass({
  11. displayName: "AsyncFrame",
  12. PropTypes: {
  13. asyncCause: PropTypes.string.isRequired
  14. },
  15. render() {
  16. let { asyncCause } = this.props;
  17. return dom.span(
  18. { className: "frame-link-async-cause" },
  19. l10n.getFormatStr("stacktrace.asyncStack", asyncCause)
  20. );
  21. }
  22. }));
  23. const StackTrace = createClass({
  24. displayName: "StackTrace",
  25. PropTypes: {
  26. stacktrace: PropTypes.array.isRequired,
  27. onViewSourceInDebugger: PropTypes.func.isRequired
  28. },
  29. render() {
  30. let { stacktrace, onViewSourceInDebugger } = this.props;
  31. let frames = [];
  32. stacktrace.forEach(s => {
  33. if (s.asyncCause) {
  34. frames.push("\t", AsyncFrame({
  35. asyncCause: s.asyncCause
  36. }), "\n");
  37. }
  38. frames.push("\t", Frame({
  39. frame: {
  40. functionDisplayName: s.functionName,
  41. source: s.filename.split(" -> ").pop(),
  42. line: s.lineNumber,
  43. column: s.columnNumber,
  44. },
  45. showFunctionName: true,
  46. showAnonymousFunctionName: true,
  47. showFullSourceUrl: true,
  48. onClick: onViewSourceInDebugger
  49. }), "\n");
  50. });
  51. return dom.div({ className: "stack-trace" }, frames);
  52. }
  53. });
  54. module.exports = StackTrace;