ClrFunctionInstance.cs 831 B

12345678910111213141516171819202122232425262728293031
  1. using System;
  2. using Jint.Native;
  3. using Jint.Native.Function;
  4. namespace Jint.Runtime.Interop
  5. {
  6. /// <summary>
  7. /// Wraps a Clr method into a FunctionInstance
  8. /// </summary>
  9. public sealed class ClrFunctionInstance<T> : FunctionInstance
  10. {
  11. private readonly Engine _engine;
  12. private readonly Func<T, object[], object> _func;
  13. public ClrFunctionInstance(Engine engine, Func<T, object[], object> func)
  14. : base(engine, null, null, null)
  15. {
  16. _engine = engine;
  17. _func = func;
  18. }
  19. public override object Call(object thisObject, object[] arguments)
  20. {
  21. // initialize Return flag
  22. _engine.CurrentExecutionContext.Return = Undefined.Instance;
  23. return _func((T) thisObject, arguments);
  24. }
  25. }
  26. }