process: move process.features initialization into node.js
Use `internalBinding('config')` to shim the legacy `process.features`. PR-URL: https://github.com/nodejs/node/pull/25239 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Minwoo Jung <minwoo@nodesource.com>
This commit is contained in:
parent
6c7c77ef05
commit
39a2ac4c6b
@ -270,6 +270,24 @@ function startup() {
|
||||
'process.assert() is deprecated. Please use the `assert` module instead.',
|
||||
'DEP0100');
|
||||
|
||||
// TODO(joyeecheung): this property has not been well-maintained, should we
|
||||
// deprecate it in favor of a better API?
|
||||
const { isDebugBuild, hasOpenSSL } = internalBinding('config');
|
||||
Object.defineProperty(process, 'features', {
|
||||
enumerable: true,
|
||||
writable: false,
|
||||
configurable: false,
|
||||
value: {
|
||||
debug: isDebugBuild,
|
||||
uv: true,
|
||||
ipv6: true, // TODO(bnoordhuis) ping libuv
|
||||
tls_alpn: hasOpenSSL,
|
||||
tls_sni: hasOpenSSL,
|
||||
tls_ocsp: hasOpenSSL,
|
||||
tls: hasOpenSSL
|
||||
}
|
||||
});
|
||||
|
||||
const perf = internalBinding('performance');
|
||||
const {
|
||||
NODE_PERFORMANCE_MILESTONE_BOOTSTRAP_COMPLETE,
|
||||
|
44
src/node.cc
44
src/node.cc
@ -801,49 +801,6 @@ static void OnMessage(Local<Message> message, Local<Value> error) {
|
||||
}
|
||||
}
|
||||
|
||||
static Local<Object> GetFeatures(Environment* env) {
|
||||
EscapableHandleScope scope(env->isolate());
|
||||
|
||||
Local<Object> obj = Object::New(env->isolate());
|
||||
#if defined(DEBUG) && DEBUG
|
||||
Local<Value> debug = True(env->isolate());
|
||||
#else
|
||||
Local<Value> debug = False(env->isolate());
|
||||
#endif // defined(DEBUG) && DEBUG
|
||||
|
||||
obj->Set(env->context(),
|
||||
FIXED_ONE_BYTE_STRING(env->isolate(), "debug"),
|
||||
debug).FromJust();
|
||||
obj->Set(env->context(),
|
||||
FIXED_ONE_BYTE_STRING(env->isolate(), "uv"),
|
||||
True(env->isolate())).FromJust();
|
||||
// TODO(bnoordhuis) ping libuv
|
||||
obj->Set(env->context(),
|
||||
FIXED_ONE_BYTE_STRING(env->isolate(), "ipv6"),
|
||||
True(env->isolate())).FromJust();
|
||||
|
||||
#ifdef HAVE_OPENSSL
|
||||
Local<Boolean> have_openssl = True(env->isolate());
|
||||
#else
|
||||
Local<Boolean> have_openssl = False(env->isolate());
|
||||
#endif
|
||||
|
||||
obj->Set(env->context(),
|
||||
FIXED_ONE_BYTE_STRING(env->isolate(), "tls_alpn"),
|
||||
have_openssl).FromJust();
|
||||
obj->Set(env->context(),
|
||||
FIXED_ONE_BYTE_STRING(env->isolate(), "tls_sni"),
|
||||
have_openssl).FromJust();
|
||||
obj->Set(env->context(),
|
||||
FIXED_ONE_BYTE_STRING(env->isolate(), "tls_ocsp"),
|
||||
have_openssl).FromJust();
|
||||
obj->Set(env->context(),
|
||||
FIXED_ONE_BYTE_STRING(env->isolate(), "tls"),
|
||||
have_openssl).FromJust();
|
||||
|
||||
return scope.Escape(obj);
|
||||
}
|
||||
|
||||
void SetupProcessObject(Environment* env,
|
||||
const std::vector<std::string>& args,
|
||||
const std::vector<std::string>& exec_args) {
|
||||
@ -964,7 +921,6 @@ void SetupProcessObject(Environment* env,
|
||||
|
||||
READONLY_PROPERTY(process, "pid",
|
||||
Integer::New(env->isolate(), uv_os_getpid()));
|
||||
READONLY_PROPERTY(process, "features", GetFeatures(env));
|
||||
|
||||
CHECK(process->SetAccessor(env->context(),
|
||||
FIXED_ONE_BYTE_STRING(env->isolate(), "ppid"),
|
||||
|
@ -26,6 +26,18 @@ static void Initialize(Local<Object> target,
|
||||
Environment* env = Environment::GetCurrent(context);
|
||||
Isolate* isolate = env->isolate();
|
||||
|
||||
#if defined(DEBUG) && DEBUG
|
||||
READONLY_TRUE_PROPERTY(target, "isDebugBuild");
|
||||
#else
|
||||
READONLY_FALSE_PROPERTY(target, "isDebugBuild");
|
||||
#endif // defined(DEBUG) && DEBUG
|
||||
|
||||
#if HAVE_OPENSSL
|
||||
READONLY_TRUE_PROPERTY(target, "hasOpenSSL");
|
||||
#else
|
||||
READONLY_FALSE_PROPERTY(target, "hasOpenSSL");
|
||||
#endif // HAVE_OPENSSL
|
||||
|
||||
#ifdef NODE_FIPS_MODE
|
||||
READONLY_TRUE_PROPERTY(target, "fipsMode");
|
||||
// TODO(addaleax): Use options parser variable instead.
|
||||
|
@ -546,8 +546,11 @@ inline v8::MaybeLocal<v8::Value> ToV8Value(v8::Local<v8::Context> context,
|
||||
.FromJust(); \
|
||||
} while (0)
|
||||
|
||||
#define READONLY_FALSE_PROPERTY(obj, name) \
|
||||
READONLY_PROPERTY(obj, name, v8::False(isolate))
|
||||
|
||||
#define READONLY_TRUE_PROPERTY(obj, name) \
|
||||
READONLY_PROPERTY(obj, name, True(isolate))
|
||||
READONLY_PROPERTY(obj, name, v8::True(isolate))
|
||||
|
||||
#define READONLY_STRING_PROPERTY(obj, name, str) \
|
||||
READONLY_PROPERTY(obj, name, ToV8Value(context, str).ToLocalChecked())
|
||||
|
20
test/parallel/test-process-features.js
Normal file
20
test/parallel/test-process-features.js
Normal file
@ -0,0 +1,20 @@
|
||||
'use strict';
|
||||
|
||||
require('../common');
|
||||
const assert = require('assert');
|
||||
|
||||
const keys = new Set(Object.keys(process.features));
|
||||
|
||||
assert.deepStrictEqual(keys, new Set([
|
||||
'debug',
|
||||
'uv',
|
||||
'ipv6',
|
||||
'tls_alpn',
|
||||
'tls_sni',
|
||||
'tls_ocsp',
|
||||
'tls'
|
||||
]));
|
||||
|
||||
for (const key of keys) {
|
||||
assert.strictEqual(typeof process.features[key], 'boolean');
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user