DebugCallStack.cs 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. using System.Collections;
  2. using Esprima;
  3. using Jint.Native;
  4. using Jint.Runtime.CallStack;
  5. namespace Jint.Runtime.Debugger
  6. {
  7. public sealed class DebugCallStack : IReadOnlyList<CallFrame>
  8. {
  9. private readonly List<CallFrame> _stack;
  10. internal DebugCallStack(Engine engine, Location location, JintCallStack callStack, JsValue? returnValue)
  11. {
  12. _stack = new List<CallFrame>(callStack.Count + 1);
  13. var executionContext = new CallStackExecutionContext(engine.ExecutionContext);
  14. foreach (var element in callStack.Stack)
  15. {
  16. _stack.Add(new CallFrame(element, executionContext, location, returnValue));
  17. location = element.Location;
  18. returnValue = null;
  19. executionContext = element.CallingExecutionContext;
  20. }
  21. // Add root location
  22. _stack.Add(new CallFrame(null, executionContext, location, returnValue: null));
  23. }
  24. public CallFrame this[int index] => _stack[index];
  25. public int Count => _stack.Count;
  26. public IEnumerator<CallFrame> GetEnumerator()
  27. {
  28. return _stack.GetEnumerator();
  29. }
  30. IEnumerator IEnumerable.GetEnumerator()
  31. {
  32. return GetEnumerator();
  33. }
  34. }
  35. }