Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 4de4c54

Browse filesBrowse 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: #18916 PR-URL: #17338 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
1 parent 8c93499 commit 4de4c54
Copy full SHA for 4de4c54

File tree

Expand file treeCollapse file tree

3 files changed

+30
-9
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

3 files changed

+30
-9
lines changed
Open diff view settings
Collapse file

‎src/uv.cc‎

Copy file name to clipboardExpand all lines: src/uv.cc
+23-2Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,15 @@
2727
namespace node {
2828
namespace {
2929

30+
using v8::Array;
3031
using v8::Context;
3132
using v8::FunctionCallbackInfo;
33+
using v8::Integer;
34+
using v8::Isolate;
3235
using v8::Local;
36+
using v8::Map;
3337
using v8::Object;
38+
using v8::String;
3439
using v8::Value;
3540

3641

@@ -47,14 +52,30 @@ void InitializeUV(Local<Object> target,
4752
Local<Value> unused,
4853
Local<Context> context) {
4954
Environment* env = Environment::GetCurrent(context);
50-
target->Set(FIXED_ONE_BYTE_STRING(env->isolate(), "errname"),
55+
Isolate* isolate = env->isolate();
56+
target->Set(FIXED_ONE_BYTE_STRING(isolate, "errname"),
5157
env->NewFunctionTemplate(ErrName)->GetFunction());
5258

5359
#define V(name, _) NODE_DEFINE_CONSTANT(target, UV_##name);
5460
UV_ERRNO_MAP(V)
5561
#undef V
56-
}
5762

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

5980
} // anonymous namespace
6081
} // namespace node
Collapse file

‎test/parallel/test-uv-binding-constant.js‎

Copy file name to clipboardExpand all lines: test/parallel/test-uv-binding-constant.js
+6-6Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,10 @@ const uv = process.binding('uv');
99

1010
const keys = Object.keys(uv);
1111
keys.forEach((key) => {
12-
if (key === 'errname')
13-
return; // skip this
14-
const val = uv[key];
15-
assert.throws(() => uv[key] = 1,
16-
/^TypeError: Cannot assign to read only property/);
17-
assert.strictEqual(uv[key], val);
12+
if (key.startsWith('UV_')) {
13+
const val = uv[key];
14+
assert.throws(() => uv[key] = 1,
15+
/^TypeError: Cannot assign to read only property/);
16+
assert.strictEqual(uv[key], val);
17+
}
1818
});
Collapse file

‎test/parallel/test-uv-errno.js‎

Copy file name to clipboardExpand all lines: test/parallel/test-uv-errno.js
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ const uv = process.binding('uv');
88
const keys = Object.keys(uv);
99

1010
keys.forEach((key) => {
11-
if (key === 'errname')
11+
if (!key.startsWith('UV_'))
1212
return;
1313

1414
assert.doesNotThrow(() => {

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.