@@ -60,23 +60,29 @@ static int RunNodeInstance(MultiIsolatePlatform* platform,
60
60
const std::vector<std::string>& args,
61
61
const std::vector<std::string>& exec_args) {
62
62
int exit_code = 0 ;
63
+ uv_loop_t * loop;
64
+ #ifndef BOXEDNODE_USE_DEFAULT_UV_LOOP
63
65
// Set up a libuv event loop.
64
- uv_loop_t loop;
65
- int ret = uv_loop_init (&loop);
66
+ uv_loop_t loop_;
67
+ loop = &loop_;
68
+ int ret = uv_loop_init (loop);
66
69
if (ret != 0 ) {
67
70
fprintf (stderr, " %s: Failed to initialize loop: %s\n " ,
68
71
args[0 ].c_str (),
69
72
uv_err_name (ret));
70
73
return 1 ;
71
74
}
75
+ #else
76
+ loop = uv_default_loop ();
77
+ #endif
72
78
73
79
std::shared_ptr<ArrayBufferAllocator> allocator =
74
80
ArrayBufferAllocator::Create ();
75
81
76
82
#if NODE_VERSION_AT_LEAST(14, 0, 0)
77
- Isolate* isolate = NewIsolate (allocator, & loop, platform);
83
+ Isolate* isolate = NewIsolate (allocator, loop, platform);
78
84
#else
79
- Isolate* isolate = NewIsolate (allocator.get (), & loop, platform);
85
+ Isolate* isolate = NewIsolate (allocator.get (), loop, platform);
80
86
#endif
81
87
if (isolate == nullptr ) {
82
88
fprintf (stderr, " %s: Failed to initialize V8 Isolate\n " , args[0 ].c_str ());
@@ -90,7 +96,7 @@ static int RunNodeInstance(MultiIsolatePlatform* platform,
90
96
// Create a node::IsolateData instance that will later be released using
91
97
// node::FreeIsolateData().
92
98
std::unique_ptr<IsolateData, decltype (&node::FreeIsolateData)> isolate_data (
93
- node::CreateIsolateData (isolate, & loop, platform, allocator.get ()),
99
+ node::CreateIsolateData (isolate, loop, platform, allocator.get ()),
94
100
node::FreeIsolateData);
95
101
96
102
// Set up a new v8::Context.
@@ -154,15 +160,15 @@ static int RunNodeInstance(MultiIsolatePlatform* platform,
154
160
SealHandleScope seal (isolate);
155
161
bool more;
156
162
do {
157
- uv_run (& loop, UV_RUN_DEFAULT);
163
+ uv_run (loop, UV_RUN_DEFAULT);
158
164
159
165
// V8 tasks on background threads may end up scheduling new tasks in the
160
166
// foreground, which in turn can keep the event loop going. For example,
161
167
// WebAssembly.compile() may do so.
162
168
platform->DrainTasks (isolate);
163
169
164
170
// If there are new tasks, continue.
165
- more = uv_loop_alive (& loop);
171
+ more = uv_loop_alive (loop);
166
172
if (more) continue ;
167
173
168
174
// node::EmitBeforeExit() is used to emit the 'beforeExit' event on
@@ -171,7 +177,7 @@ static int RunNodeInstance(MultiIsolatePlatform* platform,
171
177
172
178
// 'beforeExit' can also schedule new work that keeps the event loop
173
179
// running.
174
- more = uv_loop_alive (& loop);
180
+ more = uv_loop_alive (loop);
175
181
} while (more == true );
176
182
}
177
183
@@ -196,9 +202,11 @@ static int RunNodeInstance(MultiIsolatePlatform* platform,
196
202
197
203
// Wait until the platform has cleaned up all relevant resources.
198
204
while (!platform_finished)
199
- uv_run (&loop, UV_RUN_ONCE);
200
- int err = uv_loop_close (&loop);
205
+ uv_run (loop, UV_RUN_ONCE);
206
+ #ifndef BOXEDNODE_USE_DEFAULT_UV_LOOP
207
+ int err = uv_loop_close (loop);
201
208
assert (err == 0 );
209
+ #endif
202
210
203
211
return exit_code;
204
212
}
0 commit comments