2
0

LazyPropertyDescriptor.cs 765 B

12345678910111213141516171819202122232425
  1. using System.Runtime.CompilerServices;
  2. using Jint.Native;
  3. namespace Jint.Runtime.Descriptors.Specialized
  4. {
  5. internal sealed class LazyPropertyDescriptor : PropertyDescriptor
  6. {
  7. private readonly object? _state;
  8. private readonly Func<object?, JsValue> _resolver;
  9. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  10. internal LazyPropertyDescriptor(object? state, Func<object?, JsValue> resolver, PropertyFlag flags)
  11. : base(null, flags | PropertyFlag.CustomJsValue)
  12. {
  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. }
  22. }