src,lib: move natives
and constants
to internalBinding()
Refs: https://github.com/nodejs/node/issues/22160 PR-URL: https://github.com/nodejs/node/pull/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>
This commit is contained in:
parent
20282b1cb0
commit
87b808f761
@ -29,7 +29,7 @@ const {
|
|||||||
ERR_INVALID_ARG_TYPE
|
ERR_INVALID_ARG_TYPE
|
||||||
} = require('internal/errors').codes;
|
} = require('internal/errors').codes;
|
||||||
|
|
||||||
const { SSL_OP_CIPHER_SERVER_PREFERENCE } = process.binding('constants').crypto;
|
const { SSL_OP_CIPHER_SERVER_PREFERENCE } = internalBinding('constants').crypto;
|
||||||
|
|
||||||
// Lazily loaded from internal/crypto/util.
|
// Lazily loaded from internal/crypto/util.
|
||||||
let toBuf = null;
|
let toBuf = null;
|
||||||
|
@ -25,7 +25,7 @@
|
|||||||
// towards using the specific constants exposed by the individual modules on
|
// towards using the specific constants exposed by the individual modules on
|
||||||
// which they are most relevant.
|
// which they are most relevant.
|
||||||
// Deprecation Code: DEP0008
|
// Deprecation Code: DEP0008
|
||||||
const constants = process.binding('constants');
|
const constants = internalBinding('constants');
|
||||||
Object.assign(exports,
|
Object.assign(exports,
|
||||||
constants.os.dlopen,
|
constants.os.dlopen,
|
||||||
constants.os.errno,
|
constants.os.errno,
|
||||||
|
@ -34,7 +34,7 @@ const {
|
|||||||
ERR_CRYPTO_FIPS_FORCED,
|
ERR_CRYPTO_FIPS_FORCED,
|
||||||
ERR_CRYPTO_FIPS_UNAVAILABLE
|
ERR_CRYPTO_FIPS_UNAVAILABLE
|
||||||
} = require('internal/errors').codes;
|
} = require('internal/errors').codes;
|
||||||
const constants = process.binding('constants').crypto;
|
const constants = internalBinding('constants').crypto;
|
||||||
const { getOptions } = internalBinding('options');
|
const { getOptions } = internalBinding('options');
|
||||||
const pendingDeprecation = getOptions('--pending-deprecation');
|
const pendingDeprecation = getOptions('--pending-deprecation');
|
||||||
const {
|
const {
|
||||||
|
@ -52,7 +52,7 @@ const {
|
|||||||
defaultTriggerAsyncIdScope,
|
defaultTriggerAsyncIdScope,
|
||||||
symbols: { async_id_symbol, owner_symbol }
|
symbols: { async_id_symbol, owner_symbol }
|
||||||
} = require('internal/async_hooks');
|
} = require('internal/async_hooks');
|
||||||
const { UV_UDP_REUSEADDR } = process.binding('constants').os;
|
const { UV_UDP_REUSEADDR } = internalBinding('constants').os;
|
||||||
|
|
||||||
const { UDP, SendWrap } = internalBinding('udp_wrap');
|
const { UDP, SendWrap } = internalBinding('udp_wrap');
|
||||||
|
|
||||||
|
@ -24,7 +24,7 @@
|
|||||||
|
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
const { fs: constants } = process.binding('constants');
|
const { fs: constants } = internalBinding('constants');
|
||||||
const {
|
const {
|
||||||
S_IFIFO,
|
S_IFIFO,
|
||||||
S_IFLNK,
|
S_IFLNK,
|
||||||
|
@ -123,7 +123,7 @@
|
|||||||
this.script = null; // The ContextifyScript of the module
|
this.script = null; // The ContextifyScript of the module
|
||||||
}
|
}
|
||||||
|
|
||||||
NativeModule._source = getBinding('natives');
|
NativeModule._source = getInternalBinding('natives');
|
||||||
NativeModule._cache = {};
|
NativeModule._cache = {};
|
||||||
|
|
||||||
const config = getBinding('config');
|
const config = getBinding('config');
|
||||||
@ -256,12 +256,12 @@
|
|||||||
// 1. `internalBinding('code_cache_hash')` must be in sync with
|
// 1. `internalBinding('code_cache_hash')` must be in sync with
|
||||||
// `internalBinding('code_cache')` (same C++ file)
|
// `internalBinding('code_cache')` (same C++ file)
|
||||||
// 2. `internalBinding('natives_hash')` must be in sync with
|
// 2. `internalBinding('natives_hash')` must be in sync with
|
||||||
// `process.binding('natives')` (same C++ file)
|
// `internalBinding('natives')` (same C++ file)
|
||||||
// 3. If `internalBinding('natives_hash')` is in sync with
|
// 3. If `internalBinding('natives_hash')` is in sync with
|
||||||
// `internalBinding('natives_hash')`, then the (unwrapped)
|
// `internalBinding('natives_hash')`, then the (unwrapped)
|
||||||
// code used to generate `internalBinding('code_cache')`
|
// code used to generate `internalBinding('code_cache')`
|
||||||
// should be in sync with the (unwrapped) code in
|
// should be in sync with the (unwrapped) code in
|
||||||
// `process.binding('natives')`
|
// `internalBinding('natives')`
|
||||||
// There will be, however, false positives if the wrapper used
|
// There will be, however, false positives if the wrapper used
|
||||||
// to generate the cache is different from the one used at run time,
|
// to generate the cache is different from the one used at run time,
|
||||||
// and the length of the wrapper somehow stays the same.
|
// and the length of the wrapper somehow stays the same.
|
||||||
|
@ -414,7 +414,9 @@
|
|||||||
'spawn_sync',
|
'spawn_sync',
|
||||||
'js_stream',
|
'js_stream',
|
||||||
'zlib',
|
'zlib',
|
||||||
'buffer']);
|
'buffer',
|
||||||
|
'natives',
|
||||||
|
'constants']);
|
||||||
process.binding = function binding(name) {
|
process.binding = function binding(name) {
|
||||||
return internalBindingWhitelist.has(name) ?
|
return internalBindingWhitelist.has(name) ?
|
||||||
internalBinding(name) :
|
internalBinding(name) :
|
||||||
|
@ -3,7 +3,7 @@
|
|||||||
const {
|
const {
|
||||||
RSA_PKCS1_OAEP_PADDING,
|
RSA_PKCS1_OAEP_PADDING,
|
||||||
RSA_PKCS1_PADDING
|
RSA_PKCS1_PADDING
|
||||||
} = process.binding('constants').crypto;
|
} = internalBinding('constants').crypto;
|
||||||
|
|
||||||
const {
|
const {
|
||||||
ERR_CRYPTO_INVALID_STATE,
|
ERR_CRYPTO_INVALID_STATE,
|
||||||
|
@ -24,7 +24,7 @@ const {
|
|||||||
POINT_CONVERSION_COMPRESSED,
|
POINT_CONVERSION_COMPRESSED,
|
||||||
POINT_CONVERSION_HYBRID,
|
POINT_CONVERSION_HYBRID,
|
||||||
POINT_CONVERSION_UNCOMPRESSED
|
POINT_CONVERSION_UNCOMPRESSED
|
||||||
} = process.binding('constants').crypto;
|
} = internalBinding('constants').crypto;
|
||||||
|
|
||||||
const DH_GENERATOR = 2;
|
const DH_GENERATOR = 2;
|
||||||
|
|
||||||
|
@ -9,7 +9,7 @@ const { Sign: _Sign, Verify: _Verify } = internalBinding('crypto');
|
|||||||
const {
|
const {
|
||||||
RSA_PSS_SALTLEN_AUTO,
|
RSA_PSS_SALTLEN_AUTO,
|
||||||
RSA_PKCS1_PADDING
|
RSA_PKCS1_PADDING
|
||||||
} = process.binding('constants').crypto;
|
} = internalBinding('constants').crypto;
|
||||||
const {
|
const {
|
||||||
getDefaultEncoding,
|
getDefaultEncoding,
|
||||||
kHandle,
|
kHandle,
|
||||||
|
@ -10,7 +10,7 @@ const {
|
|||||||
|
|
||||||
const {
|
const {
|
||||||
ENGINE_METHOD_ALL
|
ENGINE_METHOD_ALL
|
||||||
} = process.binding('constants').crypto;
|
} = internalBinding('constants').crypto;
|
||||||
|
|
||||||
const {
|
const {
|
||||||
ERR_CRYPTO_ENGINE_UNKNOWN,
|
ERR_CRYPTO_ENGINE_UNKNOWN,
|
||||||
|
@ -6,7 +6,7 @@ const {
|
|||||||
O_WRONLY,
|
O_WRONLY,
|
||||||
S_IFMT,
|
S_IFMT,
|
||||||
S_IFREG
|
S_IFREG
|
||||||
} = process.binding('constants').fs;
|
} = internalBinding('constants').fs;
|
||||||
const binding = process.binding('fs');
|
const binding = process.binding('fs');
|
||||||
const { Buffer, kMaxLength } = require('buffer');
|
const { Buffer, kMaxLength } = require('buffer');
|
||||||
const {
|
const {
|
||||||
|
@ -43,7 +43,7 @@ const {
|
|||||||
UV_DIRENT_SOCKET,
|
UV_DIRENT_SOCKET,
|
||||||
UV_DIRENT_CHAR,
|
UV_DIRENT_CHAR,
|
||||||
UV_DIRENT_BLOCK
|
UV_DIRENT_BLOCK
|
||||||
} = process.binding('constants').fs;
|
} = internalBinding('constants').fs;
|
||||||
|
|
||||||
const isWindows = process.platform === 'win32';
|
const isWindows = process.platform === 'win32';
|
||||||
|
|
||||||
|
@ -118,7 +118,7 @@ function setupPosixMethods(_initgroups, _setegid, _seteuid,
|
|||||||
|
|
||||||
// Worker threads don't receive signals.
|
// Worker threads don't receive signals.
|
||||||
function setupSignalHandlers(internalBinding) {
|
function setupSignalHandlers(internalBinding) {
|
||||||
const constants = process.binding('constants').os.signals;
|
const constants = internalBinding('constants').os.signals;
|
||||||
const signalWraps = Object.create(null);
|
const signalWraps = Object.create(null);
|
||||||
let Signal;
|
let Signal;
|
||||||
|
|
||||||
|
@ -17,7 +17,7 @@ const {
|
|||||||
}
|
}
|
||||||
} = require('internal/errors');
|
} = require('internal/errors');
|
||||||
const util = require('util');
|
const util = require('util');
|
||||||
const constants = process.binding('constants').os.signals;
|
const constants = internalBinding('constants').os.signals;
|
||||||
const { deprecate } = require('internal/util');
|
const { deprecate } = require('internal/util');
|
||||||
|
|
||||||
function setupAssert() {
|
function setupAssert() {
|
||||||
|
@ -5,7 +5,7 @@ const {
|
|||||||
ERR_NO_CRYPTO,
|
ERR_NO_CRYPTO,
|
||||||
ERR_UNKNOWN_SIGNAL
|
ERR_UNKNOWN_SIGNAL
|
||||||
} = require('internal/errors').codes;
|
} = require('internal/errors').codes;
|
||||||
const { signals } = process.binding('constants').os;
|
const { signals } = internalBinding('constants').os;
|
||||||
const {
|
const {
|
||||||
getHiddenValue,
|
getHiddenValue,
|
||||||
setHiddenValue,
|
setHiddenValue,
|
||||||
|
@ -19,7 +19,7 @@ const scriptFiles = [
|
|||||||
var script = '';
|
var script = '';
|
||||||
|
|
||||||
scriptFiles.forEach(function(s) {
|
scriptFiles.forEach(function(s) {
|
||||||
script += process.binding('natives')[s] + '\n';
|
script += internalBinding('natives')[s] + '\n';
|
||||||
});
|
});
|
||||||
|
|
||||||
const tickArguments = [];
|
const tickArguments = [];
|
||||||
|
@ -22,7 +22,7 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
const { pushValToArrayMax, safeGetenv } = internalBinding('util');
|
const { pushValToArrayMax, safeGetenv } = internalBinding('util');
|
||||||
const constants = process.binding('constants').os;
|
const constants = internalBinding('constants').os;
|
||||||
const { deprecate } = require('internal/util');
|
const { deprecate } = require('internal/util');
|
||||||
const isWindows = process.platform === 'win32';
|
const isWindows = process.platform === 'win32';
|
||||||
|
|
||||||
|
@ -46,7 +46,7 @@ exports.CLIENT_RENEG_LIMIT = 3;
|
|||||||
exports.CLIENT_RENEG_WINDOW = 600;
|
exports.CLIENT_RENEG_WINDOW = 600;
|
||||||
|
|
||||||
exports.DEFAULT_CIPHERS =
|
exports.DEFAULT_CIPHERS =
|
||||||
process.binding('constants').crypto.defaultCipherList;
|
internalBinding('constants').crypto.defaultCipherList;
|
||||||
|
|
||||||
exports.DEFAULT_ECDH_CURVE = 'auto';
|
exports.DEFAULT_ECDH_CURVE = 'auto';
|
||||||
|
|
||||||
|
@ -45,7 +45,7 @@ const {
|
|||||||
} = require('buffer');
|
} = require('buffer');
|
||||||
const { owner_symbol } = require('internal/async_hooks').symbols;
|
const { owner_symbol } = require('internal/async_hooks').symbols;
|
||||||
|
|
||||||
const constants = process.binding('constants').zlib;
|
const constants = internalBinding('constants').zlib;
|
||||||
const {
|
const {
|
||||||
Z_NO_FLUSH, Z_BLOCK, Z_PARTIAL_FLUSH, Z_SYNC_FLUSH, Z_FULL_FLUSH, Z_FINISH,
|
Z_NO_FLUSH, Z_BLOCK, Z_PARTIAL_FLUSH, Z_SYNC_FLUSH, Z_FULL_FLUSH, Z_FINISH,
|
||||||
Z_MIN_CHUNK, Z_MIN_WINDOWBITS, Z_MAX_WINDOWBITS, Z_MIN_LEVEL, Z_MAX_LEVEL,
|
Z_MIN_CHUNK, Z_MIN_WINDOWBITS, Z_MAX_WINDOWBITS, Z_MIN_LEVEL, Z_MAX_LEVEL,
|
||||||
|
16
src/node.cc
16
src/node.cc
@ -1542,14 +1542,6 @@ static void GetBinding(const FunctionCallbackInfo<Value>& args) {
|
|||||||
Local<Object> exports;
|
Local<Object> exports;
|
||||||
if (mod != nullptr) {
|
if (mod != nullptr) {
|
||||||
exports = InitModule(env, mod, module);
|
exports = InitModule(env, mod, module);
|
||||||
} else if (!strcmp(*module_v, "constants")) {
|
|
||||||
exports = Object::New(env->isolate());
|
|
||||||
CHECK(exports->SetPrototype(env->context(),
|
|
||||||
Null(env->isolate())).FromJust());
|
|
||||||
DefineConstants(env->isolate(), exports);
|
|
||||||
} else if (!strcmp(*module_v, "natives")) {
|
|
||||||
exports = Object::New(env->isolate());
|
|
||||||
DefineJavaScript(env, exports);
|
|
||||||
} else {
|
} else {
|
||||||
return ThrowIfNoSuchModule(env, *module_v);
|
return ThrowIfNoSuchModule(env, *module_v);
|
||||||
}
|
}
|
||||||
@ -1569,6 +1561,14 @@ static void GetInternalBinding(const FunctionCallbackInfo<Value>& args) {
|
|||||||
node_module* mod = get_internal_module(*module_v);
|
node_module* mod = get_internal_module(*module_v);
|
||||||
if (mod != nullptr) {
|
if (mod != nullptr) {
|
||||||
exports = InitModule(env, mod, module);
|
exports = InitModule(env, mod, module);
|
||||||
|
} else if (!strcmp(*module_v, "constants")) {
|
||||||
|
exports = Object::New(env->isolate());
|
||||||
|
CHECK(exports->SetPrototype(env->context(),
|
||||||
|
Null(env->isolate())).FromJust());
|
||||||
|
DefineConstants(env->isolate(), exports);
|
||||||
|
} else if (!strcmp(*module_v, "natives")) {
|
||||||
|
exports = Object::New(env->isolate());
|
||||||
|
DefineJavaScript(env, exports);
|
||||||
} else if (!strcmp(*module_v, "code_cache")) {
|
} else if (!strcmp(*module_v, "code_cache")) {
|
||||||
// internalBinding('code_cache')
|
// internalBinding('code_cache')
|
||||||
exports = Object::New(env->isolate());
|
exports = Object::New(env->isolate());
|
||||||
|
Loading…
x
Reference in New Issue
Block a user