2
0

Engine.Advanced.cs 2.0 KB

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