Skip to content

Commit

Permalink
uv: move process.binding('uv') to internalBinding
Browse files Browse the repository at this point in the history
  • Loading branch information
jasnell committed Aug 9, 2018
1 parent c1e2d6b commit 300895b
Show file tree
Hide file tree
Showing 25 changed files with 143 additions and 84 deletions.
4 changes: 3 additions & 1 deletion lib/internal/child_process.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ const { HTTPParser } = process.binding('http_parser');
const { freeParser } = require('_http_common');
const { kStateSymbol } = require('internal/dgram');

const { internalBinding } = require('internal/bootstrap/loaders');

const {
UV_EACCES,
UV_EAGAIN,
Expand All @@ -45,7 +47,7 @@ const {
UV_ENOENT,
UV_ENOSYS,
UV_ESRCH
} = process.binding('uv');
} = internalBinding('uv');

const { SocketListSend, SocketListReceive } = SocketList;

Expand Down
3 changes: 2 additions & 1 deletion lib/internal/cluster/round_robin_handle.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ const assert = require('assert');
const net = require('net');
const { sendHelper } = require('internal/cluster/utils');
const getOwnPropertyNames = Object.getOwnPropertyNames;
const uv = process.binding('uv');
const { internalBinding } = require('internal/bootstrap/loaders');
const uv = internalBinding('uv');

module.exports = RoundRobinHandle;

Expand Down
3 changes: 2 additions & 1 deletion lib/internal/dgram.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ const { codes } = require('internal/errors');
const { UDP } = process.binding('udp_wrap');
const { isInt32 } = require('internal/validators');
const TTYWrap = process.binding('tty_wrap');
const { UV_EINVAL } = process.binding('uv');
const { internalBinding } = require('internal/bootstrap/loaders');
const { UV_EINVAL } = internalBinding('uv');
const { ERR_INVALID_ARG_TYPE, ERR_SOCKET_BAD_TYPE } = codes;
const kStateSymbol = Symbol('state symbol');
let dns; // Lazy load for startup performance.
Expand Down
3 changes: 2 additions & 1 deletion lib/internal/errors.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,12 @@ const kInfo = Symbol('info');
const messages = new Map();
const codes = {};

const { internalBinding } = require('internal/bootstrap/loaders');
const {
errmap,
UV_EAI_NODATA,
UV_EAI_NONAME
} = process.binding('uv');
} = internalBinding('uv');
const { kMaxLength } = process.binding('buffer');
const { defineProperty } = Object;

Expand Down
2 changes: 1 addition & 1 deletion lib/internal/http2/core.js
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ const { isArrayBufferView } = require('internal/util/types');
const { FileHandle } = process.binding('fs');
const binding = process.binding('http2');
const { ShutdownWrap } = process.binding('stream_wrap');
const { UV_EOF } = process.binding('uv');
const { UV_EOF } = internalBinding('uv');

const { StreamPipe } = internalBinding('stream_pipe');
const { _connectionListener: httpConnectionListener } = http;
Expand Down
4 changes: 3 additions & 1 deletion lib/internal/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@ const {
arrow_message_private_symbol: kArrowMessagePrivateSymbolIndex,
decorated_private_symbol: kDecoratedPrivateSymbolIndex
} = process.binding('util');
const { errmap } = process.binding('uv');

const { internalBinding } = require('internal/bootstrap/loaders');
const { errmap } = internalBinding('uv');

const noCrypto = !process.versions.openssl;

Expand Down
3 changes: 2 additions & 1 deletion lib/internal/wrap_js_stream.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ const assert = require('assert');
const util = require('util');
const { Socket } = require('net');
const { JSStream } = process.binding('js_stream');
const uv = process.binding('uv');
const { internalBinding } = require('internal/bootstrap/loaders');
const uv = internalBinding('uv');
const debug = util.debuglog('stream_wrap');
const { owner_symbol } = require('internal/async_hooks').symbols;
const { ERR_STREAM_WRAP } = require('internal/errors').codes;
Expand Down
3 changes: 2 additions & 1 deletion lib/net.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,12 @@ const {
makeSyncWrite
} = require('internal/net');
const assert = require('assert');
const { internalBinding } = require('internal/bootstrap/loaders');
const {
UV_EADDRINUSE,
UV_EINVAL,
UV_EOF
} = process.binding('uv');
} = internalBinding('uv');

