DebugCallStack.cs 1.2 KB

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