CallFrame.cs 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. using Jint.Native;
  2. using Jint.Runtime.CallStack;
  3. using Environment = Jint.Runtime.Environments.Environment;
  4. namespace Jint.Runtime.Debugger
  5. {
  6. public sealed class CallFrame
  7. {
  8. private readonly CallStackExecutionContext _context;
  9. private SourceLocation _location;
  10. private readonly CallStackElement? _element;
  11. private readonly Lazy<DebugScopes> _scopeChain;
  12. internal CallFrame(
  13. CallStackElement? element,
  14. in CallStackExecutionContext context,
  15. in SourceLocation location,
  16. JsValue? returnValue)
  17. {
  18. _element = element;
  19. _context = context;
  20. _location = location;
  21. ReturnValue = returnValue;
  22. _scopeChain = new Lazy<DebugScopes>(() => new DebugScopes(Environment));
  23. }
  24. private Environment Environment => _context.LexicalEnvironment;
  25. // TODO: CallFrameId
  26. /// <summary>
  27. /// Name of the function of this call frame. For global scope, this will be "(anonymous)".
  28. /// </summary>
  29. public string FunctionName => _element?.ToString() ?? "(anonymous)";
  30. /// <summary>
  31. /// Source location of function of this call frame.
  32. /// </summary>
  33. /// <remarks>For top level (global) call frames, as well as functions not defined in script, this will be null.</remarks>
  34. public SourceLocation? FunctionLocation => (_element?.Function._functionDefinition?.Function as Node)?.Location;
  35. /// <summary>
  36. /// Currently executing source location in this call frame.
  37. /// </summary>
  38. public ref SourceLocation Location => ref _location;
  39. /// <summary>
  40. /// The scope chain of this call frame.
  41. /// </summary>
  42. public DebugScopes ScopeChain => _scopeChain.Value;
  43. /// <summary>
  44. /// The value of <c>this</c> in this call frame.
  45. /// </summary>
  46. public JsValue This
  47. {
  48. get
  49. {
  50. var environment = _context.GetThisEnvironment();
  51. return environment.GetThisBinding();
  52. }
  53. }
  54. /// <summary>
  55. /// The return value of this call frame. Will be null for call frames that aren't at the top of the stack,
  56. /// as well as if execution is not at a return point.
  57. /// </summary>
  58. public JsValue? ReturnValue { get; }
  59. }
  60. }