Created
August 19, 2015 11:40
-
-
Save ghaiklor/08863a0db452379ae90d to your computer and use it in GitHub Desktop.
NodeJS Create Environment method
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Environment* CreateEnvironment(Isolate* isolate, uv_loop_t* loop, Handle<Context> context, int argc, const char* const* argv, int exec_argc, const char* const* exec_argv) { | |
HandleScope handle_scope(isolate); | |
Context::Scope context_scope(context); | |
Environment* env = Environment::New(context, loop); | |
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_check_init(env->event_loop(), env->idle_check_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); | |
if (v8_is_profiling) { | |
StartProfilerIdleNotifier(env); | |
} | |
Local<FunctionTemplate> process_template = FunctionTemplate::New(isolate); | |
process_template->SetClassName(FIXED_ONE_BYTE_STRING(isolate, "process")); | |
Local<Object> process_object = process_template->GetFunction()->NewInstance(); | |
env->set_process_object(process_object); | |
SetupProcessObject(env, argc, argv, exec_argc, exec_argv); | |
LoadAsyncWrapperInfo(env); | |
return env; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment