javascript_environment.h 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. // Copyright (c) 2013 GitHub, Inc.
  2. // Use of this source code is governed by the MIT license that can be
  3. // found in the LICENSE file.
  4. #ifndef ELECTRON_SHELL_BROWSER_JAVASCRIPT_ENVIRONMENT_H_
  5. #define ELECTRON_SHELL_BROWSER_JAVASCRIPT_ENVIRONMENT_H_
  6. #include <memory>
  7. #include "base/memory/raw_ptr.h"
  8. #include "gin/public/isolate_holder.h"
  9. #include "uv.h" // NOLINT(build/include_directory)
  10. #include "v8/include/v8-locker.h"
  11. namespace node {
  12. class Environment;
  13. class MultiIsolatePlatform;
  14. } // namespace node
  15. namespace electron {
  16. class MicrotasksRunner;
  17. // Manage the V8 isolate and context automatically.
  18. class JavascriptEnvironment {
  19. public:
  20. JavascriptEnvironment(uv_loop_t* event_loop,
  21. bool setup_wasm_streaming = false);
  22. ~JavascriptEnvironment();
  23. // disable copy
  24. JavascriptEnvironment(const JavascriptEnvironment&) = delete;
  25. JavascriptEnvironment& operator=(const JavascriptEnvironment&) = delete;
  26. void CreateMicrotasksRunner();
  27. void DestroyMicrotasksRunner();
  28. node::MultiIsolatePlatform* platform() const { return platform_.get(); }
  29. v8::Isolate* isolate() const { return isolate_; }
  30. static v8::Isolate* GetIsolate();
  31. private:
  32. v8::Isolate* Initialize(uv_loop_t* event_loop, bool setup_wasm_streaming);
  33. std::unique_ptr<node::MultiIsolatePlatform> platform_;
  34. gin::IsolateHolder isolate_holder_;
  35. // owned-by: isolate_holder_
  36. const raw_ptr<v8::Isolate> isolate_;
  37. // depends-on: isolate_
  38. const v8::Locker locker_;
  39. std::unique_ptr<MicrotasksRunner> microtasks_runner_;
  40. };
  41. } // namespace electron
  42. #endif // ELECTRON_SHELL_BROWSER_JAVASCRIPT_ENVIRONMENT_H_