Skip to content
Permalink
Browse files

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>
  • Loading branch information...
joyeecheung authored and BridgeAR committed Dec 26, 2018
1 parent c07b12d commit 743056e3af278300667a2874ecb183b9c41dd80d
Showing with 54 additions and 45 deletions.
  1. +18 −0 lib/internal/bootstrap/node.js
  2. +0 −44 src/node.cc
  3. +12 −0 src/node_config.cc
  4. +4 −1 src/util.h
  5. +20 −0 test/parallel/test-process-features.js
@@ -306,6 +306,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,
@@ -809,49 +809,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) {
@@ -934,7 +891,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.
@@ -555,8 +555,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())
@@ -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');
}

0 comments on commit 743056e

Please sign in to comment.
You can’t perform that action at this time.