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 JsValue _value;
  12. internal JsSymbol(string value) : this(new JsString(value))
  13. {
  14. }
  15. internal JsSymbol(JsValue value) : base(Types.Symbol)
  16. {
  17. _value = value;
  18. }
  19. public override object ToObject()
  20. {
  21. return _value;
  22. }
  23. public override string ToString()
  24. {
  25. var value = _value.IsUndefined() ? "" : _value.AsString();
  26. return "Symbol(" + value + ")";
  27. }
  28. public override bool Equals(JsValue obj)
  29. {
  30. return Equals(obj as JsSymbol);
  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. }