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.
5 #ifndef ATOM_BROWSER_JAVASCRIPT_ENVIRONMENT_H_
6 #define ATOM_BROWSER_JAVASCRIPT_ENVIRONMENT_H_
8 #include "base/macros.h"
9 #include "gin/public/isolate_holder.h"
17 // Manage the V8 isolate and context automatically.
18 class JavascriptEnvironment {
20 JavascriptEnvironment();
22 void OnMessageLoopCreated();
23 void OnMessageLoopDestroying();
26 v8::Isolate* isolate() const { return isolate_; }
27 v8::Local<v8::Context> context() const {
28 return v8::Local<v8::Context>::New(isolate_, context_);
35 gin::IsolateHolder isolate_holder_;
36 v8::Isolate* isolate_;
37 v8::Isolate::Scope isolate_scope_;
38 std::unique_ptr<v8::Locker> locker_;
39 v8::HandleScope handle_scope_;
40 v8::UniquePersistent<v8::Context> context_;
41 v8::Context::Scope context_scope_;
43 DISALLOW_COPY_AND_ASSIGN(JavascriptEnvironment);
46 // Manage the Node Environment automatically.
47 class NodeEnvironment {
49 explicit NodeEnvironment(node::Environment* env);
53 node::Environment* env_;
55 DISALLOW_COPY_AND_ASSIGN(NodeEnvironment);
60 #endif // ATOM_BROWSER_JAVASCRIPT_ENVIRONMENT_H_