LazyPropertyDescriptor.cs 810 B

1234567891011121314151617181920212223242526
  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. _flags &= ~PropertyFlag.NonData;
  14. _state = state;
  15. _resolver = resolver;
  16. }
  17. protected internal override JsValue? CustomValue
  18. {
  19. get => _value ??= _resolver(_state);
  20. set => _value = value;
  21. }
  22. }
  23. }