-
Notifications
You must be signed in to change notification settings - Fork 30.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
uv: binding improvements #14933
uv: binding improvements #14933
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1030,13 +1030,16 @@ function error(...args) { | |
} | ||
|
||
function _errnoException(err, syscall, original) { | ||
var name = errname(err); | ||
if (typeof err !== 'number' || err >= 0 || !Number.isSafeInteger(err)) { | ||
throw new errors.TypeError('ERR_INVALID_ARG_TYPE', 'err', | ||
'negative number'); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Does it make sense to add the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not particularly useful. The |
||
} | ||
const name = errname(err); | ||
var message = `${syscall} ${name}`; | ||
if (original) | ||
message += ` ${original}`; | ||
var e = new Error(message); | ||
e.code = name; | ||
e.errno = name; | ||
const e = new Error(message); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. IMHO a new type something like There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That's not something I want to do in this pr There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Agreed. |
||
e.code = e.errno = name; | ||
e.syscall = syscall; | ||
return e; | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
'use strict'; | ||
|
||
require('../common'); | ||
const assert = require('assert'); | ||
const uv = process.binding('uv'); | ||
|
||
// Ensures that the `UV_...` values in process.binding('uv') | ||
// are constants. | ||
|
||
const keys = Object.keys(uv); | ||
keys.forEach((key) => { | ||
if (key === 'errname') | ||
return; // skip this | ||
const val = uv[key]; | ||
assert.throws(() => uv[key] = 1, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. So what am I thinking us 😕? I remember an old debate that ended up with the invention of |
||
/^TypeError: Cannot assign to read only property/); | ||
assert.strictEqual(uv[key], val); | ||
}); |
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
@@ -0,0 +1,31 @@ | ||||||||||||||||||||||||||||
'use strict'; | ||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||
const common = require('../common'); | ||||||||||||||||||||||||||||
const assert = require('assert'); | ||||||||||||||||||||||||||||
const util = require('util'); | ||||||||||||||||||||||||||||
const uv = process.binding('uv'); | ||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||
const keys = Object.keys(uv); | ||||||||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Personally I'd go: const keys = Object.keys(uv).filter(k => k !== 'errname'); and drop L10-11 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not particularly a fan of using filter There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ack. |
||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||
keys.forEach((key) => { | ||||||||||||||||||||||||||||
if (key === 'errname') | ||||||||||||||||||||||||||||
return; | ||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||
assert.doesNotThrow(() => { | ||||||||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm not sure the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not strictly necessary but not a problem either There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think it mangles the actual error a little bit: node/test/parallel/test-assert.js Lines 485 to 497 in 467385a
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm aware of what the function does. These cases do not throw |
||||||||||||||||||||||||||||
const err = util._errnoException(uv[key], 'test'); | ||||||||||||||||||||||||||||
const name = uv.errname(uv[key]); | ||||||||||||||||||||||||||||
assert.strictEqual(err.code, err.errno); | ||||||||||||||||||||||||||||
assert.strictEqual(err.code, name); | ||||||||||||||||||||||||||||
assert.strictEqual(err.message, `test ${name}`); | ||||||||||||||||||||||||||||
}); | ||||||||||||||||||||||||||||
}); | ||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||
[0, 1, 'test', {}, [], Infinity, -Infinity, NaN].forEach((key) => { | ||||||||||||||||||||||||||||
common.expectsError( | ||||||||||||||||||||||||||||
() => util._errnoException(key), | ||||||||||||||||||||||||||||
{ | ||||||||||||||||||||||||||||
code: 'ERR_INVALID_ARG_TYPE', | ||||||||||||||||||||||||||||
type: TypeError, | ||||||||||||||||||||||||||||
message: 'The "err" argument must be of type negative number' | ||||||||||||||||||||||||||||
}); | ||||||||||||||||||||||||||||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
-0 on this.
I like one expression per line...