Initialize node in browser process.
This commit is contained in:
parent
e49861b45b
commit
f853fc3df5
7 changed files with 90 additions and 3 deletions
46
common/node_bindings.cc
Normal file
46
common/node_bindings.cc
Normal file
|
@ -0,0 +1,46 @@
|
|||
// Copyright (c) 2013 GitHub, Inc. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
#include "common/node_bindings.h"
|
||||
|
||||
#include "base/command_line.h"
|
||||
#include "base/logging.h"
|
||||
#include "v8/include/v8.h"
|
||||
#include "vendor/node/src/node.h"
|
||||
#include "vendor/node/src/node_internals.h"
|
||||
|
||||
namespace atom {
|
||||
|
||||
NodeBindings::NodeBindings() {
|
||||
}
|
||||
|
||||
NodeBindings::~NodeBindings() {
|
||||
}
|
||||
|
||||
void NodeBindings::Initialize() {
|
||||
CommandLine::StringVector str_argv = CommandLine::ForCurrentProcess()->argv();
|
||||
|
||||
// Convert string vector to char* array.
|
||||
std::vector<char*> argv(str_argv.size(), NULL);
|
||||
for (size_t i = 0; i < str_argv.size(); ++i) {
|
||||
LOG(ERROR) << str_argv[i];
|
||||
argv[i] = const_cast<char*>(str_argv[i].c_str());
|
||||
}
|
||||
|
||||
// Init node.
|
||||
node::Init(argv.size(), &argv[0]);
|
||||
v8::V8::Initialize();
|
||||
|
||||
// Load node.js.
|
||||
v8::HandleScope scope;
|
||||
node::g_context = v8::Context::New();
|
||||
{
|
||||
v8::Context::Scope context_scope(node::g_context);
|
||||
v8::Handle<v8::Object> process = node::SetupProcessObject(
|
||||
argv.size(), &argv[0]);
|
||||
node::Load(process);
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace at
|
26
common/node_bindings.h
Normal file
26
common/node_bindings.h
Normal file
|
@ -0,0 +1,26 @@
|
|||
// Copyright (c) 2013 GitHub, Inc. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
#ifndef RAVE_COMMON_NODE_BINDINGS_
|
||||
#define RAVE_COMMON_NODE_BINDINGS_
|
||||
|
||||
#include "base/basictypes.h"
|
||||
|
||||
namespace atom {
|
||||
|
||||
class NodeBindings {
|
||||
public:
|
||||
NodeBindings();
|
||||
virtual ~NodeBindings();
|
||||
|
||||
// Setup everything including V8, libuv and node.js main script.
|
||||
void Initialize();
|
||||
|
||||
private:
|
||||
DISALLOW_COPY_AND_ASSIGN(NodeBindings);
|
||||
};
|
||||
|
||||
} // namespace at
|
||||
|
||||
#endif // RAVE_COMMON_NODE_BINDINGS_
|
Loading…
Add table
Add a link
Reference in a new issue