diff options
author | Joyee Cheung <joyeec9h3@gmail.com> | 2019-03-20 09:02:57 +0800 |
---|---|---|
committer | Joyee Cheung <joyeec9h3@gmail.com> | 2019-04-04 05:14:54 +0800 |
commit | 9dba96dc1a754616c81a550c057ce7cf9552e9cf (patch) | |
tree | fbec9fd2a7a51634ac50c849192d8fd0e9f02cbb /src | |
parent | d005f382cdcec7dff1d61cf5ab3604e55f004471 (diff) | |
download | android-node-v8-9dba96dc1a754616c81a550c057ce7cf9552e9cf.tar.gz android-node-v8-9dba96dc1a754616c81a550c057ce7cf9552e9cf.tar.bz2 android-node-v8-9dba96dc1a754616c81a550c057ce7cf9552e9cf.zip |
process: patch more process properties during pre-execution
Delay the creation of process properties that depend on
runtime states and properties that should not be accessed
during bootstrap and patch them during pre-execution:
- process.argv
- process.execPath
- process.title
- process.pid
- process.ppid
- process.REVERT_*
- process.debugPort
PR-URL: https://github.com/nodejs/node/pull/26945
Reviewed-By: Gus Caplan <me@gus.host>
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
Diffstat (limited to 'src')
-rw-r--r-- | src/node_process.h | 2 | ||||
-rw-r--r-- | src/node_process_methods.cc | 1 | ||||
-rw-r--r-- | src/node_process_object.cc | 86 |
3 files changed, 46 insertions, 43 deletions
diff --git a/src/node_process.h b/src/node_process.h index 4edf10a1c5..cb6ad85828 100644 --- a/src/node_process.h +++ b/src/node_process.h @@ -35,7 +35,7 @@ v8::MaybeLocal<v8::Object> CreateProcessObject( Environment* env, const std::vector<std::string>& args, const std::vector<std::string>& exec_args); - +void PatchProcessObject(const v8::FunctionCallbackInfo<v8::Value>& args); } // namespace node #endif // defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS #endif // SRC_NODE_PROCESS_H_ diff --git a/src/node_process_methods.cc b/src/node_process_methods.cc index d2ba00b89b..dd27329ee2 100644 --- a/src/node_process_methods.cc +++ b/src/node_process_methods.cc @@ -426,6 +426,7 @@ static void InitializeProcessMethods(Local<Object> target, env->SetMethod(target, "dlopen", binding::DLOpen); env->SetMethod(target, "reallyExit", ReallyExit); env->SetMethodNoSideEffect(target, "uptime", Uptime); + env->SetMethod(target, "patchProcessObject", PatchProcessObject); } } // namespace node diff --git a/src/node_process_object.cc b/src/node_process_object.cc index 93193a18fc..04d0c44add 100644 --- a/src/node_process_object.cc +++ b/src/node_process_object.cc @@ -13,6 +13,7 @@ using v8::Context; using v8::DEFAULT; using v8::EscapableHandleScope; using v8::Function; +using v8::FunctionCallbackInfo; using v8::FunctionTemplate; using v8::HandleScope; using v8::Integer; @@ -84,20 +85,6 @@ MaybeLocal<Object> CreateProcessObject( return MaybeLocal<Object>(); } - // process.title - auto title_string = FIXED_ONE_BYTE_STRING(env->isolate(), "title"); - CHECK(process - ->SetAccessor( - env->context(), - title_string, - ProcessTitleGetter, - env->owns_process_state() ? ProcessTitleSetter : nullptr, - env->as_callback_data(), - DEFAULT, - None, - SideEffectType::kHasNoSideEffect) - .FromJust()); - // process.version READONLY_PROPERTY(process, "version", @@ -140,34 +127,56 @@ MaybeLocal<Object> CreateProcessObject( #endif // _WIN32 #endif // NODE_HAS_RELEASE_URLS + // process._rawDebug: may be overwritten later in JS land, but should be + // availbale from the begining for debugging purposes + env->SetMethod(process, "_rawDebug", RawDebug); + + return scope.Escape(process); +} + +void PatchProcessObject(const FunctionCallbackInfo<Value>& args) { + Isolate* isolate = args.GetIsolate(); + Local<Context> context = isolate->GetCurrentContext(); + Environment* env = Environment::GetCurrent(context); + CHECK(args[0]->IsObject()); + Local<Object> process = args[0].As<Object>(); + + // process.title + CHECK(process + ->SetAccessor( + context, + FIXED_ONE_BYTE_STRING(isolate, "title"), + ProcessTitleGetter, + env->owns_process_state() ? ProcessTitleSetter : nullptr, + env->as_callback_data(), + DEFAULT, + None, + SideEffectType::kHasNoSideEffect) + .FromJust()); + // process.argv - process->Set(env->context(), - FIXED_ONE_BYTE_STRING(env->isolate(), "argv"), - ToV8Value(env->context(), args).ToLocalChecked()).FromJust(); + process->Set(context, + FIXED_ONE_BYTE_STRING(isolate, "argv"), + ToV8Value(context, env->argv()).ToLocalChecked()).FromJust(); // process.execArgv - process->Set(env->context(), - FIXED_ONE_BYTE_STRING(env->isolate(), "execArgv"), - ToV8Value(env->context(), exec_args) + process->Set(context, + FIXED_ONE_BYTE_STRING(isolate, "execArgv"), + ToV8Value(context, env->exec_argv()) .ToLocalChecked()).FromJust(); READONLY_PROPERTY(process, "pid", - Integer::New(env->isolate(), uv_os_getpid())); + Integer::New(isolate, uv_os_getpid())); - CHECK(process->SetAccessor(env->context(), - FIXED_ONE_BYTE_STRING(env->isolate(), "ppid"), + CHECK(process->SetAccessor(context, + FIXED_ONE_BYTE_STRING(isolate, "ppid"), GetParentProcessId).FromJust()); - // TODO(joyeecheung): make this available in JS during pre-execution. - // Note that to use this in releases the code doing the revert need to be - // careful to delay the check until after the bootstrap but that may not - // be possible depending on the feature being reverted. - // --security-revert flags #define V(code, _, __) \ do { \ if (IsReverted(SECURITY_REVERT_ ## code)) { \ - READONLY_PROPERTY(process, "REVERT_" #code, True(env->isolate())); \ + READONLY_PROPERTY(process, "REVERT_" #code, True(isolate)); \ } \ } while (0); SECURITY_REVERSIONS(V) @@ -181,7 +190,7 @@ MaybeLocal<Object> CreateProcessObject( if (uv_exepath(exec_path_buf, &exec_path_len) == 0) { exec_path = std::string(exec_path_buf, exec_path_len); } else { - exec_path = args[0]; + exec_path = env->argv()[0]; } // On OpenBSD process.execPath will be relative unless we // get the full path before process.execPath is used. @@ -196,9 +205,9 @@ MaybeLocal<Object> CreateProcessObject( uv_fs_req_cleanup(&req); #endif process - ->Set(env->context(), - FIXED_ONE_BYTE_STRING(env->isolate(), "execPath"), - String::NewFromUtf8(env->isolate(), + ->Set(context, + FIXED_ONE_BYTE_STRING(isolate, "execPath"), + String::NewFromUtf8(isolate, exec_path.c_str(), NewStringType::kInternalized, exec_path.size()) @@ -207,20 +216,13 @@ MaybeLocal<Object> CreateProcessObject( } // process.debugPort - auto debug_port_string = FIXED_ONE_BYTE_STRING(env->isolate(), "debugPort"); CHECK(process - ->SetAccessor(env->context(), - debug_port_string, + ->SetAccessor(context, + FIXED_ONE_BYTE_STRING(isolate, "debugPort"), DebugPortGetter, env->owns_process_state() ? DebugPortSetter : nullptr, env->as_callback_data()) .FromJust()); - - // process._rawDebug: may be overwritten later in JS land, but should be - // availbale from the begining for debugging purposes - env->SetMethod(process, "_rawDebug", RawDebug); - - return scope.Escape(process); } } // namespace node |