Skip to content

Commit d375b50

Browse files
codebyteredeepak1556
authored andcommitted
REVIEW: Address node api changes
- Always start the inspector agent for nodejs/node#17085 - Set the tracing controller for node nodejs/node#15538 - Isolate data creation now requires plaform nodejs/node#16700
1 parent 09623d4 commit d375b50

9 files changed

Lines changed: 51 additions & 30 deletions

File tree

atom/app/node_main.cc

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
#include "atom/common/api/atom_bindings.h"
1111
#include "atom/common/crash_reporter/crash_reporter.h"
1212
#include "atom/common/native_mate_converters/string16_converter.h"
13+
#include "atom/common/node_bindings.h"
1314
#include "base/command_line.h"
1415
#include "base/feature_list.h"
1516
#include "base/task_scheduler/task_scheduler.h"
@@ -48,14 +49,16 @@ int NodeMain(int argc, char *argv[]) {
4849
// Initialize gin::IsolateHolder.
4950
JavascriptEnvironment gin_env;
5051

52+
// Explicitly register electron's builtin modules.
53+
NodeBindings::RegisterBuiltinModules();
54+
5155
int exec_argc;
5256
const char** exec_argv;
5357
node::Init(&argc, const_cast<const char**>(argv), &exec_argc, &exec_argv);
5458

55-
node::IsolateData isolate_data(gin_env.isolate(), loop);
5659
node::Environment* env = node::CreateEnvironment(
57-
&isolate_data, gin_env.context(), argc, argv,
58-
exec_argc, exec_argv);
60+
node::CreateIsolateData(gin_env.isolate(), loop, gin_env.platform()),
61+
gin_env.context(), argc, argv, exec_argc, exec_argv);
5962

