void UvNoOp(uv_async_t* handle) {
}
+// Moved from node.cc.
+void HandleCloseCb(uv_handle_t* handle) {
+ node::Environment* env = reinterpret_cast<node::Environment*>(handle->data);
+ env->FinishHandleCleanup(handle);
+}
+
+void HandleCleanup(node::Environment* env,
+ uv_handle_t* handle,
+ void* arg) {
+ handle->data = env;
+ uv_close(handle, HandleCloseCb);
+}
+
// Convert the given vector to an array of C-strings. The strings in the
// returned vector are only guaranteed valid so long as the vector of strings
// is not modified.
// Construct the parameters that passed to node::CreateEnvironment:
v8::Isolate* isolate = context->GetIsolate();
+ uv_loop_t* loop = uv_default_loop();
int argc = args.size();
const char** argv = c_argv.get();
int exec_argc = 0;
// Following code are stripped from node::CreateEnvironment in node.cc:
HandleScope handle_scope(isolate);
+
Context::Scope context_scope(context);
+ Environment* env = Environment::New(context, loop);
- Environment* env = Environment::New(context);
+ isolate->SetAutorunMicrotasks(false);
uv_check_init(env->event_loop(), env->immediate_check_handle());
uv_unref(
reinterpret_cast<uv_handle_t*>(env->immediate_check_handle()));
+
uv_idle_init(env->event_loop(), env->immediate_idle_handle());
uv_prepare_init(env->event_loop(), env->idle_prepare_handle());
uv_unref(reinterpret_cast<uv_handle_t*>(env->idle_prepare_handle()));
uv_unref(reinterpret_cast<uv_handle_t*>(env->idle_check_handle()));
+ // Register handle cleanups
+ env->RegisterHandleCleanup(
+ reinterpret_cast<uv_handle_t*>(env->immediate_check_handle()),
+ HandleCleanup,
+ nullptr);
+ env->RegisterHandleCleanup(
+ reinterpret_cast<uv_handle_t*>(env->immediate_idle_handle()),
+ HandleCleanup,
+ nullptr);
+ env->RegisterHandleCleanup(
+ reinterpret_cast<uv_handle_t*>(env->idle_prepare_handle()),
+ HandleCleanup,
+ nullptr);
+ env->RegisterHandleCleanup(
+ reinterpret_cast<uv_handle_t*>(env->idle_check_handle()),
+ HandleCleanup,
+ nullptr);
+
Local<FunctionTemplate> process_template = FunctionTemplate::New(isolate);
process_template->SetClassName(FIXED_ONE_BYTE_STRING(isolate, "process"));
env->set_process_object(process_object);
SetupProcessObject(env, argc, argv, exec_argc, exec_argv);
- Load(env);
+ LoadEnvironment(env);
return env;
}