2014-10-31 18:17:05 +00:00
|
|
|
// Copyright (c) 2013 GitHub, Inc.
|
2014-07-28 08:00:15 +00:00
|
|
|
// Use of this source code is governed by the MIT license that can be
|
|
|
|
// found in the LICENSE file.
|
|
|
|
|
|
|
|
#ifndef ATOM_BROWSER_JAVASCRIPT_ENVIRONMENT_H_
|
|
|
|
#define ATOM_BROWSER_JAVASCRIPT_ENVIRONMENT_H_
|
|
|
|
|
2016-03-08 04:38:49 +00:00
|
|
|
#include "base/macros.h"
|
2014-09-01 08:41:26 +00:00
|
|
|
#include "gin/public/isolate_holder.h"
|
2018-10-05 18:40:17 +00:00
|
|
|
#include "uv.h" // NOLINT(build/include)
|
2014-07-28 08:00:15 +00:00
|
|
|
|
2017-02-28 00:56:09 +00:00
|
|
|
namespace node {
|
|
|
|
class Environment;
|
2018-01-06 15:58:24 +00:00
|
|
|
class MultiIsolatePlatform;
|
2018-04-18 01:44:10 +00:00
|
|
|
} // namespace node
|
2017-02-28 00:56:09 +00:00
|
|
|
|
2014-07-28 08:00:15 +00:00
|
|
|
namespace atom {
|
|
|
|
|
2017-02-28 00:56:09 +00:00
|
|
|
// Manage the V8 isolate and context automatically.
|
2014-07-28 08:00:15 +00:00
|
|
|
class JavascriptEnvironment {
|
|
|
|
public:
|
2018-10-05 18:40:17 +00:00
|
|
|
explicit JavascriptEnvironment(uv_loop_t* event_loop);
|
2018-04-17 23:37:22 +00:00
|
|
|
~JavascriptEnvironment();
|
2014-07-28 08:00:15 +00:00
|
|
|
|
2016-06-24 05:45:31 +00:00
|
|
|
void OnMessageLoopDestroying();
|
|
|
|
|
2018-01-06 15:58:24 +00:00
|
|
|
node::MultiIsolatePlatform* platform() const { return platform_; }
|
2014-07-28 08:00:15 +00:00
|
|
|
v8::Isolate* isolate() const { return isolate_; }
|
|
|
|
v8::Local<v8::Context> context() const {
|
|
|
|
return v8::Local<v8::Context>::New(isolate_, context_);
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
2018-10-05 18:40:17 +00:00
|
|
|
v8::Isolate* Initialize(uv_loop_t* event_loop);
|
2017-12-08 00:23:17 +00:00
|
|
|
// Leaked on exit.
|
2018-01-06 15:58:24 +00:00
|
|
|
node::MultiIsolatePlatform* platform_;
|
2017-12-08 00:23:17 +00:00
|
|
|
|
2014-07-28 08:00:15 +00:00
|
|
|
v8::Isolate* isolate_;
|
2018-10-05 18:40:17 +00:00
|
|
|
gin::IsolateHolder isolate_holder_;
|
2014-09-01 08:41:26 +00:00
|
|
|
v8::Isolate::Scope isolate_scope_;
|
2014-07-28 08:00:15 +00:00
|
|
|
v8::Locker locker_;
|
|
|
|
v8::HandleScope handle_scope_;
|
2018-10-05 18:40:17 +00:00
|
|
|
v8::Global<v8::Context> context_;
|
2014-07-28 08:00:15 +00:00
|
|
|
v8::Context::Scope context_scope_;
|
|
|
|
|
|
|
|
DISALLOW_COPY_AND_ASSIGN(JavascriptEnvironment);
|
|
|
|
};
|
|
|
|
|
2017-02-28 00:56:09 +00:00
|
|
|
// Manage the Node Environment automatically.
|
|
|
|
class NodeEnvironment {
|
|
|
|
public:
|
2017-03-02 08:26:15 +00:00
|
|
|
explicit NodeEnvironment(node::Environment* env);
|
2017-02-28 00:56:09 +00:00
|
|
|
~NodeEnvironment();
|
|
|
|
|
|
|
|
private:
|
|
|
|
node::Environment* env_;
|
|
|
|
|
|
|
|
DISALLOW_COPY_AND_ASSIGN(NodeEnvironment);
|
|
|
|
};
|
|
|
|
|
2014-07-28 08:00:15 +00:00
|
|
|
} // namespace atom
|
|
|
|
|
|
|
|
#endif // ATOM_BROWSER_JAVASCRIPT_ENVIRONMENT_H_
|