DelegateWrapper.cs 808 B

12345678910111213141516171819202122232425262728
  1. using System;
  2. using Jint.Native;
  3. using Jint.Native.Function;
  4. namespace Jint.Runtime.Interop
  5. {
  6. /// <summary>
  7. /// Represents a FunctionInstance wrapper around a CLR method. This is used by user to pass
  8. /// custom methods to the engine.
  9. /// </summary>
  10. public sealed class DelegateWrapper : FunctionInstance
  11. {
  12. private readonly Engine _engine;
  13. private readonly Delegate _d;
  14. public DelegateWrapper(Engine engine, Delegate d) : base(engine, null, null, null, false)
  15. {
  16. _engine = engine;
  17. _d = d;
  18. }
  19. public override object Call(object thisObject, object[] arguments)
  20. {
  21. var result = _d.DynamicInvoke(arguments);
  22. return new Completion(Completion.Normal, result, null);
  23. }
  24. }
  25. }