const { Buffer } = require('buffer');
const TTYWrap = process.binding('tty_wrap');
Expand Down
2 changes: 1 addition & 1 deletion src/uv.cc
Original file line number Diff line number Diff line change
Expand Up @@ -82,4 +82,4 @@ void Initialize(Local<Object> target,
} // anonymous namespace
} // namespace node

NODE_BUILTIN_MODULE_CONTEXT_AWARE(uv, node::Initialize)
NODE_MODULE_CONTEXT_AWARE_INTERNAL(uv, node::Initialize)
4 changes: 3 additions & 1 deletion test/parallel/test-dgram-cluster-bind-error.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
// Flags: --expose-internals
'use strict';
const common = require('../common');
const assert = require('assert');
const cluster = require('cluster');
const dgram = require('dgram');
const { UV_UNKNOWN } = process.binding('uv');
const { internalBinding } = require('internal/test/binding');
const { UV_UNKNOWN } = internalBinding('uv');

if (cluster.isMaster) {
cluster.fork();
Expand Down
5 changes: 3 additions & 2 deletions test/parallel/test-dgram-send-error.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
const common = require('../common');
const assert = require('assert');
const dgram = require('dgram');
const { internalBinding } = require('internal/test/binding');
const { UV_UNKNOWN } = internalBinding('uv');
const { kStateSymbol } = require('internal/dgram');
const mockError = new Error('mock DNS error');

Expand Down Expand Up @@ -45,7 +47,6 @@ getSocket((socket) => {

socket.bind(common.mustCall(() => {
const port = socket.address().port;
const errCode = process.binding('uv').UV_UNKNOWN;
const callback = common.mustCall((err) => {
socket.close();
assert.strictEqual(err.code, 'UNKNOWN');
Expand All @@ -60,7 +61,7 @@ getSocket((socket) => {
});

socket[kStateSymbol].handle.send = function() {
return errCode;
return UV_UNKNOWN;
};

socket.send('foo', port, common.localhostIPv4, callback);
Expand Down
15 changes: 10 additions & 5 deletions test/parallel/test-dgram-socket-buffer-size.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,22 @@
'use strict';
// Flags: --expose-internals
'use strict';

const common = require('../common');
const assert = require('assert');
const dgram = require('dgram');
const { SystemError } = require('internal/errors');
const uv = process.binding('uv');
const { internalBinding } = require('internal/test/binding');
const {
UV_EBADF,
UV_EINVAL,
UV_ENOTSOCK
} = internalBinding('uv');

function getExpectedError(type) {
const code = common.isWindows ? 'ENOTSOCK' : 'EBADF';
const message = common.isWindows ?
'socket operation on non-socket' : 'bad file descriptor';
const errno = common.isWindows ? uv.UV_ENOTSOCK : uv.UV_EBADF;
const errno = common.isWindows ? UV_ENOTSOCK : UV_EBADF;
const syscall = `uv_${type}_buffer_size`;
const suffix = common.isWindows ?
'ENOTSOCK (socket operation on non-socket)' : 'EBADF (bad file descriptor)';
Expand Down Expand Up @@ -105,7 +110,7 @@ function getExpectedError(type) {
const info = {
code: 'EINVAL',
message: 'invalid argument',
errno: uv.UV_EINVAL,
errno: UV_EINVAL,
syscall: 'uv_recv_buffer_size'
};
const errorObj = {
Expand All @@ -128,7 +133,7 @@ function getExpectedError(type) {
const info = {
code: 'EINVAL',
message: 'invalid argument',
errno: uv.UV_EINVAL,
errno: UV_EINVAL,
syscall: 'uv_send_buffer_size'
};
const errorObj = {
Expand Down
5 changes: 4 additions & 1 deletion test/parallel/test-dns-lookup.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
// Flags: --expose-internals
'use strict';
const common = require('../common');
const assert = require('assert');
const cares = process.binding('cares_wrap');
const dns = require('dns');
const dnsPromises = dns.promises;

const { internalBinding } = require('internal/test/binding');

// Stub `getaddrinfo` to *always* error.
cares.getaddrinfo = () => process.binding('uv').UV_ENOENT;
cares.getaddrinfo = () => internalBinding('uv').UV_ENOENT;

{
const err = {
Expand Down
3 changes: 2 additions & 1 deletion test/parallel/test-dns-memory-error.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,9 @@ require('../common');

const assert = require('assert');
const errors = require('internal/errors');
const { internalBinding } = require('internal/test/binding');

const { UV_EAI_MEMORY } = process.binding('uv');
const { UV_EAI_MEMORY } = internalBinding('uv');
const memoryError = errors.dnsException(UV_EAI_MEMORY, 'fhqwhgads');

assert.strictEqual(memoryError.code, 'EAI_MEMORY');
8 changes: 5 additions & 3 deletions test/parallel/test-fs-access.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// Flags: --expose-internals
'use strict';

// This tests that fs.access and fs.accessSync works as expected
Expand All @@ -8,7 +9,8 @@ const assert = require('assert');
const fs = require('fs');
const path = require('path');

const uv = process.binding('uv');
const { internalBinding } = require('internal/test/binding');
const { UV_ENOENT } = internalBinding('uv');

const tmpdir = require('../common/tmpdir');
const doesNotExist = path.join(tmpdir.path, '__this_should_not_exist');
Expand Down Expand Up @@ -161,7 +163,7 @@ assert.throws(
);
assert.strictEqual(err.constructor, Error);
assert.strictEqual(err.syscall, 'access');
assert.strictEqual(err.errno, uv.UV_ENOENT);
assert.strictEqual(err.errno, UV_ENOENT);
return true;
}
);
Expand All @@ -177,7 +179,7 @@ assert.throws(
);
assert.strictEqual(err.constructor, Error);
assert.strictEqual(err.syscall, 'access');
assert.strictEqual(err.errno, uv.UV_ENOENT);
assert.strictEqual(err.errno, UV_ENOENT);
return true;
}
);
11 changes: 8 additions & 3 deletions test/parallel/test-fs-copyfile.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
// Flags: --expose-internals
'use strict';
const common = require('../common');
const fixtures = require('../common/fixtures');
const tmpdir = require('../common/tmpdir');
const assert = require('assert');
const fs = require('fs');
const uv = process.binding('uv');
const { internalBinding } = require('internal/test/binding');
const {
UV_ENOENT,
UV_EEXIST
} = internalBinding('uv');
const path = require('path');
const src = fixtures.path('a.js');
const dest = path.join(tmpdir.path, 'copyfile.out');
Expand Down Expand Up @@ -81,14 +86,14 @@ fs.copyFile(src, dest, common.mustCall((err) => {
assert.strictEqual(err.message,
'ENOENT: no such file or directory, copyfile ' +
`'${src}' -> '${dest}'`);
assert.strictEqual(err.errno, uv.UV_ENOENT);
assert.strictEqual(err.errno, UV_ENOENT);
assert.strictEqual(err.code, 'ENOENT');
assert.strictEqual(err.syscall, 'copyfile');
} else {
assert.strictEqual(err.message,
'EEXIST: file already exists, copyfile ' +
`'${src}' -> '${dest}'`);
assert.strictEqual(err.errno, uv.UV_EEXIST);
assert.strictEqual(err.errno, UV_EEXIST);
assert.strictEqual(err.code, 'EEXIST');
assert.strictEqual(err.syscall, 'copyfile');
}
Expand Down
Loading

0 comments on commit 300895b

Please sign in to comment.