summaryrefslogtreecommitdiff
path: root/src/uv.cc
diff options
context:
space:
mode:
authorJoyee Cheung <joyeec9h3@gmail.com>2017-12-25 21:36:15 +0800
committerJoyee Cheung <joyeec9h3@gmail.com>2017-12-28 03:08:25 +0800
commitc56972779b8c239a48df46b7caadf1ef1b9eacd2 (patch)
tree6ed2b0e27c279c7285dc512e836da6a3185e3939 /src/uv.cc
parent24c71fb47cd772d4b4f8f3d55e5be24ba7a43342 (diff)
downloadandroid-node-v8-c56972779b8c239a48df46b7caadf1ef1b9eacd2.tar.gz
android-node-v8-c56972779b8c239a48df46b7caadf1ef1b9eacd2.tar.bz2
android-node-v8-c56972779b8c239a48df46b7caadf1ef1b9eacd2.zip
src: expose uv.errmap to binding
Add a errno -> [error code, uv error message] map to the uv binding so the error message can be assembled in the JS layer. PR-URL: https://github.com/nodejs/node/pull/17338 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
Diffstat (limited to 'src/uv.cc')
-rw-r--r--src/uv.cc25
1 files changed, 23 insertions, 2 deletions
diff --git a/src/uv.cc b/src/uv.cc
index f70da1baae..3c115cf05b 100644
--- a/src/uv.cc
+++ b/src/uv.cc
@@ -27,10 +27,15 @@
namespace node {
namespace {
+using v8::Array;
using v8::Context;
using v8::FunctionCallbackInfo;
+using v8::Integer;
+using v8::Isolate;
using v8::Local;
+using v8::Map;
using v8::Object;
+using v8::String;
using v8::Value;
@@ -47,14 +52,30 @@ void InitializeUV(Local<Object> target,
Local<Value> unused,
Local<Context> context) {
Environment* env = Environment::GetCurrent(context);
- target->Set(FIXED_ONE_BYTE_STRING(env->isolate(), "errname"),
+ Isolate* isolate = env->isolate();
+ target->Set(FIXED_ONE_BYTE_STRING(isolate, "errname"),
env->NewFunctionTemplate(ErrName)->GetFunction());
#define V(name, _) NODE_DEFINE_CONSTANT(target, UV_##name);
UV_ERRNO_MAP(V)
#undef V
-}
+ Local<Map> err_map = Map::New(isolate);
+
+#define V(name, msg) do { \
+ Local<Array> arr = Array::New(isolate, 2); \
+ arr->Set(0, OneByteString(isolate, #name)); \
+ arr->Set(1, OneByteString(isolate, msg)); \
+ err_map->Set(context, \
+ Integer::New(isolate, UV_##name), \
+ arr).ToLocalChecked(); \
+} while (0);
+ UV_ERRNO_MAP(V)
+#undef V
+
+ target->Set(context, FIXED_ONE_BYTE_STRING(isolate, "errmap"),
+ err_map).FromJust();
+}
} // anonymous namespace
} // namespace node