ClrFunctionInstance.cs 1018 B

1234567891011121314151617181920212223242526272829303132
  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 ClrFunctionInstance(Engine engine, Func<TObject, object[], TResult> func, int length)
  18. : this(engine, func)
  19. {
  20. FastAddProperty("length", length, false, false, false);
  21. }
  22. public override object Call(object thisObject, object[] arguments)
  23. {
  24. var result = _func((TObject) thisObject, arguments);
  25. return new Completion(Completion.Normal, result, null);
  26. }
  27. }
  28. }