LazyPropertyDescriptor.cs 715 B

12345678910111213141516171819202122232425
  1. using System.Runtime.CompilerServices;
  2. using Jint.Native;
  3. namespace Jint.Runtime.Descriptors.Specialized;
  4. internal sealed class LazyPropertyDescriptor<T> : PropertyDescriptor
  5. {
  6. private readonly T _state;
  7. private readonly Func<T, JsValue> _resolver;
  8. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  9. internal LazyPropertyDescriptor(T state, Func<T, JsValue> resolver, PropertyFlag flags)
  10. : base(null, flags | PropertyFlag.CustomJsValue)
  11. {
  12. _flags &= ~PropertyFlag.NonData;
  13. _state = state;
  14. _resolver = resolver;
  15. }
  16. protected internal override JsValue? CustomValue
  17. {
  18. get => _value ??= _resolver(_state);
  19. set => _value = value;
  20. }
  21. }