GeezerVison is showing github.com — src: expose uv.errmap to binding · nodejs/node@4de4c54
File treeExpand file treeCollapse file tree Open diff view settings Expand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboardExpand all lines: src/uv.cc +23-2Lines changed: 23 additions & 2 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 27 | 27 | namespace node { | 28 | 28 | namespace { | 29 | 29 |
| | 30 | +using v8::Array; | 30 | 31 | using v8::Context; | 31 | 32 | using v8::FunctionCallbackInfo; | | 33 | +using v8::Integer; | | 34 | +using v8::Isolate; | 32 | 35 | using v8::Local; | | 36 | +using v8::Map; | 33 | 37 | using v8::Object; | | 38 | +using v8::String; | 34 | 39 | using v8::Value; | 35 | 40 |
| 36 | 41 |
| @@ -47,14 +52,30 @@ void InitializeUV(Local<Object> target, | 47 | 52 | Local<Value> unused, | 48 | 53 | Local<Context> context) { | 49 | 54 | 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"), | 51 | 57 | env->NewFunctionTemplate(ErrName)->GetFunction()); | 52 | 58 |
| 53 | 59 | #define V(name, _) NODE_DEFINE_CONSTANT(target, UV_##name); | 54 | 60 | UV_ERRNO_MAP(V) | 55 | 61 | #undef V | 56 | | -} | 57 | 62 |
| | 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 | +} | 58 | 79 |
| 59 | 80 | } // anonymous namespace | 60 | 81 | } // namespace node | |
Collapse file Copy file name to clipboardExpand all lines: test/parallel/test-uv-binding-constant.js +6-6Lines changed: 6 additions & 6 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -9,10 +9,10 @@ const uv = process.binding('uv'); | 9 | 9 |
| 10 | 10 | const keys = Object.keys(uv); | 11 | 11 | 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 | + } | 18 | 18 | }); |
Collapse file Copy file name to clipboardExpand all lines: test/parallel/test-uv-errno.js +1-1Lines changed: 1 addition & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -8,7 +8,7 @@ const uv = process.binding('uv'); | 8 | 8 | const keys = Object.keys(uv); | 9 | 9 |
| 10 | 10 | keys.forEach((key) => { | 11 | | - if (key === 'errname') | | 11 | + if (!key.startsWith('UV_')) | 12 | 12 | return; | 13 | 13 |
| 14 | 14 | assert.doesNotThrow(() => { | |
|