JsSymbol.cs 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  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. private readonly Key _key;
  13. internal JsSymbol(string value, int identity) : base(Types.Symbol)
  14. {
  15. _value = value;
  16. _key = new Key(_value, identity);
  17. }
  18. internal JsSymbol(JsValue value, int identity) : this(value.IsUndefined() ? "" : value.ToString(), identity)
  19. {
  20. }
  21. public override object ToObject()
  22. {
  23. return _value;
  24. }
  25. internal override Key ToPropertyKey()
  26. {
  27. return _key;
  28. }
  29. public override string ToString()
  30. {
  31. return "Symbol(" + _value + ")";
  32. }
  33. public override bool Equals(JsValue obj)
  34. {
  35. return Equals(obj as JsSymbol);
  36. }
  37. public bool Equals(JsSymbol other)
  38. {
  39. return other != null && other._key == _key;
  40. }
  41. public override int GetHashCode()
  42. {
  43. return RuntimeHelpers.GetHashCode(this);
  44. }
  45. }
  46. }