JsSymbol.cs 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  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. /// <summary>
  24. /// https://tc39.es/ecma262/#sec-symboldescriptivestring
  25. /// </summary>
  26. public override string ToString()
  27. {
  28. var value = _value.IsUndefined() ? "" : _value.AsString();
  29. return "Symbol(" + value + ")";
  30. }
  31. public override bool Equals(JsValue obj)
  32. {
  33. return Equals(obj as JsSymbol);
  34. }
  35. public bool Equals(JsSymbol other)
  36. {
  37. return ReferenceEquals(this, other);
  38. }
  39. public override int GetHashCode()
  40. {
  41. return RuntimeHelpers.GetHashCode(this);
  42. }
  43. }
  44. }