2
0

LazyPropertyDescriptor.cs 667 B

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