Reference.cs 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. using System;
  2. using Jint.Native;
  3. using Jint.Runtime.Environments;
  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 sealed class Reference
  11. {
  12. private JsValue _baseValue;
  13. private string _name;
  14. private bool _strict;
  15. public Reference(JsValue baseValue, string name, bool strict)
  16. {
  17. _baseValue = baseValue;
  18. _name = name;
  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 HasPrimitiveBase() || (_baseValue.IsObject() && !(_baseValue is EnvironmentRecord));
  44. }
  45. internal Reference Reassign(JsValue baseValue, string name, bool strict)
  46. {
  47. _baseValue = baseValue;
  48. _name = name;
  49. _strict = strict;
  50. return this;
  51. }
  52. }
  53. }