lib: migrate process.binding to internalBinding
Migrate various modules from using process.binding to internalBinding. PR-URL: https://github.com/nodejs/node/pull/24952 Refs: https://github.com/nodejs/node/issues/22160 Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com> Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de> Reviewed-By: Anna Henningsen <anna@addaleax.net>
This commit is contained in:
parent
80209cc4c9
commit
53d4e04be5
@ -11,7 +11,7 @@ const hooks = initHooks();
|
||||
hooks.enable();
|
||||
const { internalBinding } = require('internal/test/binding');
|
||||
const { Zlib } = internalBinding('zlib');
|
||||
const constants = process.binding('constants').zlib;
|
||||
const constants = internalBinding('constants').zlib;
|
||||
|
||||
const handle = new Zlib(constants.DEFLATE);
|
||||
|
||||
|
@ -57,7 +57,7 @@ const UDP = internalBinding('udp_wrap').UDP;
|
||||
|
||||
if (common.hasCrypto) { // eslint-disable-line node-core/crypto-check
|
||||
// There are accessor properties in crypto too
|
||||
const crypto = process.binding('crypto');
|
||||
const crypto = internalBinding('crypto');
|
||||
|
||||
assert.throws(() => {
|
||||
crypto.SecureContext.prototype._external;
|
||||
|
@ -1,7 +1,9 @@
|
||||
// Flags: --expose-internals
|
||||
'use strict';
|
||||
|
||||
require('../common');
|
||||
const constants = process.binding('constants');
|
||||
const { internalBinding } = require('internal/test/binding');
|
||||
const constants = internalBinding('constants');
|
||||
const assert = require('assert');
|
||||
|
||||
assert.deepStrictEqual(
|
||||
|
@ -9,7 +9,7 @@ if (process.argv[2] === 'child') {
|
||||
} else {
|
||||
const internalCp = require('internal/child_process');
|
||||
const oldSpawnSync = internalCp.spawnSync;
|
||||
const { SIGKILL } = process.binding('constants').os.signals;
|
||||
const { SIGKILL } = require('os').constants.signals;
|
||||
|
||||
function spawn(killSignal, beforeSpawn) {
|
||||
if (beforeSpawn) {
|
||||
|
@ -2,7 +2,7 @@
|
||||
const common = require('../common');
|
||||
const assert = require('assert');
|
||||
const spawnSync = require('child_process').spawnSync;
|
||||
const signals = process.binding('constants').os.signals;
|
||||
const signals = require('os').constants.signals;
|
||||
const rootUser = common.isWindows ? false : process.getuid() === 0;
|
||||
|
||||
const invalidArgTypeError = common.expectsError(
|
||||
|
@ -1,7 +1,9 @@
|
||||
// Flags: --expose_internals
|
||||
'use strict';
|
||||
|
||||
require('../common');
|
||||
const binding = process.binding('constants');
|
||||
const { internalBinding } = require('internal/test/binding');
|
||||
const binding = internalBinding('constants');
|
||||
const constants = require('constants');
|
||||
const assert = require('assert');
|
||||
|
||||
|
@ -8,7 +8,7 @@ const assert = require('assert');
|
||||
const dgram = require('dgram');
|
||||
const { internalBinding } = require('internal/test/binding');
|
||||
const { UDP } = internalBinding('udp_wrap');
|
||||
const { UV_UDP_REUSEADDR } = process.binding('constants').os;
|
||||
const { UV_UDP_REUSEADDR } = require('os').constants;
|
||||
|
||||
const BUFFER_SIZE = 4096;
|
||||
|
||||
|
@ -1,3 +1,4 @@
|
||||
// Flags: --expose-internals
|
||||
'use strict';
|
||||
|
||||
const common = require('../common');
|
||||
@ -6,11 +7,12 @@ const fs = require('fs');
|
||||
|
||||
const tmpdir = require('../common/tmpdir');
|
||||
|
||||
const binding = process.binding('fs');
|
||||
const { internalBinding } = require('internal/test/binding');
|
||||
const binding = internalBinding('fs');
|
||||
|
||||
const readdirDir = tmpdir.path;
|
||||
const files = ['empty', 'files', 'for', 'just', 'testing'];
|
||||
const constants = process.binding('constants').fs;
|
||||
const constants = require('fs').constants;
|
||||
const types = {
|
||||
isDirectory: constants.UV_DIRENT_DIR,
|
||||
isFile: constants.UV_DIRENT_FILE,
|
||||
|
@ -16,7 +16,8 @@ common.expectsError(
|
||||
common.expectsError(
|
||||
() => {
|
||||
const source = 'module.exports = require("internal/bootstrap/loaders")';
|
||||
process.binding('natives').owo = source;
|
||||
const { internalBinding } = require('internal/test/binding');
|
||||
internalBinding('natives').owo = source;
|
||||
require('owo');
|
||||
}, {
|
||||
code: 'MODULE_NOT_FOUND',
|
||||
|
@ -1,21 +1,41 @@
|
||||
// Flags: --no-warnings
|
||||
'use strict';
|
||||
|
||||
require('../common');
|
||||
const common = require('../common');
|
||||
const assert = require('assert');
|
||||
|
||||
// Assert that whitelisted internalBinding modules are accessible via
|
||||
// process.binding().
|
||||
assert(process.binding('uv'));
|
||||
assert(process.binding('http_parser'));
|
||||
assert(process.binding('v8'));
|
||||
assert(process.binding('stream_wrap'));
|
||||
assert(process.binding('signal_wrap'));
|
||||
assert(process.binding('contextify'));
|
||||
assert(process.binding('url'));
|
||||
assert(process.binding('spawn_sync'));
|
||||
assert(process.binding('js_stream'));
|
||||
assert(process.binding('async_wrap'));
|
||||
assert(process.binding('buffer'));
|
||||
assert(process.binding('cares_wrap'));
|
||||
assert(process.binding('constants'));
|
||||
assert(process.binding('contextify'));
|
||||
if (common.hasCrypto) { // eslint-disable-line node-core/crypto-check
|
||||
assert(process.binding('crypto'));
|
||||
}
|
||||
assert(process.binding('fs'));
|
||||
assert(process.binding('fs_event_wrap'));
|
||||
assert(process.binding('http_parser'));
|
||||
if (common.hasIntl) {
|
||||
assert(process.binding('icu'));
|
||||
}
|
||||
assert(process.binding('inspector'));
|
||||
assert(process.binding('js_stream'));
|
||||
assert(process.binding('natives'));
|
||||
assert(process.binding('os'));
|
||||
assert(process.binding('pipe_wrap'));
|
||||
assert(process.binding('signal_wrap'));
|
||||
assert(process.binding('spawn_sync'));
|
||||
assert(process.binding('stream_wrap'));
|
||||
assert(process.binding('tcp_wrap'));
|
||||
if (common.hasCrypto) { // eslint-disable-line node-core/crypto-check
|
||||
assert(process.binding('tls_wrap'));
|
||||
}
|
||||
assert(process.binding('tty_wrap'));
|
||||
assert(process.binding('udp_wrap'));
|
||||
assert(process.binding('url'));
|
||||
assert(process.binding('util'));
|
||||
assert(process.binding('uv'));
|
||||
assert(process.binding('v8'));
|
||||
assert(process.binding('zlib'));
|
||||
|
@ -2,11 +2,11 @@
|
||||
|
||||
const common = require('../common');
|
||||
const assert = require('assert');
|
||||
const constants = process.binding('constants');
|
||||
const constants = require('fs').constants;
|
||||
|
||||
if (common.isLinux) {
|
||||
assert('O_NOATIME' in constants.fs);
|
||||
assert.strictEqual(constants.fs.O_NOATIME, 0x40000);
|
||||
assert('O_NOATIME' in constants);
|
||||
assert.strictEqual(constants.O_NOATIME, 0x40000);
|
||||
} else {
|
||||
assert(!('O_NOATIME' in constants.fs));
|
||||
assert(!('O_NOATIME' in constants));
|
||||
}
|
||||
|
@ -23,7 +23,7 @@
|
||||
const common = require('../common');
|
||||
const assert = require('assert');
|
||||
const { internalBinding } = require('internal/test/binding');
|
||||
const JSStream = process.binding('js_stream').JSStream;
|
||||
const JSStream = internalBinding('js_stream').JSStream;
|
||||
const util = require('util');
|
||||
const vm = require('vm');
|
||||
const { previewEntries } = internalBinding('util');
|
||||
|
Loading…
x
Reference in New Issue
Block a user