Reference.cs 1.6 KB

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