JsSymbol.cs 968 B

12345678910111213141516171819202122232425262728293031323334353637
  1. using System.Runtime.CompilerServices;
  2. using Jint.Runtime;
  3. namespace Jint.Native;
  4. public sealed class JsSymbol : JsValue, IEquatable<JsSymbol>
  5. {
  6. internal readonly JsValue _value;
  7. internal JsSymbol(string value) : this(new JsString(value))
  8. {
  9. }
  10. internal JsSymbol(JsValue value) : base(Types.Symbol)
  11. {
  12. _value = value;
  13. }
  14. public override object ToObject() => _value;
  15. /// <summary>
  16. /// https://tc39.es/ecma262/#sec-symboldescriptivestring
  17. /// </summary>
  18. public override string ToString()
  19. {
  20. var value = _value.IsUndefined() ? "" : _value.AsString();
  21. return "Symbol(" + value + ")";
  22. }
  23. public override bool Equals(object? obj) => Equals(obj as JsSymbol);
  24. public override bool Equals(JsValue? other) => Equals(other as JsSymbol);
  25. public bool Equals(JsSymbol? other) => ReferenceEquals(this, other);
  26. public override int GetHashCode() => RuntimeHelpers.GetHashCode(this);
  27. }