Reference.cs 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. using Jint.Native;
  2. using Jint.Runtime.Environments;
  3. namespace Jint.Runtime.References
  4. {
  5. /// <summary>
  6. /// Represents the Reference Specification Type
  7. /// http://www.ecma-international.org/ecma-262/5.1/#sec-8.7
  8. /// </summary>
  9. public class Reference
  10. {
  11. private readonly JsValue _baseValue;
  12. private readonly string _name;
  13. private readonly bool _strict;
  14. public Reference(JsValue baseValue, string name, bool strict)
  15. {
  16. _baseValue = baseValue;
  17. _name = name;
  18. _strict = strict;
  19. }
  20. public JsValue GetBase()
  21. {
  22. return _baseValue;
  23. }
  24. public string GetReferencedName()
  25. {
  26. return _name;
  27. }
  28. public bool IsStrict()
  29. {
  30. return _strict;
  31. }
  32. public bool HasPrimitiveBase()
  33. {
  34. return _baseValue.IsPrimitive();
  35. }
  36. public bool IsUnresolvableReference()
  37. {
  38. return _baseValue.IsUndefined();
  39. }
  40. public bool IsPropertyReference()
  41. {
  42. // http://www.ecma-international.org/ecma-262/5.1/#sec-8.7
  43. return (_baseValue.IsObject() && !_baseValue.Is<EnvironmentRecord>()) || HasPrimitiveBase();
  44. }
  45. }
  46. }