DebugScope.cs 2.0 KB

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