Skip to content

Commit

Permalink
lib: migrate process.binding to internalBinding
Browse files Browse the repository at this point in the history
Migrate various modules from using process.binding to internalBinding.

PR-URL: #24952
Refs: #22160
Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com>
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
  • Loading branch information
BeniCheni authored and BridgeAR committed Mar 14, 2019
1 parent a67fea5 commit fe6c419
Show file tree
Hide file tree
Showing 12 changed files with 52 additions and 25 deletions.
2 changes: 1 addition & 1 deletion test/async-hooks/test-zlib.zlib-binding.deflate.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
2 changes: 1 addition & 1 deletion test/parallel/test-accessor-properties.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
4 changes: 3 additions & 1 deletion test/parallel/test-binding-constants.js
Original file line number Diff line number Diff line change
@@ -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(
Expand Down
2 changes: 1 addition & 1 deletion test/parallel/test-child-process-spawnsync-kill-signal.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
4 changes: 3 additions & 1 deletion test/parallel/test-constants.js
Original file line number Diff line number Diff line change
@@ -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');

Expand Down
2 changes: 1 addition & 1 deletion test/parallel/test-dgram-bind-fd.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
6 changes: 4 additions & 2 deletions test/parallel/test-fs-readdir-types.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// Flags: --expose-internals
'use strict';

const common = require('../common');
Expand All @@ -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,
Expand Down
3 changes: 2 additions & 1 deletion test/parallel/test-loaders-hidden-from-users.js
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
40 changes: 30 additions & 10 deletions test/parallel/test-process-binding-internalbinding-whitelist.js
Original file line number Diff line number Diff line change
@@ -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'));
8 changes: 4 additions & 4 deletions test/parallel/test-process-constants-noatime.js
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}
2 changes: 1 addition & 1 deletion test/parallel/test-util-inspect.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down

0 comments on commit fe6c419

Please sign in to comment.