JsrtRuntime.h 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. //-------------------------------------------------------------------------------------------------------
  2. // Copyright (C) Microsoft. All rights reserved.
  3. // Licensed under the MIT license. See LICENSE.txt file in the project root for full license information.
  4. //-------------------------------------------------------------------------------------------------------
  5. #pragma once
  6. #include "ChakraCore.h"
  7. #include "JsrtThreadService.h"
  8. #ifdef ENABLE_SCRIPT_DEBUGGING
  9. #include "JsrtDebugManager.h"
  10. #endif
  11. class JsrtContext;
  12. class JsrtRuntime
  13. {
  14. friend class JsrtContext;
  15. public:
  16. JsrtRuntime(ThreadContext * threadContext, bool useIdle, bool dispatchExceptions);
  17. ~JsrtRuntime();
  18. ThreadContext * GetThreadContext() { return this->threadContext; }
  19. JsRuntimeHandle ToHandle() { return static_cast<JsRuntimeHandle>(this); }
  20. static JsrtRuntime * FromHandle(JsRuntimeHandle runtimeHandle)
  21. {
  22. JsrtRuntime * runtime = static_cast<JsrtRuntime *>(runtimeHandle);
  23. runtime->threadContext->ValidateThreadContext();
  24. return runtime;
  25. }
  26. static void Uninitialize();
  27. bool UseIdle() const { return useIdle; }
  28. unsigned int Idle();
  29. bool DispatchExceptions() const { return dispatchExceptions; }
  30. void CloseContexts();
  31. void SetBeforeCollectCallback(JsBeforeCollectCallback beforeCollectCallback, void * callbackContext);
  32. #ifdef _CHAKRACOREBUILD
  33. void SetBeforeSweepCallback(JsBeforeSweepCallback beforeCollectCallback, void * callbackContext);
  34. #endif
  35. #ifdef ENABLE_DEBUG_CONFIG_OPTIONS
  36. void SetSerializeByteCodeForLibrary(bool set) { serializeByteCodeForLibrary = set; }
  37. bool IsSerializeByteCodeForLibrary() const { return serializeByteCodeForLibrary; }
  38. #endif
  39. #ifdef ENABLE_SCRIPT_DEBUGGING
  40. void EnsureJsrtDebugManager();
  41. void DeleteJsrtDebugManager();
  42. JsrtDebugManager * GetJsrtDebugManager();
  43. #endif
  44. #if ENABLE_TTD
  45. uint32 BPRegister_TTD(int64 bpID, Js::ScriptContext* scriptContext, Js::Utf8SourceInfo* utf8SourceInfo, uint32 line, uint32 column, BOOL* isNewBP);
  46. void BPDelete_TTD(uint32 bpID);
  47. void BPClearDocument_TTD();
  48. #endif
  49. private:
  50. static void __cdecl RecyclerCollectCallbackStatic(void * context, RecyclerCollectCallBackFlags flags);
  51. private:
  52. ThreadContext * threadContext;
  53. AllocationPolicyManager* allocationPolicyManager;
  54. JsrtContext * contextList;
  55. ThreadContext::CollectCallBack * collectCallback;
  56. JsBeforeCollectCallback beforeCollectCallback;
  57. #ifdef _CHAKRACOREBUILD
  58. JsBeforeSweepCallback beforeSweepCallback;
  59. void * beforeSweepCallbackContext;
  60. #endif
  61. JsrtThreadService threadService;
  62. void * beforeCollectCallbackContext;
  63. bool useIdle;
  64. bool dispatchExceptions;
  65. #ifdef ENABLE_DEBUG_CONFIG_OPTIONS
  66. bool serializeByteCodeForLibrary;
  67. #endif
  68. #ifdef ENABLE_SCRIPT_DEBUGGING
  69. JsrtDebugManager * jsrtDebugManager;
  70. #endif
  71. };