JsSymbol.cs 1.1 KB

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