Skip to content

Commit 87b808f

Browse files
committedOct 21, 2018
src,lib: move natives and constants to internalBinding()
Refs: #22160 PR-URL: #23663 Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com> Reviewed-By: Weijia Wang <starkwang@126.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Sakthipriyan Vairamani <thechargingvolcano@gmail.com> Reviewed-By: Denys Otrishko <shishugi@gmail.com> Reviewed-By: Refael Ackermann <refack@gmail.com>
1 parent 20282b1 commit 87b808f

21 files changed

+32
-30
lines changed
 

‎lib/_tls_common.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ const {
2929
ERR_INVALID_ARG_TYPE
3030
} = require('internal/errors').codes;
3131

32-
const { SSL_OP_CIPHER_SERVER_PREFERENCE } = process.binding('constants').crypto;
32+
const { SSL_OP_CIPHER_SERVER_PREFERENCE } = internalBinding('constants').crypto;
3333

3434
// Lazily loaded from internal/crypto/util.
3535
let toBuf = null;

‎lib/constants.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
// towards using the specific constants exposed by the individual modules on
2626
// which they are most relevant.
2727
// Deprecation Code: DEP0008
28-
const constants = process.binding('constants');
28+
const constants = internalBinding('constants');
2929
Object.assign(exports,
3030
constants.os.dlopen,
3131
constants.os.errno,

‎lib/crypto.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ const {
3434
ERR_CRYPTO_FIPS_FORCED,
3535
ERR_CRYPTO_FIPS_UNAVAILABLE
3636
} = require('internal/errors').codes;
37-
const constants = process.binding('constants').crypto;
37+
const constants = internalBinding('constants').crypto;
3838
const { getOptions } = internalBinding('options');
3939
const pendingDeprecation = getOptions('--pending-deprecation');
4040
const {

‎lib/dgram.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ const {
5252
defaultTriggerAsyncIdScope,
5353
symbols: { async_id_symbol, owner_symbol }
5454
} = require('internal/async_hooks');
55-
const { UV_UDP_REUSEADDR } = process.binding('constants').os;
55+
const { UV_UDP_REUSEADDR } = internalBinding('constants').os;
5656

5757
const { UDP, SendWrap } = internalBinding('udp_wrap');
5858

‎lib/fs.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424

2525
'use strict';
2626

27-
const { fs: constants } = process.binding('constants');
27+
const { fs: constants } = internalBinding('constants');
2828
const {
2929
S_IFIFO,
3030
S_IFLNK,

‎lib/internal/bootstrap/loaders.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@
123123
this.script = null; // The ContextifyScript of the module
124124
}
125125

126-
NativeModule._source = getBinding('natives');
126+
NativeModule._source = getInternalBinding('natives');
127127
NativeModule._cache = {};
128128

129129
const config = getBinding('config');
@@ -256,12 +256,12 @@
256256
// 1. `internalBinding('code_cache_hash')` must be in sync with
257257
// `internalBinding('code_cache')` (same C++ file)
258258
// 2. `internalBinding('natives_hash')` must be in sync with
259-
// `process.binding('natives')` (same C++ file)
259+
// `internalBinding('natives')` (same C++ file)
260260
// 3. If `internalBinding('natives_hash')` is in sync with
261261
// `internalBinding('natives_hash')`, then the (unwrapped)
262262
// code used to generate `internalBinding('code_cache')`
263263
// should be in sync with the (unwrapped) code in
264-
// `process.binding('natives')`
264+
// `internalBinding('natives')`
265265
// There will be, however, false positives if the wrapper used
266266
// to generate the cache is different from the one used at run time,
267267
// and the length of the wrapper somehow stays the same.

‎lib/internal/bootstrap/node.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -414,7 +414,9 @@
414414
'spawn_sync',
415415
'js_stream',
416416
'zlib',
417-
'buffer']);
417+
'buffer',
418+
'natives',
419+
'constants']);
418420
process.binding = function binding(name) {
419421
return internalBindingWhitelist.has(name) ?
420422
internalBinding(name) :

‎lib/internal/crypto/cipher.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
const {
44
RSA_PKCS1_OAEP_PADDING,
55
RSA_PKCS1_PADDING
6-
} = process.binding('constants').crypto;
6+
} = internalBinding('constants').crypto;
77

88
const {
99
ERR_CRYPTO_INVALID_STATE,

‎lib/internal/crypto/diffiehellman.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ const {
2424
POINT_CONVERSION_COMPRESSED,
2525
POINT_CONVERSION_HYBRID,
2626
POINT_CONVERSION_UNCOMPRESSED
27-
} = process.binding('constants').crypto;
27+
} = internalBinding('constants').crypto;
2828

2929
const DH_GENERATOR = 2;
3030

