GetSetPropertyDescriptor.cs 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  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 readonly string _message;
  40. private JsValue _thrower;
  41. public ThrowerPropertyDescriptor(Engine engine, PropertyFlag flags, string message)
  42. : base(flags)
  43. {
  44. _engine = engine;
  45. _message = message;
  46. }
  47. public override JsValue Get => _thrower ??= new ThrowTypeError(_engine, _message) { _prototype = _engine.Function.PrototypeObject};
  48. public override JsValue Set => _thrower ??= new ThrowTypeError(_engine, _message) { _prototype = _engine.Function.PrototypeObject};
  49. protected internal override JsValue CustomValue
  50. {
  51. set => ExceptionHelper.ThrowInvalidOperationException("making changes to throw type error property's descriptor is not allowed");
  52. }
  53. }
  54. }
  55. }