frame.tsx 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. import {t} from 'sentry/locale';
  2. import {WeightedNode} from './weightedNode';
  3. export class Frame extends WeightedNode {
  4. readonly key: string | number;
  5. readonly name: string;
  6. readonly file?: string;
  7. readonly line?: number;
  8. readonly column?: number;
  9. readonly is_application: boolean;
  10. readonly image?: string;
  11. readonly resource?: string;
  12. readonly threadId?: number;
  13. static Root = new Frame(
  14. {
  15. key: 'sentry root',
  16. name: 'sentry root',
  17. is_application: false,
  18. },
  19. 'mobile'
  20. );
  21. constructor(frameInfo: Profiling.FrameInfo, type?: 'mobile' | 'web' | 'node') {
  22. super();
  23. this.key = frameInfo.key;
  24. this.file = frameInfo.file;
  25. this.name = frameInfo.name;
  26. this.resource = frameInfo.resource;
  27. this.line = frameInfo.line;
  28. this.column = frameInfo.column;
  29. this.is_application = !!frameInfo.is_application;
  30. this.image = frameInfo.image;
  31. this.threadId = frameInfo.threadId;
  32. // We are remapping some of the keys as they differ between platforms.
  33. // This is a temporary solution until we adopt a unified format.
  34. if (frameInfo.columnNumber && this.column === undefined) {
  35. this.column = frameInfo.columnNumber;
  36. }
  37. if (frameInfo.lineNumber && this.column === undefined) {
  38. this.line = frameInfo.lineNumber;
  39. }
  40. if (frameInfo.scriptName && this.column === undefined) {
  41. this.resource = frameInfo.scriptName;
  42. }
  43. // If the frame is a web frame and there is no name associated to it, then it was likely invoked as an iife or anonymous callback as
  44. // most modern browser engines properly show anonymous functions when they are assigned to references (e.g. `let foo = function() {};`)
  45. if (type === 'web' || type === 'node') {
  46. if (!this.name || this.name.startsWith('unknown ')) {
  47. this.name = t('<anonymous>');
  48. }
  49. // If the frame had no line or column, it was part of the native code, (e.g. calling String.fromCharCode)
  50. if (this.line === undefined && this.column === undefined) {
  51. this.name += ` ${t('[native code]')}`;
  52. }
  53. }
  54. if (!this.name) {
  55. this.name = t('<unknown>');
  56. }
  57. }
  58. isRoot(): boolean {
  59. return this.name === Frame.Root.name;
  60. }
  61. }