Last active
September 16, 2018 13:55
-
-
Save rpf5573/3d901f7f100f3b610692fcfa687c0489 to your computer and use it in GitHub Desktop.
This file contains 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
// 시작은 main 함수! | |
// src/node_main.cc : 94 | |
int main(int argc, char* argv[]) { | |
return node::Start(argc, argv); | |
} | |
// src/node.cc : 3036 | |
int Start(int argc, char** argv) { | |
// 아래는 무엇을 하는지 잘 모르겠지만, V8 을 쓰기위해서 준비하는것 같다 | |
PlatformInit(); | |
Init(&args, &exec_args); | |
InitializeV8Platform(per_process_opts->v8_thread_pool_size); | |
V8::Initialize(); | |
// 들어가는 인자값이 다른 Start()함수가 3개정도 되는것 같다 | |
const int exit_code = Start(uv_default_loop(), args, exec_args); | |
} | |
// src.node.cc : 2988 | |
inline int Start(uv_loop_t* event_loop, const std::vector<std::string>& args, const std::vector<std::string>& exec_args) { | |
// isolate는 javascript 코드를 실행하는 Virtual Machine의 독립된 복사본이라고 합니다 | |
Isolate* const isolate = NewIsolate(allocator.get(), event_loop); | |
// 또 Start() 함수. | |
exit_code = Start(isolate, isolate_data.get(), args, exec_args); | |
} | |
// src.node.cc : 2881 | |
inline int Start(Isolate* isolate, IsolateData* isolate_data, const std::vector<std::string>& args, const std::vector<std::string>& exec_args) {{ | |
Environment env(isolate_data, context, v8_platform.GetTracingAgentWriter()); | |
env.Start(args, exec_args, v8_is_profiling); // process object 생성 | |
// 이 부분이 중요하다. | |
// lib/internal/bootstrap/loaders.js & lib/internal/bootstrap/node.js을 메모리에 로드한뒤 실행시킨다. | |
// 나의 index.js코드도 여기서 실행된다. | |
// 아래의 긴~코드들은 여기를 시작점으로 한다. | |
LoadEnvironment(&env); | |
// 여기서 이제 루프를 돌린다. | |
uv_run(env.event_loop(), UV_RUN_DEFAULT); | |
} | |
// src/node.cc : 2116 | |
void LoadEnvironment(Environment* env) { | |
Local<String> loaders_name = | |
FIXED_ONE_BYTE_STRING(env->isolate(), "internal/bootstrap/loaders.js"); | |
MaybeLocal<Function> loaders_bootstrapper = | |
GetBootstrapper(env, LoadersBootstrapperSource(env), loaders_name); // loaders.js 코드를 실행한다 | |
Local<String> node_name = | |
FIXED_ONE_BYTE_STRING(env->isolate(), "internal/bootstrap/node.js"); | |
MaybeLocal<Function> node_bootstrapper = | |
GetBootstrapper(env, NodeBootstrapperSource(env), node_name); // node.js 코드를 실행한다 | |
} | |
// src/node.cc : 2068 | |
static MaybeLocal<Function> GetBootstrapper( Environment* env, Local<String> source, Local<String> script_name) { | |
// javascript 코드(string)를 실행한다. 가상머신이라는게, javascript 코드를 실행하면서 메모리를 관리해주는 역할을 하는것 같다. | |
MaybeLocal<Value> bootstrapper_v = ExecuteString(env, source, script_name); | |
} | |
// src/node.cc : 1008 | |
static MaybeLocal<Value> ExecuteString(Environment* env, Local<String> source, Local<String> filename) { | |
// 컴파일 하고 | |
MaybeLocal<Script> script = Script::Compile(env->context(), source, &origin); | |
// 실행 ! | |
MaybeLocal<Value> result = script.ToLocalChecked()->Run(env->context()); | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment