frame.tsx 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  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') {
  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 =
  30. type === 'web'
  31. ? frameInfo.line === undefined && frameInfo.column === undefined
  32. : !!frameInfo.is_application;
  33. this.image = frameInfo.image;
  34. this.threadId = frameInfo.threadId;
  35. if (type === 'web') {
  36. // 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
  37. // most modern browser engines properly show anonymous functions when they are assigned to references (e.g. `let foo = function() {};`)
  38. if (!frameInfo.name) {
  39. this.name = t('anonymous');
  40. }
  41. // If the frame had no line or column, it was part of the native code, (e.g. calling String.fromCharCode)
  42. if (frameInfo.line === undefined && frameInfo.column === undefined) {
  43. this.name += ` ${t('[native code]')}`;
  44. }
  45. }
  46. }
  47. isRoot(): boolean {
  48. return this.name === Frame.Root.name;
  49. }
  50. }