DebugScope.cs 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. using System;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. using Jint.Native;
  5. using Jint.Runtime.Environments;
  6. namespace Jint.Runtime.Debugger
  7. {
  8. /// <summary>
  9. /// Scope information, bindings, and values for a single scope in the scope chain
  10. /// </summary>
  11. public sealed class DebugScope
  12. {
  13. private readonly EnvironmentRecord _record;
  14. private readonly List<string> _bindingNames;
  15. internal DebugScope(DebugScopeType type, EnvironmentRecord record, List<string> bindingNames, bool isTopLevel)
  16. {
  17. ScopeType = type;
  18. _record = record;
  19. _bindingNames = bindingNames;
  20. IsTopLevel = isTopLevel;
  21. }
  22. /// <summary>
  23. /// The type of scope. Scope types are the same as defined by Chrome devtools protocol.
  24. /// </summary>
  25. public DebugScopeType ScopeType { get; }
  26. /// <summary>
  27. /// For <see cref="DebugScopeType.Block">block</see> scopes, indicates whether this scope is at the top level of a containing function.
  28. /// </summary>
  29. /// <remarks>
  30. /// Block scopes at the top level of a function are combined with Local scope in Chromium and devtools protocol.
  31. /// This property facilitates implementing the same "flattening" in e.g. a UI. Because empty scopes are excluded in the scope chain,
  32. /// top level cannot be determined from the scope chain order alone.
  33. /// </remarks>
  34. public bool IsTopLevel { get; }
  35. /// <summary>
  36. /// Names of all non-shadowed bindings in the scope.
  37. /// </summary>
  38. public IReadOnlyList<string> BindingNames => _bindingNames;
  39. /// <summary>
  40. /// Retrieves the value of a specific binding. Note that some bindings (e.g. uninitialized let) may return null.
  41. /// </summary>
  42. /// <param name="name">Binding name</param>
  43. /// <returns>Value of the binding</returns>
  44. public JsValue GetBindingValue(string name)
  45. {
  46. return _record.GetBindingValue(name, strict: false);
  47. }
  48. }
  49. }