6063
// Enable support for v8 inspector.
6164
NodeDebugger node_debugger(env);
@@ -77,6 +80,7 @@ int NodeMain(int argc, char *argv[]) {
7780
bool more;
7881
do {
7982
more = uv_run(env->event_loop(), UV_RUN_ONCE);
83+
gin_env.platform()->DrainBackgroundTasks(env->isolate());
8084
if (more == false) {
8185
node::EmitBeforeExit(env);
8286

@@ -90,6 +94,8 @@ int NodeMain(int argc, char *argv[]) {
9094

9195
exit_code = node::EmitExit(env);
9296
node::RunAtExit(env);
97+
gin_env.platform()->DrainBackgroundTasks(env->isolate());
98+
gin_env.platform()->CancelPendingDelayedTasks(env->isolate());
9399

94100
node::FreeEnvironment(env);
95101
}

atom/browser/atom_browser_main_parts.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -135,8 +135,8 @@ void AtomBrowserMainParts::PostEarlyInitialization() {
135135
node_bindings_->Initialize();
136136

137137
// Create the global environment.
138-
node::Environment* env =
139-
node_bindings_->CreateEnvironment(js_env_->context());
138+
node::Environment* env = node_bindings_->CreateEnvironment(
139+
js_env_->context(), js_env_->platform());
140140
node_env_.reset(new NodeEnvironment(env));
141141

142142
// Enable support for v8 inspector

atom/browser/javascript_environment.cc

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
#include "gin/v8_initializer.h"
1616

1717
#include "atom/common/node_includes.h"
18+
#include "vendor/node/src/tracing/trace_event.h"
1819

1920
namespace atom {
2021

@@ -50,7 +51,8 @@ bool JavascriptEnvironment::Initialize() {
5051
platform_ = node::CreatePlatform(
5152
base::RecommendedMaxNumberOfThreadsInPool(3, 8, 0.1, 0), nullptr);
5253
v8::V8::InitializePlatform(platform_);
53-
54+
node::tracing::TraceEventHelper::SetTracingController(
55+
new v8::TracingController());
5456
gin::IsolateHolder::Initialize(gin::IsolateHolder::kNonStrictMode,
5557
gin::IsolateHolder::kStableV8Extras,
5658
gin::ArrayBufferAllocator::SharedInstance(),

atom/browser/node_debugger.cc

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -34,17 +34,16 @@ void NodeDebugger::Start(node::MultiIsolatePlatform* platform) {
3434
#endif
3535
}
3636

37-
if (options.inspector_enabled()) {
38-
// Set process._debugWaitConnect if --inspect-brk was specified to stop
39-
// the debugger on the first line
40-
if (options.wait_for_connect()) {
41-
mate::Dictionary process(env_->isolate(), env_->process_object());
42-
process.Set("_breakFirstLine", true);
43-
}
44-
45-
inspector->Start(static_cast<node::NodePlatform*>(platform),
46-
nullptr, options);
37+
// Set process._debugWaitConnect if --inspect-brk was specified to stop
38+
// the debugger on the first line
39+
if (options.wait_for_connect()) {
40+
mate::Dictionary process(env_->isolate(), env_->process_object());
41+
process.Set("_breakFirstLine", true);
4742
}
43+
44+
inspector->Start(static_cast<node::NodePlatform*>(platform), nullptr,
45+
options);
46+
DCHECK(env_->inspector_agent()->IsStarted());
4847
}
4948

5049
} // namespace atom

atom/common/node_bindings.cc

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -122,12 +122,6 @@ base::FilePath GetResourcesPath(bool is_browser) {
122122
return resources_path;
123123
}
124124

125-
void RegisterBuiltinModules() {
126-
#define V(modname) _register_##modname();
127-
ELECTRON_BUILTIN_MODULES(V)
128-
#undef V
129-
}
130-
131125
} // namespace
132126

133127
NodeBindings::NodeBindings(BrowserEnvironment browser_env)
@@ -161,6 +155,12 @@ NodeBindings::~NodeBindings() {
161155
stop_and_close_uv_loop(uv_loop_);
162156
}
163157

158+
void NodeBindings::RegisterBuiltinModules() {
159+
#define V(modname) _register_##modname();
160+
ELECTRON_BUILTIN_MODULES(V)
161+
#undef V
162+
}
163+
164164
void NodeBindings::Initialize() {
165165
// Open node's error reporting system for browser process.
166166
node::g_standalone_mode = browser_env_ == BROWSER;
@@ -172,13 +172,13 @@ void NodeBindings::Initialize() {
172172
AtomCommandLine::InitializeFromCommandLine();
173173
#endif
174174

175+
// Explicitly register electron's builtin modules.
176+
RegisterBuiltinModules();
177+
175178
// Init node.
176179
// (we assume node::Init would not modify the parameters under embedded mode).
177180
node::Init(nullptr, nullptr, nullptr, nullptr);
178181

179-
// Explicitly register electron's builtin modules.
180-
RegisterBuiltinModules();
181-
182182
#if defined(OS_WIN)
183183
// uv_init overrides error mode to suppress the default crash dialog, bring
184184
// it back if user wants to show it.
@@ -189,7 +189,8 @@ void NodeBindings::Initialize() {
189189
}
190190

191191
node::Environment* NodeBindings::CreateEnvironment(
192-
v8::Handle<v8::Context> context) {
192+
v8::Handle<v8::Context> context,
193+
node::MultiIsolatePlatform* platform) {
193194
auto args = AtomCommandLine::argv();
194195

195196
// Feed node the path to initialization script.
@@ -215,8 +216,8 @@ node::Environment* NodeBindings::CreateEnvironment(
215216

216217
std::unique_ptr<const char*[]> c_argv = StringVectorToArgArray(args);
217218
node::Environment* env = node::CreateEnvironment(
218-
new node::IsolateData(context->GetIsolate(), uv_loop_), context,
219-
args.size(), c_argv.get(), 0, nullptr);
219+
node::CreateIsolateData(context->GetIsolate(), uv_loop_, platform),
220+
context, args.size(), c_argv.get(), 0, nullptr);
220221

221222
if (browser_env_ == BROWSER) {
222223
// SetAutorunMicrotasks is no longer called in node::CreateEnvironment

atom/common/node_bindings.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ class MessageLoop;
1717

1818
namespace node {
1919
class Environment;
20+
class MultiIsolatePlatform;
2021
}
2122

2223
namespace atom {
@@ -30,14 +31,17 @@ class NodeBindings {
3031
};
3132

3233
static NodeBindings* Create(BrowserEnvironment browser_env);
34+
static void RegisterBuiltinModules();
3335

3436
virtual ~NodeBindings();
3537

3638
// Setup V8, libuv.
3739
void Initialize();
3840

3941
// Create the environment and load node.js.
40-
node::Environment* CreateEnvironment(v8::Handle<v8::Context> context);
42+
node::Environment* CreateEnvironment(
43+
v8::Handle<v8::Context> context,
44+
node::MultiIsolatePlatform* platform = nullptr);
4145

4246
// Load node.js in the environment.
4347
void LoadEnvironment(node::Environment* env);

atom/renderer/atom_renderer_client.cc

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525

2626
#include "atom/common/node_includes.h"
2727
#include "atom_natives.h" // NOLINT: This file is generated with js2c
28+
#include "vendor/node/src/tracing/trace_event.h"
2829

2930
namespace atom {
3031

@@ -95,6 +96,11 @@ void AtomRendererClient::DidCreateScriptContext(
9596
node_bindings_->PrepareMessageLoop();
9697
}
9798

99+
// Setup node tracing controller.
100+
if (!node::tracing::TraceEventHelper::GetTracingController())
101+
node::tracing::TraceEventHelper::SetTracingController(
102+
new v8::TracingController());
103+
98104
// Setup node environment for each window.
99105
node::Environment* env = node_bindings_->CreateEnvironment(context);
100106

atom/renderer/atom_sandboxed_renderer_client.cc

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
#include "atom/common/native_mate_converters/string16_converter.h"
1212
#include "atom/common/native_mate_converters/v8_value_converter.h"
1313
#include "atom/common/native_mate_converters/value_converter.h"
14+
#include "atom/common/node_bindings.h"
1415
#include "atom/common/options_switches.h"
1516
#include "atom/renderer/api/atom_api_renderer_ipc.h"
1617
#include "atom/renderer/atom_render_view_observer.h"
@@ -136,6 +137,8 @@ class AtomSandboxedRenderViewObserver : public AtomRenderViewObserver {
136137

137138

138139
AtomSandboxedRendererClient::AtomSandboxedRendererClient() {
140+
// Explicitly register electron's builtin modules.
141+
NodeBindings::RegisterBuiltinModules();
139142
}
140143

141144
AtomSandboxedRendererClient::~AtomSandboxedRendererClient() {

vendor/node

0 commit comments

Comments
 (0)