diff --git a/lib/internal/child_process.js b/lib/internal/child_process.js index 32568aa31128a6..c34bc996de9664 100644 --- a/lib/internal/child_process.js +++ b/lib/internal/child_process.js @@ -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, @@ -45,7 +47,7 @@ const { UV_ENOENT, UV_ENOSYS, UV_ESRCH -} = process.binding('uv'); +} = internalBinding('uv'); const { SocketListSend, SocketListReceive } = SocketList; diff --git a/lib/internal/cluster/round_robin_handle.js b/lib/internal/cluster/round_robin_handle.js index b2dff017e8b6ee..e351f433ab8c7e 100644 --- a/lib/internal/cluster/round_robin_handle.js +++ b/lib/internal/cluster/round_robin_handle.js @@ -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; diff --git a/lib/internal/dgram.js b/lib/internal/dgram.js index e9b5364c8e3674..e01b0d782fdab6 100644 --- a/lib/internal/dgram.js +++ b/lib/internal/dgram.js @@ -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. diff --git a/lib/internal/errors.js b/lib/internal/errors.js index 862ec2dbe62b67..6062c0b7d9bac9 100644 --- a/lib/internal/errors.js +++ b/lib/internal/errors.js @@ -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; diff --git a/lib/internal/http2/core.js b/lib/internal/http2/core.js index 568980c927bdb8..fe738bb4d60cc3 100644 --- a/lib/internal/http2/core.js +++ b/lib/internal/http2/core.js @@ -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; diff --git a/lib/internal/util.js b/lib/internal/util.js index 54f725f172df3c..bf8f9c26cf6e9a 100644 --- a/lib/internal/util.js +++ b/lib/internal/util.js @@ -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; diff --git a/lib/internal/wrap_js_stream.js b/lib/internal/wrap_js_stream.js index e80716059ef6e7..5ffdd23a7db3bf 100644 --- a/lib/internal/wrap_js_stream.js +++ b/lib/internal/wrap_js_stream.js @@ -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; diff --git a/lib/net.js b/lib/net.js index c49dd350c36944..b7b91a71f17659 100644 --- a/lib/net.js +++ b/lib/net.js @@ -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'); diff --git a/src/uv.cc b/src/uv.cc index 85cb2ad5373c5f..45791b28a935f0 100644 --- a/src/uv.cc +++ b/src/uv.cc @@ -82,4 +82,4 @@ void Initialize(Local target, } // anonymous namespace } // namespace node -NODE_BUILTIN_MODULE_CONTEXT_AWARE(uv, node::Initialize) +NODE_MODULE_CONTEXT_AWARE_INTERNAL(uv, node::Initialize) diff --git a/test/parallel/test-dgram-cluster-bind-error.js b/test/parallel/test-dgram-cluster-bind-error.js index ad33328d4098bf..fb338da9727123 100644 --- a/test/parallel/test-dgram-cluster-bind-error.js +++ b/test/parallel/test-dgram-cluster-bind-error.js @@ -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(); diff --git a/test/parallel/test-dgram-send-error.js b/test/parallel/test-dgram-send-error.js index 7757db1e2d4474..f6d37f2c818112 100644 --- a/test/parallel/test-dgram-send-error.js +++ b/test/parallel/test-dgram-send-error.js @@ -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'); @@ -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'); @@ -60,7 +61,7 @@ getSocket((socket) => { }); socket[kStateSymbol].handle.send = function() { - return errCode; + return UV_UNKNOWN; }; socket.send('foo', port, common.localhostIPv4, callback); diff --git a/test/parallel/test-dgram-socket-buffer-size.js b/test/parallel/test-dgram-socket-buffer-size.js index 834ca30c57d926..c2936ba8fd91b0 100644 --- a/test/parallel/test-dgram-socket-buffer-size.js +++ b/test/parallel/test-dgram-socket-buffer-size.js @@ -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)'; @@ -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 = { @@ -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 = { diff --git a/test/parallel/test-dns-lookup.js b/test/parallel/test-dns-lookup.js index 3413bcffd8abe9..99378ce01e918a 100644 --- a/test/parallel/test-dns-lookup.js +++ b/test/parallel/test-dns-lookup.js @@ -1,3 +1,4 @@ +// Flags: --expose-internals 'use strict'; const common = require('../common'); const assert = require('assert'); @@ -5,8 +6,10 @@ 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 = { diff --git a/test/parallel/test-dns-memory-error.js b/test/parallel/test-dns-memory-error.js index 2048ad4c4ea6d3..29907fb1dbfd5e 100644 --- a/test/parallel/test-dns-memory-error.js +++ b/test/parallel/test-dns-memory-error.js @@ -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'); diff --git a/test/parallel/test-fs-access.js b/test/parallel/test-fs-access.js index d053b9323bc275..02e9356275dbc7 100644 --- a/test/parallel/test-fs-access.js +++ b/test/parallel/test-fs-access.js @@ -1,3 +1,4 @@ +// Flags: --expose-internals 'use strict'; // This tests that fs.access and fs.accessSync works as expected @@ -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'); @@ -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; } ); @@ -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; } ); diff --git a/test/parallel/test-fs-copyfile.js b/test/parallel/test-fs-copyfile.js index f001535598bbeb..90e7c7009d1680 100644 --- a/test/parallel/test-fs-copyfile.js +++ b/test/parallel/test-fs-copyfile.js @@ -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'); @@ -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'); } diff --git a/test/parallel/test-fs-error-messages.js b/test/parallel/test-fs-error-messages.js index 8ef009e8128b0d..4ca9fb2ef9c21c 100644 --- a/test/parallel/test-fs-error-messages.js +++ b/test/parallel/test-fs-error-messages.js @@ -1,3 +1,4 @@ +// Flags: --expose-internals // Copyright Joyent, Inc. and other Node contributors. // // Permission is hereby granted, free of charge, to any person obtaining a @@ -35,7 +36,16 @@ const existingFile2 = fixtures.path('create-file.js'); const existingDir = tmpdir.path; const existingDir2 = fixtures.path('keys'); const { COPYFILE_EXCL } = fs.constants; -const uv = process.binding('uv'); +const { internalBinding } = require('internal/test/binding'); +const { + UV_EBADF, + UV_EEXIST, + UV_EINVAL, + UV_ENOENT, + UV_ENOTDIR, + UV_ENOTEMPTY, + UV_EPERM +} = internalBinding('uv'); // Template tag function for escaping special characters in strings so that: // new RegExp(re`${str}`).test(str) === true @@ -56,7 +66,7 @@ function re(literals, ...values) { assert.strictEqual( err.message, `ENOENT: no such file or directory, stat '${nonexistentFile}'`); - assert.strictEqual(err.errno, uv.UV_ENOENT); + assert.strictEqual(err.errno, UV_ENOENT); assert.strictEqual(err.code, 'ENOENT'); assert.strictEqual(err.syscall, 'stat'); return true; @@ -77,7 +87,7 @@ function re(literals, ...values) { assert.strictEqual( err.message, `ENOENT: no such file or directory, lstat '${nonexistentFile}'`); - assert.strictEqual(err.errno, uv.UV_ENOENT); + assert.strictEqual(err.errno, UV_ENOENT); assert.strictEqual(err.code, 'ENOENT'); assert.strictEqual(err.syscall, 'lstat'); return true; @@ -94,7 +104,7 @@ function re(literals, ...values) { { const validateError = (err) => { assert.strictEqual(err.message, 'EBADF: bad file descriptor, fstat'); - assert.strictEqual(err.errno, uv.UV_EBADF); + assert.strictEqual(err.errno, UV_EBADF); assert.strictEqual(err.code, 'EBADF'); assert.strictEqual(err.syscall, 'fstat'); return true; @@ -117,7 +127,7 @@ function re(literals, ...values) { assert.strictEqual( err.message, `ENOENT: no such file or directory, lstat '${nonexistentFile}'`); - assert.strictEqual(err.errno, uv.UV_ENOENT); + assert.strictEqual(err.errno, UV_ENOENT); assert.strictEqual(err.code, 'ENOENT'); assert.strictEqual(err.syscall, 'lstat'); return true; @@ -138,7 +148,7 @@ function re(literals, ...values) { assert.strictEqual( err.message, `ENOENT: no such file or directory, realpath '${nonexistentFile}'`); - assert.strictEqual(err.errno, uv.UV_ENOENT); + assert.strictEqual(err.errno, UV_ENOENT); assert.strictEqual(err.code, 'ENOENT'); assert.strictEqual(err.syscall, 'realpath'); return true; @@ -159,7 +169,7 @@ function re(literals, ...values) { assert.strictEqual( err.message, `ENOENT: no such file or directory, readlink '${nonexistentFile}'`); - assert.strictEqual(err.errno, uv.UV_ENOENT); + assert.strictEqual(err.errno, UV_ENOENT); assert.strictEqual(err.code, 'ENOENT'); assert.strictEqual(err.syscall, 'readlink'); return true; @@ -184,7 +194,7 @@ function re(literals, ...values) { re`'${nonexistentFile}' -> ` + '\'.*foo\''); assert.ok(regexp.test(err.message), `Expect ${err.message} to match ${regexp}`); - assert.strictEqual(err.errno, uv.UV_ENOENT); + assert.strictEqual(err.errno, UV_ENOENT); assert.strictEqual(err.code, 'ENOENT'); assert.strictEqual(err.syscall, 'link'); return true; @@ -207,7 +217,7 @@ function re(literals, ...values) { err.message, `EEXIST: file already exists, link '${existingFile}' -> ` + `'${existingFile2}'`); - assert.strictEqual(err.errno, uv.UV_EEXIST); + assert.strictEqual(err.errno, UV_EEXIST); assert.strictEqual(err.code, 'EEXIST'); assert.strictEqual(err.syscall, 'link'); return true; @@ -230,7 +240,7 @@ function re(literals, ...values) { err.message, `EEXIST: file already exists, symlink '${existingFile}' -> ` + `'${existingFile2}'`); - assert.strictEqual(err.errno, uv.UV_EEXIST); + assert.strictEqual(err.errno, UV_EEXIST); assert.strictEqual(err.code, 'EEXIST'); assert.strictEqual(err.syscall, 'symlink'); return true; @@ -251,7 +261,7 @@ function re(literals, ...values) { assert.strictEqual( err.message, `ENOENT: no such file or directory, unlink '${nonexistentFile}'`); - assert.strictEqual(err.errno, uv.UV_ENOENT); + assert.strictEqual(err.errno, UV_ENOENT); assert.strictEqual(err.code, 'ENOENT'); assert.strictEqual(err.syscall, 'unlink'); return true; @@ -276,7 +286,7 @@ function re(literals, ...values) { re`'${nonexistentFile}' -> ` + '\'.*foo\''); assert.ok(regexp.test(err.message), `Expect ${err.message} to match ${regexp}`); - assert.strictEqual(err.errno, uv.UV_ENOENT); + assert.strictEqual(err.errno, UV_ENOENT); assert.strictEqual(err.code, 'ENOENT'); assert.strictEqual(err.syscall, 'rename'); return true; @@ -302,7 +312,7 @@ function re(literals, ...values) { err.message, `ENOTEMPTY: directory not empty, rename '${existingDir}' -> ` + `'${existingDir2}'`); - assert.strictEqual(err.errno, uv.UV_ENOTEMPTY); + assert.strictEqual(err.errno, UV_ENOTEMPTY); } else if (err.code === 'EXDEV') { // not on the same mounted filesystem assert.strictEqual( err.message, @@ -313,13 +323,13 @@ function re(literals, ...values) { err.message, `EEXIST: file already exists, rename '${existingDir}' -> ` + `'${existingDir2}'`); - assert.strictEqual(err.errno, uv.UV_EEXIST); + assert.strictEqual(err.errno, UV_EEXIST); } else { // windows assert.strictEqual( err.message, `EPERM: operation not permitted, rename '${existingDir}' -> ` + `'${existingDir2}'`); - assert.strictEqual(err.errno, uv.UV_EPERM); + assert.strictEqual(err.errno, UV_EPERM); assert.strictEqual(err.code, 'EPERM'); } return true; @@ -340,7 +350,7 @@ function re(literals, ...values) { assert.strictEqual( err.message, `ENOENT: no such file or directory, rmdir '${nonexistentFile}'`); - assert.strictEqual(err.errno, uv.UV_ENOENT); + assert.strictEqual(err.errno, UV_ENOENT); assert.strictEqual(err.code, 'ENOENT'); assert.strictEqual(err.syscall, 'rmdir'); return true; @@ -363,12 +373,12 @@ function re(literals, ...values) { assert.strictEqual( err.message, `ENOTDIR: not a directory, rmdir '${existingFile}'`); - assert.strictEqual(err.errno, uv.UV_ENOTDIR); + assert.strictEqual(err.errno, UV_ENOTDIR); } else { // windows assert.strictEqual( err.message, `ENOENT: no such file or directory, rmdir '${existingFile}'`); - assert.strictEqual(err.errno, uv.UV_ENOENT); + assert.strictEqual(err.errno, UV_ENOENT); assert.strictEqual(err.code, 'ENOENT'); } return true; @@ -389,7 +399,7 @@ function re(literals, ...values) { assert.strictEqual( err.message, `EEXIST: file already exists, mkdir '${existingFile}'`); - assert.strictEqual(err.errno, uv.UV_EEXIST); + assert.strictEqual(err.errno, UV_EEXIST); assert.strictEqual(err.code, 'EEXIST'); assert.strictEqual(err.syscall, 'mkdir'); return true; @@ -410,7 +420,7 @@ function re(literals, ...values) { assert.strictEqual( err.message, `ENOENT: no such file or directory, chmod '${nonexistentFile}'`); - assert.strictEqual(err.errno, uv.UV_ENOENT); + assert.strictEqual(err.errno, UV_ENOENT); assert.strictEqual(err.code, 'ENOENT'); assert.strictEqual(err.syscall, 'chmod'); return true; @@ -431,7 +441,7 @@ function re(literals, ...values) { assert.strictEqual( err.message, `ENOENT: no such file or directory, open '${nonexistentFile}'`); - assert.strictEqual(err.errno, uv.UV_ENOENT); + assert.strictEqual(err.errno, UV_ENOENT); assert.strictEqual(err.code, 'ENOENT'); assert.strictEqual(err.syscall, 'open'); return true; @@ -450,7 +460,7 @@ function re(literals, ...values) { { const validateError = (err) => { assert.strictEqual(err.message, 'EBADF: bad file descriptor, close'); - assert.strictEqual(err.errno, uv.UV_EBADF); + assert.strictEqual(err.errno, UV_EBADF); assert.strictEqual(err.code, 'EBADF'); assert.strictEqual(err.syscall, 'close'); return true; @@ -473,7 +483,7 @@ function re(literals, ...values) { assert.strictEqual( err.message, `ENOENT: no such file or directory, open '${nonexistentFile}'`); - assert.strictEqual(err.errno, uv.UV_ENOENT); + assert.strictEqual(err.errno, UV_ENOENT); assert.strictEqual(err.code, 'ENOENT'); assert.strictEqual(err.syscall, 'open'); return true; @@ -494,7 +504,7 @@ function re(literals, ...values) { assert.strictEqual( err.message, `ENOENT: no such file or directory, scandir '${nonexistentFile}'`); - assert.strictEqual(err.errno, uv.UV_ENOENT); + assert.strictEqual(err.errno, UV_ENOENT); assert.strictEqual(err.code, 'ENOENT'); assert.strictEqual(err.syscall, 'scandir'); return true; @@ -515,10 +525,10 @@ function re(literals, ...values) { // Could be EBADF or EINVAL, depending on the platform if (err.code === 'EBADF') { assert.strictEqual(err.message, 'EBADF: bad file descriptor, ftruncate'); - assert.strictEqual(err.errno, uv.UV_EBADF); + assert.strictEqual(err.errno, UV_EBADF); } else { assert.strictEqual(err.message, 'EINVAL: invalid argument, ftruncate'); - assert.strictEqual(err.errno, uv.UV_EINVAL); + assert.strictEqual(err.errno, UV_EINVAL); assert.strictEqual(err.code, 'EINVAL'); } return true; @@ -538,7 +548,7 @@ function re(literals, ...values) { { const validateError = (err) => { assert.strictEqual(err.message, 'EBADF: bad file descriptor, fdatasync'); - assert.strictEqual(err.errno, uv.UV_EBADF); + assert.strictEqual(err.errno, UV_EBADF); assert.strictEqual(err.code, 'EBADF'); assert.strictEqual(err.syscall, 'fdatasync'); return true; @@ -558,7 +568,7 @@ function re(literals, ...values) { { const validateError = (err) => { assert.strictEqual(err.message, 'EBADF: bad file descriptor, fsync'); - assert.strictEqual(err.errno, uv.UV_EBADF); + assert.strictEqual(err.errno, UV_EBADF); assert.strictEqual(err.code, 'EBADF'); assert.strictEqual(err.syscall, 'fsync'); return true; @@ -581,7 +591,7 @@ if (!common.isWindows) { assert.strictEqual( err.message, `ENOENT: no such file or directory, chown '${nonexistentFile}'`); - assert.strictEqual(err.errno, uv.UV_ENOENT); + assert.strictEqual(err.errno, UV_ENOENT); assert.strictEqual(err.code, 'ENOENT'); assert.strictEqual(err.syscall, 'chown'); return true; @@ -604,7 +614,7 @@ if (!common.isAIX) { assert.strictEqual( err.message, `ENOENT: no such file or directory, utime '${nonexistentFile}'`); - assert.strictEqual(err.errno, uv.UV_ENOENT); + assert.strictEqual(err.errno, UV_ENOENT); assert.strictEqual(err.code, 'ENOENT'); assert.strictEqual(err.syscall, 'utime'); return true; @@ -631,7 +641,7 @@ if (!common.isAIX) { assert(prefix.test(err.message), `Expect ${err.message} to match ${prefix}`); - assert.strictEqual(err.errno, uv.UV_ENOENT); + assert.strictEqual(err.errno, UV_ENOENT); assert.strictEqual(err.code, 'ENOENT'); assert.strictEqual(err.syscall, 'mkdtemp'); return true; @@ -650,7 +660,7 @@ if (!common.isAIX) { const validateError = { // TODO: Make sure the error message always also contains the src. message: `EINVAL: invalid argument, copyfile -> '${nonexistentFile}'`, - errno: uv.UV_EINVAL, + errno: UV_EINVAL, code: 'EINVAL', syscall: 'copyfile' }; @@ -673,14 +683,14 @@ if (!common.isAIX) { assert.strictEqual(err.message, 'ENOENT: no such file or directory, copyfile ' + `'${existingFile}' -> '${existingFile2}'`); - 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 ' + `'${existingFile}' -> '${existingFile2}'`); - assert.strictEqual(err.errno, uv.UV_EEXIST); + assert.strictEqual(err.errno, UV_EEXIST); assert.strictEqual(err.code, 'EEXIST'); assert.strictEqual(err.syscall, 'copyfile'); } @@ -702,7 +712,7 @@ if (!common.isAIX) { assert.strictEqual(err.message, 'ENOENT: no such file or directory, copyfile ' + `'${nonexistentFile}' -> '${existingFile2}'`); - assert.strictEqual(err.errno, uv.UV_ENOENT); + assert.strictEqual(err.errno, UV_ENOENT); assert.strictEqual(err.code, 'ENOENT'); assert.strictEqual(err.syscall, 'copyfile'); return true; @@ -721,7 +731,7 @@ if (!common.isAIX) { { const validateError = (err) => { assert.strictEqual(err.message, 'EBADF: bad file descriptor, read'); - assert.strictEqual(err.errno, uv.UV_EBADF); + assert.strictEqual(err.errno, UV_EBADF); assert.strictEqual(err.code, 'EBADF'); assert.strictEqual(err.syscall, 'read'); return true; @@ -742,7 +752,7 @@ if (!common.isAIX) { { const validateError = (err) => { assert.strictEqual(err.message, 'EBADF: bad file descriptor, fchmod'); - assert.strictEqual(err.errno, uv.UV_EBADF); + assert.strictEqual(err.errno, UV_EBADF); assert.strictEqual(err.code, 'EBADF'); assert.strictEqual(err.syscall, 'fchmod'); return true; @@ -762,7 +772,7 @@ if (!common.isAIX) { if (!common.isWindows) { const validateError = (err) => { assert.strictEqual(err.message, 'EBADF: bad file descriptor, fchown'); - assert.strictEqual(err.errno, uv.UV_EBADF); + assert.strictEqual(err.errno, UV_EBADF); assert.strictEqual(err.code, 'EBADF'); assert.strictEqual(err.syscall, 'fchown'); return true; @@ -783,7 +793,7 @@ if (!common.isWindows) { { const validateError = (err) => { assert.strictEqual(err.message, 'EBADF: bad file descriptor, write'); - assert.strictEqual(err.errno, uv.UV_EBADF); + assert.strictEqual(err.errno, UV_EBADF); assert.strictEqual(err.code, 'EBADF'); assert.strictEqual(err.syscall, 'write'); return true; @@ -804,7 +814,7 @@ if (!common.isWindows) { { const validateError = (err) => { assert.strictEqual(err.message, 'EBADF: bad file descriptor, write'); - assert.strictEqual(err.errno, uv.UV_EBADF); + assert.strictEqual(err.errno, UV_EBADF); assert.strictEqual(err.code, 'EBADF'); assert.strictEqual(err.syscall, 'write'); return true; @@ -825,7 +835,7 @@ if (!common.isWindows) { if (!common.isAIX) { const validateError = (err) => { assert.strictEqual(err.message, 'EBADF: bad file descriptor, futime'); - assert.strictEqual(err.errno, uv.UV_EBADF); + assert.strictEqual(err.errno, UV_EBADF); assert.strictEqual(err.code, 'EBADF'); assert.strictEqual(err.syscall, 'futime'); return true; diff --git a/test/parallel/test-fs-sync-fd-leak.js b/test/parallel/test-fs-sync-fd-leak.js index 52e40eb3901f4c..ee2e0355ec7aab 100644 --- a/test/parallel/test-fs-sync-fd-leak.js +++ b/test/parallel/test-fs-sync-fd-leak.js @@ -1,3 +1,4 @@ +// Flags: --expose-internals // Copyright Joyent, Inc. and other Node contributors. // // Permission is hereby granted, free of charge, to any person obtaining a @@ -23,7 +24,8 @@ require('../common'); const assert = require('assert'); const fs = require('fs'); -const uv = process.binding('uv'); +const { internalBinding } = require('internal/test/binding'); +const { UV_EBADF } = internalBinding('uv'); // ensure that (read|write|append)FileSync() closes the file descriptor fs.openSync = function() { @@ -41,7 +43,7 @@ fs.writeSync = function() { }; process.binding('fs').fstat = function(fd, bigint, _, ctx) { - ctx.errno = uv.UV_EBADF; + ctx.errno = UV_EBADF; ctx.syscall = 'fstat'; }; diff --git a/test/parallel/test-fs-watch-enoent.js b/test/parallel/test-fs-watch-enoent.js index e6db65993d666e..1ed9f2ed641f19 100644 --- a/test/parallel/test-fs-watch-enoent.js +++ b/test/parallel/test-fs-watch-enoent.js @@ -1,3 +1,4 @@ +// Flags: --expose-internals 'use strict'; // This verifies the error thrown by fs.watch. @@ -8,7 +9,11 @@ const fs = require('fs'); const tmpdir = require('../common/tmpdir'); const path = require('path'); const nonexistentFile = path.join(tmpdir.path, 'non-existent'); -const uv = process.binding('uv'); +const { internalBinding } = require('internal/test/binding'); +const { + UV_ENODEV, + UV_ENOENT +} = internalBinding('uv'); tmpdir.refresh(); @@ -21,13 +26,13 @@ tmpdir.refresh(); assert.strictEqual( err.message, `ENOENT: no such file or directory, watch '${nonexistentFile}'`); - assert.strictEqual(err.errno, uv.UV_ENOENT); + assert.strictEqual(err.errno, UV_ENOENT); assert.strictEqual(err.code, 'ENOENT'); } else { // AIX assert.strictEqual( err.message, `ENODEV: no such device, watch '${nonexistentFile}'`); - assert.strictEqual(err.errno, uv.UV_ENODEV); + assert.strictEqual(err.errno, UV_ENODEV); assert.strictEqual(err.code, 'ENODEV'); } return true; @@ -50,7 +55,7 @@ tmpdir.refresh(); assert.strictEqual( err.message, `ENOENT: no such file or directory, watch '${nonexistentFile}'`); - assert.strictEqual(err.errno, uv.UV_ENOENT); + assert.strictEqual(err.errno, UV_ENOENT); assert.strictEqual(err.code, 'ENOENT'); assert.strictEqual(err.syscall, 'watch'); fs.unlinkSync(file); @@ -60,5 +65,5 @@ tmpdir.refresh(); watcher.on('error', common.mustCall(validateError)); // Simulate the invocation from the binding - watcher._handle.onchange(uv.UV_ENOENT, 'ENOENT', nonexistentFile); + watcher._handle.onchange(UV_ENOENT, 'ENOENT', nonexistentFile); } diff --git a/test/parallel/test-http-client-immediate-error.js b/test/parallel/test-http-client-immediate-error.js index 1c65d07ca50bfe..ff29ad72bd8585 100644 --- a/test/parallel/test-http-client-immediate-error.js +++ b/test/parallel/test-http-client-immediate-error.js @@ -8,7 +8,8 @@ const common = require('../common'); const assert = require('assert'); const net = require('net'); const http = require('http'); -const uv = process.binding('uv'); +const { internalBinding } = require('internal/test/binding'); +const { UV_ENETUNREACH } = internalBinding('uv'); const { newAsyncId, symbols: { async_id_symbol } @@ -21,7 +22,7 @@ agent.createConnection = common.mustCall((cfg) => { // Fake the handle so we can enforce returning an immediate error sock._handle = { connect: common.mustCall((req, addr, port) => { - return uv.UV_ENETUNREACH; + return UV_ENETUNREACH; }), readStart() {}, close() {} diff --git a/test/parallel/test-net-end-close.js b/test/parallel/test-net-end-close.js index 31c150e09c09af..c0705da9d089e4 100644 --- a/test/parallel/test-net-end-close.js +++ b/test/parallel/test-net-end-close.js @@ -1,14 +1,16 @@ +// Flags: --expose-internals 'use strict'; require('../common'); const assert = require('assert'); const net = require('net'); -const uv = process.binding('uv'); +const { internalBinding } = require('internal/test/binding'); +const { UV_EOF } = internalBinding('uv'); const s = new net.Socket({ handle: { readStart: function() { - setImmediate(() => this.onread(uv.UV_EOF, null)); + setImmediate(() => this.onread(UV_EOF, null)); }, close: (cb) => setImmediate(cb) }, diff --git a/test/parallel/test-tcp-wrap.js b/test/parallel/test-tcp-wrap.js index 36a45d7606b125..f6a54a012b80cc 100644 --- a/test/parallel/test-tcp-wrap.js +++ b/test/parallel/test-tcp-wrap.js @@ -1,3 +1,4 @@ +// Flags: --expose-internals // Copyright Joyent, Inc. and other Node contributors. // // Permission is hereby granted, free of charge, to any person obtaining a @@ -24,7 +25,8 @@ require('../common'); const assert = require('assert'); const { TCP, constants: TCPConstants } = process.binding('tcp_wrap'); -const uv = process.binding('uv'); +const { internalBinding } = require('internal/test/binding'); +const { UV_EINVAL } = internalBinding('uv'); const handle = new TCP(TCPConstants.SOCKET); @@ -36,6 +38,6 @@ assert.strictEqual(err, 0); const out = {}; handle.getsockname(out); err = handle.bind('0.0.0.0', out.port); -assert.strictEqual(err, uv.UV_EINVAL); +assert.strictEqual(err, UV_EINVAL); handle.close(); diff --git a/test/parallel/test-ttywrap-invalid-fd.js b/test/parallel/test-ttywrap-invalid-fd.js index 0a0f8c5c4e1a3a..30c3cd2bc48a4a 100644 --- a/test/parallel/test-ttywrap-invalid-fd.js +++ b/test/parallel/test-ttywrap-invalid-fd.js @@ -1,8 +1,13 @@ +// Flags: --expose-internals 'use strict'; const common = require('../common'); const tty = require('tty'); -const uv = process.binding('uv'); +const { internalBinding } = require('internal/test/binding'); +const { + UV_EBADF, + UV_EINVAL +} = internalBinding('uv'); const assert = require('assert'); assert.throws( @@ -18,7 +23,7 @@ assert.throws( const info = { code: common.isWindows ? 'EBADF' : 'EINVAL', message: common.isWindows ? 'bad file descriptor' : 'invalid argument', - errno: common.isWindows ? uv.UV_EBADF : uv.UV_EINVAL, + errno: common.isWindows ? UV_EBADF : UV_EINVAL, syscall: 'uv_tty_init' }; diff --git a/test/parallel/test-uv-binding-constant.js b/test/parallel/test-uv-binding-constant.js index beae7672db12f5..11d9f6aa09cfd1 100644 --- a/test/parallel/test-uv-binding-constant.js +++ b/test/parallel/test-uv-binding-constant.js @@ -1,10 +1,12 @@ +// Flags: --expose-internals 'use strict'; require('../common'); const assert = require('assert'); -const uv = process.binding('uv'); +const { internalBinding } = require('internal/test/binding'); +const uv = internalBinding('uv'); -// Ensures that the `UV_...` values in process.binding('uv') +// Ensures that the `UV_...` values in internalBinding('uv') // are constants. const keys = Object.keys(uv); diff --git a/test/parallel/test-uv-errno.js b/test/parallel/test-uv-errno.js index d3b4f79db3eca0..078db29adce923 100644 --- a/test/parallel/test-uv-errno.js +++ b/test/parallel/test-uv-errno.js @@ -1,3 +1,4 @@ +// Flags: --expose-internals 'use strict'; const common = require('../common'); @@ -7,7 +8,8 @@ const { _errnoException } = require('util'); -const uv = process.binding('uv'); +const { internalBinding } = require('internal/test/binding'); +const uv = internalBinding('uv'); const keys = Object.keys(uv); keys.forEach((key) => {