Reference.cs 1.6 KB

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