CallFrame.cs 2.3 KB

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