2
0

DebugCallStack.cs 1.3 KB

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