Reference.cs 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. using System;
  2. using Jint.Native;
  3. using Jint.Native.Object;
  4. namespace Jint.Runtime.References
  5. {
  6. /// <summary>
  7. /// Represents the Reference Specification Type
  8. /// http://www.ecma-international.org/ecma-262/5.1/#sec-8.7
  9. /// </summary>
  10. public class Reference
  11. {
  12. private readonly object _baseValue;
  13. private readonly string _name;
  14. private readonly bool _strict;
  15. public Reference(object baseValue, string name, bool strict)
  16. {
  17. _baseValue = baseValue;
  18. _name = name;
  19. _strict = strict;
  20. }
  21. public object GetBase()
  22. {
  23. return _baseValue;
  24. }
  25. public string GetReferencedName()
  26. {
  27. return _name;
  28. }
  29. public bool IsStrict()
  30. {
  31. return _strict;
  32. }
  33. public bool HasPrimitiveBase()
  34. {
  35. var type = TypeConverter.GetType(_baseValue);
  36. return (type == Types.Boolean)
  37. || (type == Types.String)
  38. || (type == Types.Number)
  39. ;
  40. }
  41. public bool IsUnresolvableReference()
  42. {
  43. return _baseValue == Undefined.Instance || _baseValue == Null.Instance;
  44. }
  45. public bool IsPropertyReference()
  46. {
  47. // http://www.ecma-international.org/ecma-262/5.1/#sec-8.7
  48. return _baseValue is ObjectInstance || HasPrimitiveBase();
  49. }
  50. }
  51. }