Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

process: move process.features initialization into node.js #25239

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions lib/internal/bootstrap/node.js
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,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,
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should also be available as process.versions.openssl even though that's not the purpose of that property - I wonder if we should just use that instead?

tls_sni: hasOpenSSL,
tls_ocsp: hasOpenSSL,
tls: hasOpenSSL
}
});

const perf = internalBinding('performance');
const {
NODE_PERFORMANCE_MILESTONE_BOOTSTRAP_COMPLETE,
Expand Down
44 changes: 0 additions & 44 deletions src/node.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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"),
Expand Down
12 changes: 12 additions & 0 deletions src/node_config.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
5 changes: 4 additions & 1 deletion src/util.h
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand Down
20 changes: 20 additions & 0 deletions test/parallel/test-process-features.js
Original file line number Diff line number Diff line change
@@ -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');
}