ClrFunctionInstance.cs 795 B

1234567891011121314151617181920212223242526
  1. using System;
  2. using Jint.Native.Function;
  3. namespace Jint.Runtime.Interop
  4. {
  5. /// <summary>
  6. /// Wraps a Clr method into a FunctionInstance
  7. /// </summary>
  8. public sealed class ClrFunctionInstance<TObject, TResult> : FunctionInstance
  9. {
  10. private readonly Func<TObject, object[], TResult> _func;
  11. public ClrFunctionInstance(Engine engine, Func<TObject, object[], TResult> func)
  12. : base(engine, null, null, false)
  13. {
  14. _func = func;
  15. Prototype = engine.Function.PrototypeObject;
  16. }
  17. public override object Call(object thisObject, object[] arguments)
  18. {
  19. var result = _func((TObject) thisObject, arguments);
  20. return new Completion(Completion.Normal, result, null);
  21. }
  22. }
  23. }