GetSetPropertyDescriptor.cs 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. using Jint.Native;
  2. using Jint.Native.Function;
  3. namespace Jint.Runtime.Descriptors
  4. {
  5. public sealed class GetSetPropertyDescriptor : PropertyDescriptor
  6. {
  7. private JsValue _get;
  8. private JsValue _set;
  9. public GetSetPropertyDescriptor(JsValue get, JsValue set, bool? enumerable = null, bool? configurable = null)
  10. : base(null, writable: null, enumerable: enumerable, configurable: configurable)
  11. {
  12. _get = get;
  13. _set = set;
  14. }
  15. internal GetSetPropertyDescriptor(JsValue get, JsValue set, PropertyFlag flags)
  16. : base(null, flags)
  17. {
  18. _get = get;
  19. _set = set;
  20. }
  21. public GetSetPropertyDescriptor(PropertyDescriptor descriptor) : base(descriptor)
  22. {
  23. _get = descriptor.Get;
  24. _set = descriptor.Set;
  25. }
  26. public override JsValue Get => _get;
  27. public override JsValue Set => _set;
  28. internal void SetGet(JsValue getter)
  29. {
  30. _get = getter;
  31. }
  32. internal void SetSet(JsValue setter)
  33. {
  34. _set = setter;
  35. }
  36. internal sealed class ThrowerPropertyDescriptor : PropertyDescriptor
  37. {
  38. private readonly Engine _engine;
  39. private JsValue _thrower;
  40. public ThrowerPropertyDescriptor(Engine engine, PropertyFlag flags) : base(flags)
  41. {
  42. _engine = engine;
  43. }
  44. public override JsValue Get => _thrower ??= _engine.Realm.Intrinsics.ThrowTypeError;
  45. public override JsValue Set => _thrower ??= _engine.Realm.Intrinsics.ThrowTypeError;
  46. protected internal override JsValue CustomValue
  47. {
  48. set => ExceptionHelper.ThrowInvalidOperationException("making changes to throw type error property's descriptor is not allowed");
  49. }
  50. }
  51. }
  52. }