PropertyDescriptor.cs 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. namespace Jint.Runtime.Descriptors
  2. {
  3. /// <summary>
  4. /// An element of a javascript object
  5. /// </summary>
  6. public abstract class PropertyDescriptor
  7. {
  8. public static PropertyDescriptor Undefined = new UndefinedPropertyDescriptor();
  9. /// <summary>
  10. /// If true, the property will be enumerated by a for-in
  11. /// enumeration (see 12.6.4). Otherwise, the property is said
  12. /// to be non-enumerable.
  13. /// </summary>
  14. public bool Enumerable { get; set; }
  15. /// <summary>
  16. /// If false, attempts to delete the property, change the
  17. /// property to be a data property, or change its attributes will
  18. /// fail.
  19. /// </summary>
  20. public bool Configurable { get; set; }
  21. /// <summary>
  22. /// http://www.ecma-international.org/ecma-262/5.1/#sec-8.10.1
  23. /// </summary>
  24. /// <returns></returns>
  25. public abstract bool IsAccessorDescriptor();
  26. /// <summary>
  27. /// http://www.ecma-international.org/ecma-262/5.1/#sec-8.10.2
  28. /// </summary>
  29. /// <returns></returns>
  30. public abstract bool IsDataDescriptor();
  31. /// <summary>
  32. /// http://www.ecma-international.org/ecma-262/5.1/#sec-8.10.3
  33. /// </summary>
  34. /// <returns></returns>
  35. public bool IsGenericDescriptor()
  36. {
  37. return !IsDataDescriptor() && !IsAccessorDescriptor();
  38. }
  39. public T As<T>() where T : PropertyDescriptor
  40. {
  41. return (T)this;
  42. }
  43. /// <summary>
  44. /// Local implementation used to create a singleton representing
  45. /// an undefined result of a PropertyDescriptor. This prevents the rest
  46. /// of the code to return 'object' in order to be able to return
  47. /// Undefined.Instance
  48. /// </summary>
  49. internal sealed class UndefinedPropertyDescriptor : PropertyDescriptor
  50. {
  51. public override bool IsAccessorDescriptor()
  52. {
  53. throw new System.NotImplementedException();
  54. }
  55. public override bool IsDataDescriptor()
  56. {
  57. throw new System.NotImplementedException();
  58. }
  59. }
  60. }
  61. }