DelegateWrapper.cs 892 B

1234567891011121314151617181920212223242526272829303132
  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)
  15. {
  16. _engine = engine;
  17. _d = d;
  18. }
  19. public override object Call(object thisObject, object[] arguments)
  20. {
  21. // initialize Return flag
  22. _engine.CurrentExecutionContext.Return = Undefined.Instance;
  23. _d.DynamicInvoke(arguments);
  24. return _engine.CurrentExecutionContext.Return;
  25. }
  26. }
  27. }