2
0

JsSymbol.cs 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. using System.Runtime.CompilerServices;
  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 JsValue _value;
  11. internal JsSymbol(string value) : this(new JsString(value))
  12. {
  13. }
  14. internal JsSymbol(JsValue value) : base(Types.Symbol)
  15. {
  16. _value = value;
  17. }
  18. public override object ToObject()
  19. {
  20. return _value;
  21. }
  22. /// <summary>
  23. /// https://tc39.es/ecma262/#sec-symboldescriptivestring
  24. /// </summary>
  25. public override string ToString()
  26. {
  27. var value = _value.IsUndefined() ? "" : _value.AsString();
  28. return "Symbol(" + value + ")";
  29. }
  30. public override bool Equals(JsValue? obj)
  31. {
  32. return Equals(obj as JsSymbol);
  33. }
  34. public bool Equals(JsSymbol? other)
  35. {
  36. return ReferenceEquals(this, other);
  37. }
  38. public override int GetHashCode()
  39. {
  40. return RuntimeHelpers.GetHashCode(this);
  41. }
  42. }
  43. }