EnvironmentRecord.cs 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. using Jint.Native;
  2. namespace Jint.Runtime.Environments
  3. {
  4. /// <summary>
  5. /// Base implementation of an Environment Record
  6. /// http://www.ecma-international.org/ecma-262/5.1/#sec-10.2.1
  7. /// </summary>
  8. public abstract class EnvironmentRecord : JsValue
  9. {
  10. protected readonly Engine _engine;
  11. protected EnvironmentRecord(Engine engine) : base(Types.Object)
  12. {
  13. _engine = engine;
  14. }
  15. /// <summary>
  16. /// Determines if an environment record has a binding for an identifier.
  17. /// </summary>
  18. /// <param name="name">The identifier of the binding</param>
  19. /// <returns><c>true</c> if it does and <c>false</c> if it does not.</returns>
  20. public abstract bool HasBinding(in Key name);
  21. internal abstract bool TryGetBinding(
  22. in Key name,
  23. bool strict,
  24. out Binding binding,
  25. out JsValue value);
  26. /// <summary>
  27. /// Creates a new mutable binding in an environment record.
  28. /// </summary>
  29. /// <param name="name">The identifier of the binding.</param>
  30. /// <param name="value">The value of the binding.</param>
  31. /// <param name="canBeDeleted"><c>true</c> if the binding may be subsequently deleted.</param>
  32. public abstract void CreateMutableBinding(in Key name, JsValue value, bool canBeDeleted = false);
  33. /// <summary>
  34. /// Sets the value of an already existing mutable binding in an environment record.
  35. /// </summary>
  36. /// <param name="name">The identifier of the binding</param>
  37. /// <param name="value">The value of the binding.</param>
  38. /// <param name="strict">The identify strict mode references.</param>
  39. public abstract void SetMutableBinding(in Key name, JsValue value, bool strict);
  40. /// <summary>
  41. /// Returns the value of an already existing binding from an environment record.
  42. /// </summary>
  43. /// <param name="name">The identifier of the binding</param>
  44. /// <param name="strict">The identify strict mode references.</param>
  45. /// <return>The value of an already existing binding from an environment record.</return>
  46. public abstract JsValue GetBindingValue(in Key name, bool strict);
  47. /// <summary>
  48. /// Delete a binding from an environment record. The String value N is the text of the bound name If a binding for N exists, remove the binding and return true. If the binding exists but cannot be removed return false. If the binding does not exist return true.
  49. /// </summary>
  50. /// <param name="name">The identifier of the binding</param>
  51. /// <returns><true>true</true> if the deletion is successfull.</returns>
  52. public abstract bool DeleteBinding(in Key name);
  53. /// <summary>
  54. /// Returns the value to use as the <c>this</c> value on calls to function objects that are obtained as binding values from this environment record.
  55. /// </summary>
  56. /// <returns>The value to use as <c>this</c>.</returns>
  57. public abstract JsValue ImplicitThisValue();
  58. /// <summary>
  59. /// Returns an array of all the defined binding names
  60. /// </summary>
  61. /// <returns>The array of all defined bindings</returns>
  62. public abstract string[] GetAllBindingNames();
  63. public override object ToObject()
  64. {
  65. ExceptionHelper.ThrowNotSupportedException();
  66. return null;
  67. }
  68. public override bool Equals(JsValue other)
  69. {
  70. ExceptionHelper.ThrowNotSupportedException();
  71. return false;
  72. }
  73. /// <summary>
  74. /// Informs whether arguments instance was accessed and maybe thus stored,
  75. /// which makes it unsuitable for pooling and reuse.
  76. /// </summary>
  77. internal abstract void FunctionWasCalled();
  78. }
  79. }