Skip to content

Commit 39a2ac4

Browse files
joyeecheungaddaleax
authored andcommitted
process: move process.features initialization into node.js
Use `internalBinding('config')` to shim the legacy `process.features`. PR-URL: #25239 Reviewed-By: Anna Henningsen <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Minwoo Jung <[email protected]>
1 parent 6c7c77e commit 39a2ac4

File tree

5 files changed

+54
-45
lines changed

5 files changed

+54
-45
lines changed

lib/internal/bootstrap/node.js

+18
Original file line numberDiff line numberDiff line change
@@ -270,6 +270,24 @@ function startup() {
270270
'process.assert() is deprecated. Please use the `assert` module instead.',
271271
'DEP0100');
272272

273+
// TODO(joyeecheung): this property has not been well-maintained, should we
274+
// deprecate it in favor of a better API?
275+
const { isDebugBuild, hasOpenSSL } = internalBinding('config');
276+
Object.defineProperty(process, 'features', {
277+
enumerable: true,
278+
writable: false,
279+
configurable: false,
280+
value: {
281+
debug: isDebugBuild,
282+
uv: true,
283+
ipv6: true, // TODO(bnoordhuis) ping libuv
284+
tls_alpn: hasOpenSSL,
285+
tls_sni: hasOpenSSL,
286+
tls_ocsp: hasOpenSSL,
287+
tls: hasOpenSSL
288+
}
289+
});
290+
273291
const perf = internalBinding('performance');
274292
const {
275293
NODE_PERFORMANCE_MILESTONE_BOOTSTRAP_COMPLETE,

src/node.cc

-44
Original file line numberDiff line numberDiff line change
@@ -801,49 +801,6 @@ static void OnMessage(Local<Message> message, Local<Value> error) {
801801
}
802802
}
803803

804-
static Local<Object> GetFeatures(Environment* env) {
805-
EscapableHandleScope scope(env->isolate());
806-
807-
Local<Object> obj = Object::New(env->isolate());
808-
#if defined(DEBUG) && DEBUG
809-
Local<Value> debug = True(env->isolate());
810-
#else
811-
Local<Value> debug = False(env->isolate());
812-
#endif // defined(DEBUG) && DEBUG
813-
814-
obj->Set(env->context(),
815-
FIXED_ONE_BYTE_STRING(env->isolate(), "debug"),
816-
debug).FromJust();
817-
obj->Set(env->context(),
818-
FIXED_ONE_BYTE_STRING(env->isolate(), "uv"),
819-
True(env->isolate())).FromJust();
820-
// TODO(bnoordhuis) ping libuv
821-
obj->Set(env->context(),
822-
FIXED_ONE_BYTE_STRING(env->isolate(), "ipv6"),
823-
True(env->isolate())).FromJust();
824-
825-
#ifdef HAVE_OPENSSL
826-
Local<Boolean> have_openssl = True(env->isolate());
827-
#else
828-
Local<Boolean> have_openssl = False(env->isolate());
829-
#endif
830-
831-
obj->Set(env->context(),
832-
FIXED_ONE_BYTE_STRING(env->isolate(), "tls_alpn"),
833-
have_openssl).FromJust();
834-
obj->Set(env->context(),
835-
FIXED_ONE_BYTE_STRING(env->isolate(), "tls_sni"),
836-
have_openssl).FromJust();
837-
obj->Set(env->context(),
838-
FIXED_ONE_BYTE_STRING(env->isolate(), "tls_ocsp"),
839-
have_openssl).FromJust();
840-
obj->Set(env->context(),
841-
FIXED_ONE_BYTE_STRING(env->isolate(), "tls"),
842-
have_openssl).FromJust();
843-
844-
return scope.Escape(obj);
845-
}
846-
847804
void SetupProcessObject(Environment* env,
848805
const std::vector<std::string>& args,
849806
const std::vector<std::string>& exec_args) {
@@ -964,7 +921,6 @@ void SetupProcessObject(Environment* env,
964921

965922
READONLY_PROPERTY(process, "pid",
966923
Integer::New(env->isolate(), uv_os_getpid()));
967-
READONLY_PROPERTY(process, "features", GetFeatures(env));
968924

969925
CHECK(process->SetAccessor(env->context(),
970926
FIXED_ONE_BYTE_STRING(env->isolate(), "ppid"),

src/node_config.cc

+12
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,18 @@ static void Initialize(Local<Object> target,
2626
Environment* env = Environment::GetCurrent(context);
2727
Isolate* isolate = env->isolate();
2828

29+
#if defined(DEBUG) && DEBUG
30+
READONLY_TRUE_PROPERTY(target, "isDebugBuild");
31+
#else
32+
READONLY_FALSE_PROPERTY(target, "isDebugBuild");
33+
#endif // defined(DEBUG) && DEBUG
34+
35+
#if HAVE_OPENSSL
36+
READONLY_TRUE_PROPERTY(target, "hasOpenSSL");
37+
#else
38+
READONLY_FALSE_PROPERTY(target, "hasOpenSSL");
39+
#endif // HAVE_OPENSSL
40+
2941
#ifdef NODE_FIPS_MODE
3042
READONLY_TRUE_PROPERTY(target, "fipsMode");
3143
// TODO(addaleax): Use options parser variable instead.

src/util.h

+4-1
Original file line numberDiff line numberDiff line change
@@ -546,8 +546,11 @@ inline v8::MaybeLocal<v8::Value> ToV8Value(v8::Local<v8::Context> context,
546546
.FromJust(); \
547547
} while (0)
548548

549+
#define READONLY_FALSE_PROPERTY(obj, name) \
550+
READONLY_PROPERTY(obj, name, v8::False(isolate))
551+
549552
#define READONLY_TRUE_PROPERTY(obj, name) \
550-
READONLY_PROPERTY(obj, name, True(isolate))
553+
READONLY_PROPERTY(obj, name, v8::True(isolate))
551554

552555
#define READONLY_STRING_PROPERTY(obj, name, str) \
553556
READONLY_PROPERTY(obj, name, ToV8Value(context, str).ToLocalChecked())
+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
'use strict';
2+
3+
require('../common');
4+
const assert = require('assert');
5+
6+
const keys = new Set(Object.keys(process.features));
7+
8+
assert.deepStrictEqual(keys, new Set([
9+
'debug',
10+
'uv',
11+
'ipv6',
12+
'tls_alpn',
13+
'tls_sni',
14+
'tls_ocsp',
15+
'tls'
16+
]));
17+
18+
for (const key of keys) {
19+
assert.strictEqual(typeof process.features[key], 'boolean');
20+
}

0 commit comments

Comments
 (0)