Skip to content

Commit 3a7ad60

Browse files
joyeecheungMylesBorins
authored andcommitted
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. Backport-PR-URL: #19191 PR-URL: #17338 Reviewed-By: James M Snell <[email protected]> Reviewed-By: Ruben Bridgewater <[email protected]>
1 parent 591812f commit 3a7ad60

File tree

1 file changed

+22
-2
lines changed

1 file changed

+22
-2
lines changed

src/uv.cc

+22-2
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,15 @@
2727
namespace node {
2828
namespace {
2929

30+
using v8::Array;
3031
using v8::Context;
3132
using v8::FunctionCallbackInfo;
3233
using v8::Integer;
34+
using v8::Isolate;
3335
using v8::Local;
36+
using v8::Map;
3437
using v8::Object;
38+
using v8::String;
3539
using v8::Value;
3640

3741

@@ -49,15 +53,31 @@ void InitializeUV(Local<Object> target,
4953
Local<Value> unused,
5054
Local<Context> context) {
5155
Environment* env = Environment::GetCurrent(context);
52-
target->Set(FIXED_ONE_BYTE_STRING(env->isolate(), "errname"),
56+
Isolate* isolate = env->isolate();
57+
target->Set(FIXED_ONE_BYTE_STRING(isolate, "errname"),
5358
env->NewFunctionTemplate(ErrName)->GetFunction());
5459
#define V(name, _) \
5560
target->Set(FIXED_ONE_BYTE_STRING(env->isolate(), "UV_" # name), \
5661
Integer::New(env->isolate(), UV_ ## name));
5762
UV_ERRNO_MAP(V)
5863
#undef V
59-
}
6064

65+
Local<Map> err_map = Map::New(isolate);
66+
67+
#define V(name, msg) do { \
68+
Local<Array> arr = Array::New(isolate, 2); \
69+
arr->Set(0, OneByteString(isolate, #name)); \
70+
arr->Set(1, OneByteString(isolate, msg)); \
71+
err_map->Set(context, \
72+
Integer::New(isolate, UV_##name), \
73+
arr).ToLocalChecked(); \
74+
} while (0);
75+
UV_ERRNO_MAP(V)
76+
#undef V
77+
78+
target->Set(context, FIXED_ONE_BYTE_STRING(isolate, "errmap"),
79+
err_map).FromJust();
80+
}
6181

6282
} // anonymous namespace
6383
} // namespace node

0 commit comments

Comments
 (0)