Skip to content

Commit

Permalink
src: expose uv.errmap to binding
Browse files Browse the repository at this point in the history
Add a errno -> [error code, uv error message] map to the uv binding
so the error message can be assembled in the JS layer.

Backport-PR-URL: #19191
PR-URL: #17338
Reviewed-By: James M Snell <[email protected]>
Reviewed-By: Ruben Bridgewater <[email protected]>
  • Loading branch information
joyeecheung authored and rvagg committed Aug 16, 2018
1 parent 75b456d commit c39b002
Showing 1 changed file with 22 additions and 2 deletions.
24 changes: 22 additions & 2 deletions src/uv.cc
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +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;


Expand All @@ -49,15 +53,31 @@ 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, _) \
target->Set(FIXED_ONE_BYTE_STRING(env->isolate(), "UV_" # name), \
Integer::New(env->isolate(), 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
Expand Down

0 comments on commit c39b002

Please sign in to comment.