diff options
author | Anna Henningsen <anna@addaleax.net> | 2019-01-27 16:21:21 +0300 |
---|---|---|
committer | Anna Henningsen <anna@addaleax.net> | 2019-01-29 22:02:01 +0300 |
commit | 95571ac1e9acd09d0b06b2315aabb0cc4e158572 (patch) | |
tree | 67922f8c1b831d7fce0b083a3fa2d5bdd8664f51 /src/node_process_object.cc | |
parent | 4dbff090c3ff2ba43b0fbb06cc65bef5b5d81008 (diff) |
src: pass along errors from process obj instantiation
PR-URL: https://github.com/nodejs/node/pull/25734
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Gus Caplan <me@gus.host>
Diffstat (limited to 'src/node_process_object.cc')
-rw-r--r-- | src/node_process_object.cc | 25 |
1 files changed, 17 insertions, 8 deletions
diff --git a/src/node_process_object.cc b/src/node_process_object.cc index 980b5002b69..c1f8806110f 100644 --- a/src/node_process_object.cc +++ b/src/node_process_object.cc @@ -19,6 +19,7 @@ using v8::Integer; using v8::Isolate; using v8::Just; using v8::Local; +using v8::MaybeLocal; using v8::Name; using v8::NewStringType; using v8::None; @@ -66,19 +67,22 @@ static void GetParentProcessId(Local<Name> property, info.GetReturnValue().Set(uv_os_getppid()); } -Local<Object> CreateProcessObject(Environment* env, - const std::vector<std::string>& args, - const std::vector<std::string>& exec_args) { +MaybeLocal<Object> CreateProcessObject( + Environment* env, + const std::vector<std::string>& args, + const std::vector<std::string>& exec_args) { Isolate* isolate = env->isolate(); EscapableHandleScope scope(isolate); Local<Context> context = env->context(); Local<FunctionTemplate> process_template = FunctionTemplate::New(isolate); process_template->SetClassName(FIXED_ONE_BYTE_STRING(isolate, "process")); - Local<Object> process = process_template->GetFunction(context) - .ToLocalChecked() - ->NewInstance(context) - .ToLocalChecked(); + Local<Function> process_ctor; + Local<Object> process; + if (!process_template->GetFunction(context).ToLocal(&process_ctor) || + !process_ctor->NewInstance(context).ToLocal(&process)) { + return MaybeLocal<Object>(); + } // process.title auto title_string = FIXED_ONE_BYTE_STRING(env->isolate(), "title"); @@ -145,11 +149,16 @@ Local<Object> CreateProcessObject(Environment* env, ToV8Value(env->context(), exec_args) .ToLocalChecked()).FromJust(); + Local<Object> env_var_proxy; + if (!CreateEnvVarProxy(context, isolate, env->as_external()) + .ToLocal(&env_var_proxy)) + return MaybeLocal<Object>(); + // process.env process ->Set(env->context(), FIXED_ONE_BYTE_STRING(env->isolate(), "env"), - CreateEnvVarProxy(context, isolate, env->as_external())) + env_var_proxy) .FromJust(); READONLY_PROPERTY(process, "pid", |