mirror of https://github.com/lukechilds/node.git
Browse Source
* ensure that UV_... props are constants * improve error message ... the error message when passing in `err >= 0` to `util._errnoException()` was less than useful. * refine uses of process.binding('uv') PR-URL: https://github.com/nodejs/node/pull/14933 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Refael Ackermann <refack@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com>canary-base
10 changed files with 102 additions and 39 deletions
@ -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, |
|||
/^TypeError: Cannot assign to read only property/); |
|||
assert.strictEqual(uv[key], val); |
|||
}); |
@ -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); |
|||
|
|||
keys.forEach((key) => { |
|||
if (key === 'errname') |
|||
return; |
|||
|
|||
assert.doesNotThrow(() => { |
|||
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' |
|||
}); |
|||
}); |
Loading…
Reference in new issue