JsSymbol.cs 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. using System;
  2. using Jint.Runtime;
  3. namespace Jint.Native
  4. {
  5. /// <summary>
  6. /// The _object value of a <see cref="JsSymbol"/> is the [[Description]] internal slot.
  7. /// </summary>
  8. public sealed class JsSymbol : JsValue, IEquatable<JsSymbol>
  9. {
  10. internal readonly string _value;
  11. public JsSymbol(string value) : base(Types.Symbol)
  12. {
  13. _value = value;
  14. }
  15. public override object ToObject()
  16. {
  17. return _value;
  18. }
  19. public override bool Equals(JsValue obj)
  20. {
  21. if (ReferenceEquals(null, obj))
  22. {
  23. return false;
  24. }
  25. if (!(obj is JsBoolean number))
  26. {
  27. return false;
  28. }
  29. return Equals(number);
  30. }
  31. public bool Equals(JsSymbol other)
  32. {
  33. if (ReferenceEquals(null, other))
  34. {
  35. return false;
  36. }
  37. if (ReferenceEquals(this, other))
  38. {
  39. return true;
  40. }
  41. return _value == other._value;
  42. }
  43. public override int GetHashCode()
  44. {
  45. return _value.GetHashCode();
  46. }
  47. }
  48. }