ConstantValueAccessor.cs 1013 B

1234567891011121314151617181920212223242526272829303132333435
  1. using Jint.Native;
  2. using Jint.Runtime.Descriptors;
  3. namespace Jint.Runtime.Interop.Reflection;
  4. internal sealed class ConstantValueAccessor : ReflectionAccessor
  5. {
  6. public static readonly ConstantValueAccessor NullAccessor = new(null);
  7. public ConstantValueAccessor(JsValue? value) : base(null!, null!)
  8. {
  9. ConstantValue = value;
  10. }
  11. public override bool Writable => false;
  12. protected override JsValue? ConstantValue { get; }
  13. protected override object? DoGetValue(object target, string memberName)
  14. {
  15. return ConstantValue;
  16. }
  17. protected override void DoSetValue(object target, string memberName, object? value)
  18. {
  19. throw new InvalidOperationException();
  20. }
  21. public override PropertyDescriptor CreatePropertyDescriptor(Engine engine, object target, string memberName, bool enumerable = true)
  22. {
  23. return ConstantValue is null
  24. ? PropertyDescriptor.Undefined
  25. : new(ConstantValue, PropertyFlag.AllForbidden);
  26. }
  27. }