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 #include "atom/browser/javascript_environment.h"
9 #include "base/command_line.h"
10 #include "base/message_loop/message_loop.h"
11 #include "content/public/common/content_switches.h"
12 #include "gin/array_buffer.h"
13 #include "gin/v8_initializer.h"
14 #include "tizen/common/env_variables.h"
16 #include "atom/common/node_includes.h"
20 JavascriptEnvironment::JavascriptEnvironment()
21 : initialized_(Initialize()),
22 isolate_(isolate_holder_.isolate()),
23 isolate_scope_(isolate_),
24 handle_scope_(isolate_),
25 context_(isolate_, v8::Context::New(isolate_)),
26 context_scope_(v8::Local<v8::Context>::New(isolate_, context_)) {
29 void JavascriptEnvironment::OnMessageLoopCreated() {
30 isolate_holder_.AddRunMicrotasksObserver();
33 void JavascriptEnvironment::OnMessageLoopDestroying() {
34 isolate_holder_.RemoveRunMicrotasksObserver();
37 void JavascriptEnvironment::SetupLocker() {
38 if (!::tizen::is_single_process)
39 locker_.reset(new v8::Locker(isolate_));
42 bool JavascriptEnvironment::Initialize() {
43 auto cmd = base::CommandLine::ForCurrentProcess();
46 std::string js_flags = cmd->GetSwitchValueASCII(switches::kJavaScriptFlags);
47 if (!js_flags.empty())
48 v8::V8::SetFlagsFromString(js_flags.c_str(), js_flags.size());
50 gin::IsolateHolder::Initialize(gin::IsolateHolder::kNonStrictMode,
51 gin::IsolateHolder::kStableV8Extras,
52 gin::ArrayBufferAllocator::SharedInstance());
56 NodeEnvironment::NodeEnvironment(node::Environment* env) : env_(env) {
59 NodeEnvironment::~NodeEnvironment() {
60 node::FreeEnvironment(env_);