Engine.Advanced.cs 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. using Jint.Native.Promise;
  2. namespace Jint;
  3. public partial class Engine
  4. {
  5. public AdvancedOperations Advanced { get; }
  6. }
  7. public class AdvancedOperations
  8. {
  9. private readonly Engine _engine;
  10. public AdvancedOperations(Engine engine)
  11. {
  12. _engine = engine;
  13. }
  14. /// <summary>
  15. /// Gets current stack trace that is active in engine.
  16. /// </summary>
  17. public string StackTrace
  18. {
  19. get
  20. {
  21. var lastSyntaxElement = _engine._lastSyntaxElement;
  22. if (lastSyntaxElement is null)
  23. {
  24. return string.Empty;
  25. }
  26. return _engine.CallStack.BuildCallStackString(lastSyntaxElement.Location);
  27. }
  28. }
  29. /// <summary>
  30. /// Initializes list of references of called functions
  31. /// </summary>
  32. public void ResetCallStack()
  33. {
  34. _engine.ResetCallStack();
  35. }
  36. /// <summary>
  37. /// Forcefully processes the current task queues (micro and regular), this API may break and change behavior!
  38. /// </summary>
  39. public void ProcessTasks()
  40. {
  41. _engine.RunAvailableContinuations();
  42. }
  43. /// <summary>
  44. /// EXPERIMENTAL! Subject to change.
  45. ///
  46. /// Registers a promise within the currently running EventLoop (has to be called within "ExecuteWithEventLoop" call).
  47. /// Note that ExecuteWithEventLoop will not trigger "onFinished" callback until ALL manual promises are settled.
  48. ///
  49. /// NOTE: that resolve and reject need to be called withing the same thread as "ExecuteWithEventLoop".
  50. /// The API assumes that the Engine is called from a single thread.
  51. /// </summary>
  52. /// <returns>a Promise instance and functions to either resolve or reject it</returns>
  53. public ManualPromise RegisterPromise()
  54. {
  55. return _engine.RegisterPromise();
  56. }
  57. }