Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 2bd7437

Browse filesBrowse 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 <anna@addaleax.net> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Minwoo Jung <minwoo@nodesource.com>
1 parent 127439d commit 2bd7437
Copy full SHA for 2bd7437

File tree

Expand file treeCollapse file tree

5 files changed

+54
-45
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

5 files changed

+54
-45
lines changed
Open diff view settings
Collapse file

‎lib/internal/bootstrap/node.js‎

Copy file name to clipboardExpand all lines: lib/internal/bootstrap/node.js
+18Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -306,6 +306,24 @@ function startup() {
306306
'process.assert() is deprecated. Please use the `assert` module instead.',
307307
'DEP0100');
308308

309+
// TODO(joyeecheung): this property has not been well-maintained, should we
310+
// deprecate it in favor of a better API?
311+
const { isDebugBuild, hasOpenSSL } = internalBinding('config');
312+
Object.defineProperty(process, 'features', {
313+
enumerable: true,
314+
writable: false,
315+
configurable: false,
316+
value: {
317+
debug: isDebugBuild,
318+
uv: true,
319+
ipv6: true, // TODO(bnoordhuis) ping libuv
320+
tls_alpn: hasOpenSSL,
321+
tls_sni: hasOpenSSL,
322+
tls_ocsp: hasOpenSSL,
323+
tls: hasOpenSSL
324+
}
325+
});
326+
309327
const perf = internalBinding('performance');
310328
const {
311329
NODE_PERFORMANCE_MILESTONE_BOOTSTRAP_COMPLETE,
Collapse file

‎src/node.cc‎

Copy file name to clipboardExpand all lines: src/node.cc
-44Lines changed: 0 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -809,49 +809,6 @@ static void OnMessage(Local<Message> message, Local<Value> error) {
809809
}
810810
}
811811

812-
static Local<Object> GetFeatures(Environment* env) {
813-
EscapableHandleScope scope(env->isolate());
814-
815-
Local<Object> obj = Object::New(env->isolate());
816-
#if defined(DEBUG) && DEBUG
817-
Local<Value> debug = True(env->isolate());
818-
#else
819-
Local<Value> debug = False(env->isolate());
820-
#endif // defined(DEBUG) && DEBUG
821-
822-
obj->Set(env->context(),
823-
FIXED_ONE_BYTE_STRING(env->isolate(), "debug"),
824-
debug).FromJust();
825-
obj->Set(env->context(),
826-
FIXED_ONE_BYTE_STRING(env->isolate(), "uv"),
827-
True(env->isolate())).FromJust();
828-
// TODO(bnoordhuis) ping libuv
829-
obj->Set(env->context(),
830-
FIXED_ONE_BYTE_STRING(env->isolate(), "ipv6"),
831-
True(env->isolate())).FromJust();
832-
833-
#ifdef HAVE_OPENSSL
834-
Local<Boolean> have_openssl = True(env->isolate());
835-
#else
836-
Local<Boolean> have_openssl = False(env->isolate());
837-
#endif
838-
839-
obj->Set(env->context(),
840-
FIXED_ONE_BYTE_STRING(env->isolate(), "tls_alpn"),
841-
have_openssl).FromJust();
842-
obj->Set(env->context(),
843-
FIXED_ONE_BYTE_STRING(env->isolate(), "tls_sni"),
844-
have_openssl).FromJust();
845-
obj->Set(env->context(),
846-
FIXED_ONE_BYTE_STRING(env->isolate(), "tls_ocsp"),
847-
have_openssl).FromJust();
848-
obj->Set(env->context(),
849-
FIXED_ONE_BYTE_STRING(env->isolate(), "tls"),
850-
have_openssl).FromJust();
851-
852-
return scope.Escape(obj);
853-
}
854-
855812
void SetupProcessObject(Environment* env,
856813
const std::vector<std::string>& args,
857814
const std::vector<std::string>& exec_args) {
@@ -934,7 +891,6 @@ void SetupProcessObject(Environment* env,
934891

935892
READONLY_PROPERTY(process, "pid",
936893
Integer::New(env->isolate(), uv_os_getpid()));
937-
READONLY_PROPERTY(process, "features", GetFeatures(env));
938894

939895
CHECK(process->SetAccessor(env->context(),
940896
FIXED_ONE_BYTE_STRING(env->isolate(), "ppid"),
Collapse file

‎src/node_config.cc‎

Copy file name to clipboardExpand all lines: src/node_config.cc
+12Lines changed: 12 additions & 0 deletions
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.
Collapse file

‎src/util.h‎

Copy file name to clipboardExpand all lines: src/util.h
+4-1Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -555,8 +555,11 @@ inline v8::MaybeLocal<v8::Value> ToV8Value(v8::Local<v8::Context> context,
555555
.FromJust(); \
556556
} while (0)
557557

558+
#define READONLY_FALSE_PROPERTY(obj, name) \
559+
READONLY_PROPERTY(obj, name, v8::False(isolate))
560+
558561
#define READONLY_TRUE_PROPERTY(obj, name) \
559-
READONLY_PROPERTY(obj, name, True(isolate))
562+
READONLY_PROPERTY(obj, name, v8::True(isolate))
560563

561564
#define READONLY_STRING_PROPERTY(obj, name, str) \
562565
READONLY_PROPERTY(obj, name, ToV8Value(context, str).ToLocalChecked())
Collapse file
+20Lines changed: 20 additions & 0 deletions
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 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.