CallFrame.cs 2.2 KB

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