DebugCallStack.cs 1.3 KB

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