javascript_environment.h 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  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 ATOM_BROWSER_JAVASCRIPT_ENVIRONMENT_H_
  5. #define ATOM_BROWSER_JAVASCRIPT_ENVIRONMENT_H_
  6. #include "base/macros.h"
  7. #include "gin/public/isolate_holder.h"
  8. namespace atom {
  9. class JavascriptEnvironment {
  10. public:
  11. JavascriptEnvironment();
  12. void OnMessageLoopCreated();
  13. void OnMessageLoopDestroying();
  14. v8::Isolate* isolate() const { return isolate_; }
  15. v8::Local<v8::Context> context() const {
  16. return v8::Local<v8::Context>::New(isolate_, context_);
  17. }
  18. private:
  19. bool Initialize();
  20. bool initialized_;
  21. gin::IsolateHolder isolate_holder_;
  22. v8::Isolate* isolate_;
  23. v8::Isolate::Scope isolate_scope_;
  24. v8::Locker locker_;
  25. v8::HandleScope handle_scope_;
  26. v8::UniquePersistent<v8::Context> context_;
  27. v8::Context::Scope context_scope_;
  28. DISALLOW_COPY_AND_ASSIGN(JavascriptEnvironment);
  29. };
  30. } // namespace atom
  31. #endif // ATOM_BROWSER_JAVASCRIPT_ENVIRONMENT_H_