‎lib/internal/crypto/sig.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ const { Sign: _Sign, Verify: _Verify } = internalBinding('crypto');
99
const {
1010
RSA_PSS_SALTLEN_AUTO,
1111
RSA_PKCS1_PADDING
12-
} = process.binding('constants').crypto;
12+
} = internalBinding('constants').crypto;
1313
const {
1414
getDefaultEncoding,
1515
kHandle,

‎lib/internal/crypto/util.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ const {
1010

1111
const {
1212
ENGINE_METHOD_ALL
13-
} = process.binding('constants').crypto;
13+
} = internalBinding('constants').crypto;
1414

1515
const {
1616
ERR_CRYPTO_ENGINE_UNKNOWN,

‎lib/internal/fs/promises.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ const {
66
O_WRONLY,
77
S_IFMT,
88
S_IFREG
9-
} = process.binding('constants').fs;
9+
} = internalBinding('constants').fs;
1010
const binding = process.binding('fs');
1111
const { Buffer, kMaxLength } = require('buffer');
1212
const {

‎lib/internal/fs/utils.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ const {
4343
UV_DIRENT_SOCKET,
4444
UV_DIRENT_CHAR,
4545
UV_DIRENT_BLOCK
46-
} = process.binding('constants').fs;
46+
} = internalBinding('constants').fs;
4747

4848
const isWindows = process.platform === 'win32';
4949

‎lib/internal/process/main_thread_only.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ function setupPosixMethods(_initgroups, _setegid, _seteuid,
118118

119119
// Worker threads don't receive signals.
120120
function setupSignalHandlers(internalBinding) {
121-
const constants = process.binding('constants').os.signals;
121+
const constants = internalBinding('constants').os.signals;
122122
const signalWraps = Object.create(null);
123123
let Signal;
124124

‎lib/internal/process/per_thread.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ const {
1717
}
1818
} = require('internal/errors');
1919
const util = require('util');
20-
const constants = process.binding('constants').os.signals;
20+
const constants = internalBinding('constants').os.signals;
2121
const { deprecate } = require('internal/util');
2222

2323
function setupAssert() {

‎lib/internal/util.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ const {
55
ERR_NO_CRYPTO,
66
ERR_UNKNOWN_SIGNAL
77
} = require('internal/errors').codes;
8-
const { signals } = process.binding('constants').os;
8+
const { signals } = internalBinding('constants').os;
99
const {
1010
getHiddenValue,
1111
setHiddenValue,

‎lib/internal/v8_prof_processor.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ const scriptFiles = [
1919
var script = '';
2020

2121
scriptFiles.forEach(function(s) {
22-
script += process.binding('natives')[s] + '\n';
22+
script += internalBinding('natives')[s] + '\n';
2323
});
2424

2525
const tickArguments = [];

‎lib/os.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
'use strict';
2323

2424
const { pushValToArrayMax, safeGetenv } = internalBinding('util');
25-
const constants = process.binding('constants').os;
25+
const constants = internalBinding('constants').os;
2626
const { deprecate } = require('internal/util');
2727
const isWindows = process.platform === 'win32';
2828

‎lib/tls.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ exports.CLIENT_RENEG_LIMIT = 3;
4646
exports.CLIENT_RENEG_WINDOW = 600;
4747

4848
exports.DEFAULT_CIPHERS =
49-
process.binding('constants').crypto.defaultCipherList;
49+
internalBinding('constants').crypto.defaultCipherList;
5050

5151
exports.DEFAULT_ECDH_CURVE = 'auto';
5252

‎lib/zlib.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ const {
4545
} = require('buffer');
4646
const { owner_symbol } = require('internal/async_hooks').symbols;
4747

48-
const constants = process.binding('constants').zlib;
48+
const constants = internalBinding('constants').zlib;
4949
const {
5050
Z_NO_FLUSH, Z_BLOCK, Z_PARTIAL_FLUSH, Z_SYNC_FLUSH, Z_FULL_FLUSH, Z_FINISH,
5151
Z_MIN_CHUNK, Z_MIN_WINDOWBITS, Z_MAX_WINDOWBITS, Z_MIN_LEVEL, Z_MAX_LEVEL,

‎src/node.cc

+8-8
Original file line numberDiff line numberDiff line change
@@ -1542,14 +1542,6 @@ static void GetBinding(const FunctionCallbackInfo<Value>& args) {
15421542
Local<Object> exports;
15431543
if (mod != nullptr) {
15441544
exports = InitModule(env, mod, module);
1545-
} else if (!strcmp(*module_v, "constants")) {
1546-
exports = Object::New(env->isolate());
1547-
CHECK(exports->SetPrototype(env->context(),
1548-
Null(env->isolate())).FromJust());
1549-
DefineConstants(env->isolate(), exports);
1550-
} else if (!strcmp(*module_v, "natives")) {
1551-
exports = Object::New(env->isolate());
1552-
DefineJavaScript(env, exports);
15531545
} else {
15541546
return ThrowIfNoSuchModule(env, *module_v);
15551547
}
@@ -1569,6 +1561,14 @@ static void GetInternalBinding(const FunctionCallbackInfo<Value>& args) {
15691561
node_module* mod = get_internal_module(*module_v);
15701562
if (mod != nullptr) {
15711563
exports = InitModule(env, mod, module);
1564+
} else if (!strcmp(*module_v, "constants")) {
1565+
exports = Object::New(env->isolate());
1566+
CHECK(exports->SetPrototype(env->context(),
1567+
Null(env->isolate())).FromJust());
1568+
DefineConstants(env->isolate(), exports);
1569+
} else if (!strcmp(*module_v, "natives")) {
1570+
exports = Object::New(env->isolate());
1571+
DefineJavaScript(env, exports);
15721572
} else if (!strcmp(*module_v, "code_cache")) {
15731573
// internalBinding('code_cache')
15741574
exports = Object::New(env->isolate());

0 commit comments

Comments
 (0)
Please sign in to comment.