diff options
author | James M Snell <jasnell@gmail.com> | 2017-10-27 16:25:14 -0700 |
---|---|---|
committer | James M Snell <jasnell@gmail.com> | 2017-11-02 11:58:38 -0700 |
commit | c3dc0e0d75cc5a03de154f3586e1062df1e719e4 (patch) | |
tree | 8cf83f993f44df1f9cde0b59f87db81558bed6b0 /src/env.cc | |
parent | f1f0eb25951a33cd97661aee44a9b43bc6eb6d27 (diff) | |
download | android-node-v8-c3dc0e0d75cc5a03de154f3586e1062df1e719e4.tar.gz android-node-v8-c3dc0e0d75cc5a03de154f3586e1062df1e719e4.tar.bz2 android-node-v8-c3dc0e0d75cc5a03de154f3586e1062df1e719e4.zip |
src: add CollectExceptionInfo & errors.SystemError
Preparing for the migration of existing UVException and ErrnoExceptions
from the native layer, add new `errors.SystemError` to internal/errors
and new `env->CollectExceptionInfo()` / `env->CollectUVExceptionInfo()`
methods.
PR-URL: https://github.com/nodejs/node/pull/16567
Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com>
Reviewed-By: Michael Dawson <michael_dawson@ca.ibm.com>
Diffstat (limited to 'src/env.cc')
-rw-r--r-- | src/env.cc | 78 |
1 files changed, 78 insertions, 0 deletions
diff --git a/src/env.cc b/src/env.cc index a0d82986c9..9bed08cdb0 100644 --- a/src/env.cc +++ b/src/env.cc @@ -1,6 +1,7 @@ #include "node_internals.h" #include "async-wrap.h" #include "v8-profiler.h" +#include "node_buffer.h" #if defined(_MSC_VER) #define getpid GetCurrentProcessId @@ -228,4 +229,81 @@ void Environment::EnvPromiseHook(v8::PromiseHookType type, } } +void CollectExceptionInfo(Environment* env, + v8::Local<v8::Object> obj, + int errorno, + const char* err_string, + const char* syscall, + const char* message, + const char* path, + const char* dest) { + obj->Set(env->errno_string(), v8::Integer::New(env->isolate(), errorno)); + + obj->Set(env->context(), env->code_string(), + OneByteString(env->isolate(), err_string)).FromJust(); + + if (message != nullptr) { + obj->Set(env->context(), env->message_string(), + OneByteString(env->isolate(), message)).FromJust(); + } + + v8::Local<v8::Value> path_buffer; + if (path != nullptr) { + path_buffer = + Buffer::Copy(env->isolate(), path, strlen(path)).ToLocalChecked(); + obj->Set(env->context(), env->path_string(), path_buffer).FromJust(); + } + + v8::Local<v8::Value> dest_buffer; + if (dest != nullptr) { + dest_buffer = + Buffer::Copy(env->isolate(), dest, strlen(dest)).ToLocalChecked(); + obj->Set(env->context(), env->dest_string(), dest_buffer).FromJust(); + } + + if (syscall != nullptr) { + obj->Set(env->context(), env->syscall_string(), + OneByteString(env->isolate(), syscall)); + } +} + +void Environment::CollectExceptionInfo(v8::Local<v8::Value> object, + int errorno, + const char* syscall, + const char* message, + const char* path) { + if (!object->IsObject() || errorno == 0) + return; + + v8::Local<v8::Object> obj = object.As<v8::Object>(); + const char* err_string = node::errno_string(errorno); + + if (message == nullptr || message[0] == '\0') { + message = strerror(errorno); + } + + node::CollectExceptionInfo(this, obj, errorno, err_string, + syscall, message, path, nullptr); +} + +void Environment::CollectUVExceptionInfo(v8::Local<v8::Value> object, + int errorno, + const char* syscall, + const char* message, + const char* path, + const char* dest) { + if (!object->IsObject() || errorno == 0) + return; + + v8::Local<v8::Object> obj = object.As<v8::Object>(); + const char* err_string = uv_err_name(errorno); + + if (message == nullptr || message[0] == '\0') { + message = uv_strerror(errorno); + } + + node::CollectExceptionInfo(this, obj, errorno, err_string, + syscall, message, path, dest); +} + } // namespace node |