| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 5e7c697 commit 58831b2
10 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -129,20 +129,18 @@ StreamWrap.prototype.doWrite = function doWrite(req, bufs) { | |||
| 129 | 129 | // Ensure that this is called once in case of error | |
| 130 | 130 | pending = 0; | |
| 131 | 131 | ||
| 132 | + let errCode = 0; | ||
| 133 | + if (err) { | ||
| 134 | + const code = uv[`UV_${err.code}`]; | ||
| 135 | + errCode = (err.code && code) ? code : uv.UV_EPIPE; | ||
| 136 | + } | ||
| 137 | + | ||
| 132 | 138 | // Ensure that write was dispatched | |
| 133 | 139 | setImmediate(function() { | |
| 134 | 140 | // Do not invoke callback twice | |
| 135 | 141 | if (!self._dequeue(item)) | |
| 136 | 142 | return; | |
| 137 | 143 | ||
| 138 | - var errCode = 0; | ||
| 139 | - if (err) { | ||
| 140 | - if (err.code && uv['UV_' + err.code]) | ||
| 141 | - errCode = uv['UV_' + err.code]; | ||
| 142 | - else | ||
| 143 | - errCode = uv.UV_EPIPE; | ||
| 144 | - } | ||
| 145 | - | ||
| 146 | 144 | handle.doAfterWrite(req); | |
| 147 | 145 | handle.finishWrite(req, errCode); | |
| 148 | 146 | }); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -27,10 +27,10 @@ const { createPromise, | |||
| 27 | 27 | promiseResolve, promiseReject } = process.binding('util'); | |
| 28 | 28 | const debug = util.debuglog('child_process'); | |
| 29 | 29 | ||
| 30 | - const uv = process.binding('uv'); | ||
| 31 | 30 | const Buffer = require('buffer').Buffer; | |
| 32 | 31 | const Pipe = process.binding('pipe_wrap').Pipe; | |
| 33 | 32 | const { isUint8Array } = process.binding('util'); | |
| 33 | + const { errname } = process.binding('uv'); | ||
| 34 | 34 | const child_process = require('internal/child_process'); | |
| 35 | 35 | ||
| 36 | 36 | const _validateStdio = child_process._validateStdio; | |
@@ -267,7 +267,7 @@ exports.execFile = function(file /*, args, options, callback*/) { | |||
| 267 | 267 | if (!ex) { | |
| 268 | 268 | ex = new Error('Command failed: ' + cmd + '\n' + stderr); | |
| 269 | 269 | ex.killed = child.killed || killed; | |
| 270 | - ex.code = code < 0 ? uv.errname(code) : code; | ||
| 270 | + ex.code = code < 0 ? errname(code) : code; | ||
| 271 | 271 | ex.signal = signal; | |
| 272 | 272 | } | |
| 273 | 273 | ||
@@ -565,7 +565,7 @@ function checkExecSyncError(ret, args, cmd) { | |||
| 565 | 565 | err = new Error(msg); | |
| 566 | 566 | } | |
| 567 | 567 | if (err) { | |
| 568 | - err.status = ret.status < 0 ? uv.errname(ret.status) : ret.status; | ||
| 568 | + err.status = ret.status < 0 ? errname(ret.status) : ret.status; | ||
| 569 | 569 | err.signal = ret.signal; | |
| 570 | 570 | } | |
| 571 | 571 | return err; | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -24,10 +24,14 @@ | |||
| 24 | 24 | const util = require('util'); | |
| 25 | 25 | ||
| 26 | 26 | const cares = process.binding('cares_wrap'); | |
| 27 | - const uv = process.binding('uv'); | ||
| 28 | 27 | const internalNet = require('internal/net'); | |
| 29 | 28 | const { customPromisifyArgs } = require('internal/util'); | |
| 30 | 29 | const errors = require('internal/errors'); | |
| 30 | + const { | ||
| 31 | + UV_EAI_MEMORY, | ||
| 32 | + UV_EAI_NODATA, | ||
| 33 | + UV_EAI_NONAME | ||
| 34 | + } = process.binding('uv'); | ||
| 31 | 35 | ||
| 32 | 36 | const { | |
| 33 | 37 | GetAddrInfoReqWrap, | |
@@ -43,9 +47,9 @@ const isLegalPort = internalNet.isLegalPort; | |||
| 43 | 47 | function errnoException(err, syscall, hostname) { | |
| 44 | 48 | // FIXME(bnoordhuis) Remove this backwards compatibility nonsense and pass | |
| 45 | 49 | // the true error to the user. ENOTFOUND is not even a proper POSIX error! | |
| 46 | - if (err === uv.UV_EAI_MEMORY || | ||
| 47 | - err === uv.UV_EAI_NODATA || | ||
| 48 | - err === uv.UV_EAI_NONAME) { | ||
| 50 | + if (err === UV_EAI_MEMORY || | ||
| 51 | + err === UV_EAI_NODATA || | ||
| 52 | + err === UV_EAI_NONAME) { | ||
| 49 | 53 | err = 'ENOTFOUND'; | |
| 50 | 54 | } | |
| 51 | 55 | var ex = null; | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -10,7 +10,6 @@ const assert = require('assert'); | |||
| 10 | 10 | ||
| 11 | 11 | const Process = process.binding('process_wrap').Process; | |
| 12 | 12 | const WriteWrap = process.binding('stream_wrap').WriteWrap; | |
| 13 | - const uv = process.binding('uv'); | ||
| 14 | 13 | const Pipe = process.binding('pipe_wrap').Pipe; | |
| 15 | 14 | const TTY = process.binding('tty_wrap').TTY; | |
| 16 | 15 | const TCP = process.binding('tcp_wrap').TCP; | |
@@ -20,6 +19,16 @@ const { isUint8Array } = process.binding('util'); | |||
| 20 | 19 | const { convertToValidSignal } = require('internal/util'); | |
| 21 | 20 | const spawn_sync = process.binding('spawn_sync'); | |
| 22 | 21 | ||
| 22 | + const { | ||
| 23 | + UV_EAGAIN, | ||
| 24 | + UV_EINVAL, | ||
| 25 | + UV_EMFILE, | ||
| 26 | + UV_ENFILE, | ||
| 27 | + UV_ENOENT, | ||
| 28 | + UV_ENOSYS, | ||
| 29 | + UV_ESRCH | ||
| 30 | + } = process.binding('uv'); | ||
| 31 | + | ||
| 23 | 32 | const errnoException = util._errnoException; | |
| 24 | 33 | const SocketListSend = SocketList.SocketListSend; | |
| 25 | 34 | const SocketListReceive = SocketList.SocketListReceive; | |
@@ -307,17 +316,17 @@ ChildProcess.prototype.spawn = function(options) { | |||
| 307 | 316 | var err = this._handle.spawn(options); | |
| 308 | 317 | ||
| 309 | 318 | // Run-time errors should emit an error, not throw an exception. | |
| 310 | - if (err === uv.UV_EAGAIN || | ||
| 311 | - err === uv.UV_EMFILE || | ||
| 312 | - err === uv.UV_ENFILE || | ||
| 313 | - err === uv.UV_ENOENT) { | ||
| 319 | + if (err === UV_EAGAIN || | ||
| 320 | + err === UV_EMFILE || | ||
| 321 | + err === UV_ENFILE || | ||
| 322 | + err === UV_ENOENT) { | ||
| 314 | 323 | process.nextTick(onErrorNT, this, err); | |
| 315 | 324 | // There is no point in continuing when we've hit EMFILE or ENFILE | |
| 316 | 325 | // because we won't be able to set up the stdio file descriptors. | |
| 317 | 326 | // It's kind of silly that the de facto spec for ENOENT (the test suite) | |
| 318 | 327 | // mandates that stdio _is_ set up, even if there is no process on the | |
| 319 | 328 | // receiving end, but it is what it is. | |
| 320 | - if (err !== uv.UV_ENOENT) return err; | ||
| 329 | + if (err !== UV_ENOENT) return err; | ||
| 321 | 330 | } else if (err) { | |
| 322 | 331 | // Close all opened fds on error | |
| 323 | 332 | for (i = 0; i < stdio.length; i++) { | |
@@ -394,9 +403,9 @@ ChildProcess.prototype.kill = function(sig) { | |||
| 394 | 403 | this.killed = true; | |
| 395 | 404 | return true; | |
| 396 | 405 | } | |
| 397 | - if (err === uv.UV_ESRCH) { | ||
| 406 | + if (err === UV_ESRCH) { | ||
| 398 | 407 | /* Already dead. */ | |
| 399 | - } else if (err === uv.UV_EINVAL || err === uv.UV_ENOSYS) { | ||
| 408 | + } else if (err === UV_EINVAL || err === UV_ENOSYS) { | ||
| 400 | 409 | /* The underlying platform doesn't support this signal. */ | |
| 401 | 410 | throw errnoException(err, 'kill'); | |
| 402 | 411 | } else { | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -56,8 +56,7 @@ RoundRobinHandle.prototype.add = function(worker, send) { | |||
| 56 | 56 | // Hack: translate 'EADDRINUSE' error string back to numeric error code. | |
| 57 | 57 | // It works but ideally we'd have some backchannel between the net and | |
| 58 | 58 | // cluster modules for stuff like this. | |
| 59 | - const errno = uv['UV_' + err.errno]; | ||
| 60 | - send(errno, null); | ||
| 59 | + send(uv[`UV_${err.errno}`], null); | ||
| 61 | 60 | }); | |
| 62 | 61 | }; | |
| 63 | 62 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -29,7 +29,11 @@ const internalUtil = require('internal/util'); | |||
| 29 | 29 | const internalNet = require('internal/net'); | |
| 30 | 30 | const assert = require('assert'); | |
| 31 | 31 | const cares = process.binding('cares_wrap'); | |
| 32 | - const uv = process.binding('uv'); | ||
| 32 | + const { | ||
| 33 | + UV_EADDRINUSE, | ||
| 34 | + UV_EINVAL, | ||
| 35 | + UV_EOF | ||
| 36 | + } = process.binding('uv'); | ||
| 33 | 37 | ||
| 34 | 38 | const Buffer = require('buffer').Buffer; | |
| 35 | 39 | const TTYWrap = process.binding('tty_wrap'); | |
@@ -604,7 +608,7 @@ function onread(nread, buffer) { | |||
| 604 | 608 | } | |
| 605 | 609 | ||
| 606 | 610 | // Error, possibly EOF. | |
| 607 | - if (nread !== uv.UV_EOF) { | ||
| 611 | + if (nread !== UV_EOF) { | ||
| 608 | 612 | return self.destroy(errnoException(nread, 'read')); | |
| 609 | 613 | } | |
| 610 | 614 | ||
@@ -1229,7 +1233,7 @@ function createServerHandle(address, port, addressType, fd) { | |||
| 1229 | 1233 | } catch (e) { | |
| 1230 | 1234 | // Not a fd we can listen on. This will trigger an error. | |
| 1231 | 1235 | debug('listen invalid fd=%d:', fd, e.message); | |
| 1232 | - return uv.UV_EINVAL; | ||
| 1236 | + return UV_EINVAL; | ||
| 1233 | 1237 | } | |
| 1234 | 1238 | handle.open(fd); | |
| 1235 | 1239 | handle.readable = true; | |
@@ -1389,7 +1393,7 @@ function listenInCluster(server, address, port, addressType, | |||
| 1389 | 1393 | var out = {}; | |
| 1390 | 1394 | err = handle.getsockname(out); | |
| 1391 | 1395 | if (err === 0 && port !== out.port) | |
| 1392 | - err = uv.UV_EADDRINUSE; | ||
| 1396 | + err = UV_EADDRINUSE; | ||
| 1393 | 1397 | } | |
| 1394 | 1398 | ||
| 1395 | 1399 | if (err) { | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1031,13 +1031,16 @@ function error(...args) { | |||
| 1031 | 1031 | } | |
| 1032 | 1032 | ||
| 1033 | 1033 | function _errnoException(err, syscall, original) { | |
| 1034 | - var name = errname(err); | ||
| 1034 | + if (typeof err !== 'number' || err >= 0 || !Number.isSafeInteger(err)) { | ||
| 1035 | + throw new errors.TypeError('ERR_INVALID_ARG_TYPE', 'err', | ||
| 1036 | + 'negative number'); | ||
| 1037 | + } | ||
| 1038 | + const name = errname(err); | ||
| 1035 | 1039 | var message = `${syscall} ${name}`; | |
| 1036 | 1040 | if (original) | |
| 1037 | 1041 | message += ` ${original}`; | |
| 1038 | - var e = new Error(message); | ||
| 1039 | - e.code = name; | ||
| 1040 | - e.errno = name; | ||
| 1042 | + const e = new Error(message); | ||
| 1043 | + e.code = e.errno = name; | ||
| 1041 | 1044 | e.syscall = syscall; | |
| 1042 | 1045 | return e; | |
| 1043 | 1046 | } | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -29,7 +29,6 @@ namespace { | |||
| 29 | 29 | ||
| 30 | 30 | using v8::Context; | |
| 31 | 31 | using v8::FunctionCallbackInfo; | |
| 32 | - using v8::Integer; | ||
| 33 | 32 | using v8::Local; | |
| 34 | 33 | using v8::Object; | |
| 35 | 34 | using v8::Value; | |
@@ -38,8 +37,7 @@ using v8::Value; | |||
| 38 | 37 | void ErrName(const FunctionCallbackInfo<Value>& args) { | |
| 39 | 38 | Environment* env = Environment::GetCurrent(args); | |
| 40 | 39 | int err = args[0]->Int32Value(); | |
| 41 | - if (err >= 0) | ||
| 42 | - return env->ThrowError("err >= 0"); | ||
| 40 | + CHECK_LT(err, 0); | ||
| 43 | 41 | const char* name = uv_err_name(err); | |
| 44 | 42 | args.GetReturnValue().Set(OneByteString(env->isolate(), name)); | |
| 45 | 43 | } | |
@@ -51,9 +49,8 @@ void InitializeUV(Local<Object> target, | |||
| 51 | 49 | Environment* env = Environment::GetCurrent(context); | |
| 52 | 50 | target->Set(FIXED_ONE_BYTE_STRING(env->isolate(), "errname"), | |
| 53 | 51 | env->NewFunctionTemplate(ErrName)->GetFunction()); | |
| 54 | - #define V(name, _) \ | ||
| 55 | - target->Set(FIXED_ONE_BYTE_STRING(env->isolate(), "UV_" # name), \ | ||
| 56 | - Integer::New(env->isolate(), UV_ ## name)); | ||
| 52 | + | ||
| 53 | + #define V(name, _) NODE_DEFINE_CONSTANT(target, UV_##name); | ||
| 57 | 54 | UV_ERRNO_MAP(V) | |
| 58 | 55 | #undef V | |
| 59 | 56 | } | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,18 @@ | |||
| 1 | + 'use strict'; | ||
| 2 | + | ||
| 3 | + require('../common'); | ||
| 4 | + const assert = require('assert'); | ||
| 5 | + const uv = process.binding('uv'); | ||
| 6 | + | ||
| 7 | + // Ensures that the `UV_...` values in process.binding('uv') | ||
| 8 | + // are constants. | ||
| 9 | + | ||
| 10 | + const keys = Object.keys(uv); | ||
| 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); | ||
| 18 | + }); | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,31 @@ | |||
| 1 | + 'use strict'; | ||
| 2 | + | ||
| 3 | + const common = require('../common'); | ||
| 4 | + const assert = require('assert'); | ||
| 5 | + const util = require('util'); | ||
| 6 | + const uv = process.binding('uv'); | ||
| 7 | + | ||
| 8 | + const keys = Object.keys(uv); | ||
| 9 | + | ||
| 10 | + keys.forEach((key) => { | ||
| 11 | + if (key === 'errname') | ||
| 12 | + return; | ||
| 13 | + | ||
| 14 | + assert.doesNotThrow(() => { | ||
| 15 | + const err = util._errnoException(uv[key], 'test'); | ||
| 16 | + const name = uv.errname(uv[key]); | ||
| 17 | + assert.strictEqual(err.code, err.errno); | ||
| 18 | + assert.strictEqual(err.code, name); | ||
| 19 | + assert.strictEqual(err.message, `test ${name}`); | ||
| 20 | + }); | ||
| 21 | + }); | ||
| 22 | + | ||
| 23 | + [0, 1, 'test', {}, [], Infinity, -Infinity, NaN].forEach((key) => { | ||
| 24 | + common.expectsError( | ||
| 25 | + () => util._errnoException(key), | ||
| 26 | + { | ||
| 27 | + code: 'ERR_INVALID_ARG_TYPE', | ||
| 28 | + type: TypeError, | ||
| 29 | + message: 'The "err" argument must be of type negative number' | ||
| 30 | + }); | ||
| 31 | + }); | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments