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

src: move version metadata into node_metadata{.h, .cc} #24774

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from 2 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
2 changes: 2 additions & 0 deletions node.gyp
Original file line number Diff line number Diff line change
Expand Up @@ -370,6 +370,7 @@
'src/node_url.cc',
'src/node_util.cc',
'src/node_v8.cc',
'src/node_metadata.cc',
Copy link
Member Author

Choose a reason for hiding this comment

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

Oops, should've sort these

'src/node_watchdog.cc',
'src/node_worker.cc',
'src/node_zlib.cc',
Expand Down Expand Up @@ -442,6 +443,7 @@
'src/node_union_bytes.h',
'src/node_url.h',
'src/node_version.h',
'src/node_metadata.h',
'src/node_watchdog.h',
'src/node_worker.h',
'src/pipe_wrap.h',
Expand Down
130 changes: 12 additions & 118 deletions src/node.cc
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
#include "node_context_data.h"
#include "node_errors.h"
#include "node_internals.h"
#include "node_metadata.h"
#include "node_native_module.h"
#include "node_perf.h"
#include "node_platform.h"
Expand All @@ -48,16 +49,9 @@
#include "node_dtrace.h"
#endif

#include "ares.h"
#include "async_wrap-inl.h"
#include "env-inl.h"
#include "handle_wrap.h"
#ifdef NODE_EXPERIMENTAL_HTTP
# include "llhttp.h"
#else /* !NODE_EXPERIMENTAL_HTTP */
# include "http_parser.h"
#endif /* NODE_EXPERIMENTAL_HTTP */
#include "nghttp2/nghttp2ver.h"
#include "req_wrap-inl.h"
#include "string_bytes.h"
#include "tracing/agent.h"
Expand All @@ -68,7 +62,6 @@
#include "libplatform/libplatform.h"
#endif // NODE_USE_V8_PLATFORM
#include "v8-profiler.h"
#include "zlib.h"

#ifdef NODE_ENABLE_VTUNE_PROFILING
#include "../deps/v8/src/third_party/vtune/v8-vtune.h"
Expand Down Expand Up @@ -123,7 +116,6 @@ using v8::Array;
using v8::Boolean;
using v8::Context;
using v8::DEFAULT;
using v8::DontEnum;
using v8::EscapableHandleScope;
using v8::Exception;
using v8::Function;
Expand All @@ -146,8 +138,6 @@ using v8::Nothing;
using v8::Null;
using v8::Object;
using v8::ObjectTemplate;
using v8::PropertyAttribute;
using v8::ReadOnly;
using v8::Script;
using v8::ScriptOrigin;
using v8::SealHandleScope;
Expand All @@ -161,22 +151,6 @@ using v8::Value;

static bool v8_is_profiling = false;

#ifdef NODE_EXPERIMENTAL_HTTP
static const char llhttp_version[] =
NODE_STRINGIFY(LLHTTP_VERSION_MAJOR)
"."
NODE_STRINGIFY(LLHTTP_VERSION_MINOR)
"."
NODE_STRINGIFY(LLHTTP_VERSION_PATCH);
#else /* !NODE_EXPERIMENTAL_HTTP */
static const char http_parser_version[] =
NODE_STRINGIFY(HTTP_PARSER_VERSION_MAJOR)
"."
NODE_STRINGIFY(HTTP_PARSER_VERSION_MINOR)
"."
NODE_STRINGIFY(HTTP_PARSER_VERSION_PATCH);
#endif /* NODE_EXPERIMENTAL_HTTP */

// Bit flag used to track security reverts (see node_revert.h)
unsigned int reverted = 0;

Expand Down Expand Up @@ -215,27 +189,12 @@ class NodeTraceStateObserver :
auto trace_process = tracing::TracedValue::Create();
trace_process->BeginDictionary("versions");

#ifdef NODE_EXPERIMENTAL_HTTP
trace_process->SetString("llhttp", llhttp_version);
#else /* !NODE_EXPERIMENTAL_HTTP */
trace_process->SetString("http_parser", http_parser_version);
#endif /* NODE_EXPERIMENTAL_HTTP */

const char node_napi_version[] = NODE_STRINGIFY(NAPI_VERSION);
const char node_modules_version[] = NODE_STRINGIFY(NODE_MODULE_VERSION);
#define V(key) \
trace_process->SetString(#key, per_process::metadata.versions.key.c_str());

trace_process->SetString("node", NODE_VERSION_STRING);
trace_process->SetString("v8", V8::GetVersion());
trace_process->SetString("uv", uv_version_string());
trace_process->SetString("zlib", ZLIB_VERSION);
trace_process->SetString("ares", ARES_VERSION_STR);
trace_process->SetString("modules", node_modules_version);
trace_process->SetString("nghttp2", NGHTTP2_VERSION);
trace_process->SetString("napi", node_napi_version);
NODE_VERSIONS_KEYS(V)
#undef V

#if HAVE_OPENSSL
trace_process->SetString("openssl", crypto::GetOpenSSLVersion());
#endif
trace_process->EndDictionary();

trace_process->SetString("arch", NODE_ARCH);
Expand Down Expand Up @@ -954,31 +913,12 @@ static Local<Object> GetFeatures(Environment* env) {
static void DebugProcess(const FunctionCallbackInfo<Value>& args);
static void DebugEnd(const FunctionCallbackInfo<Value>& args);

namespace {

#define READONLY_PROPERTY(obj, str, var) \
do { \
obj->DefineOwnProperty(env->context(), \
OneByteString(env->isolate(), str), \
var, \
ReadOnly).FromJust(); \
} while (0)

#define READONLY_DONT_ENUM_PROPERTY(obj, str, var) \
do { \
obj->DefineOwnProperty(env->context(), \
OneByteString(env->isolate(), str), \
var, \
static_cast<PropertyAttribute>(ReadOnly|DontEnum)) \
.FromJust(); \
} while (0)

} // anonymous namespace

void SetupProcessObject(Environment* env,
const std::vector<std::string>& args,
const std::vector<std::string>& exec_args) {
HandleScope scope(env->isolate());
Isolate* isolate = env->isolate();
HandleScope scope(isolate);
Local<Context> context = env->context();

Local<Object> process = env->process_object();

Expand All @@ -1002,53 +942,10 @@ void SetupProcessObject(Environment* env,
Local<Object> versions = Object::New(env->isolate());
READONLY_PROPERTY(process, "versions", versions);

#ifdef NODE_EXPERIMENTAL_HTTP
READONLY_PROPERTY(versions,
"llhttp",
FIXED_ONE_BYTE_STRING(env->isolate(), llhttp_version));
#else /* !NODE_EXPERIMENTAL_HTTP */
READONLY_PROPERTY(versions,
"http_parser",
FIXED_ONE_BYTE_STRING(env->isolate(), http_parser_version));
#endif /* NODE_EXPERIMENTAL_HTTP */

// +1 to get rid of the leading 'v'
READONLY_PROPERTY(versions,
"node",
OneByteString(env->isolate(), NODE_VERSION + 1));
READONLY_PROPERTY(versions,
"v8",
OneByteString(env->isolate(), V8::GetVersion()));
READONLY_PROPERTY(versions,
"uv",
OneByteString(env->isolate(), uv_version_string()));
READONLY_PROPERTY(versions,
"zlib",
FIXED_ONE_BYTE_STRING(env->isolate(), ZLIB_VERSION));
READONLY_PROPERTY(versions,
"ares",
FIXED_ONE_BYTE_STRING(env->isolate(), ARES_VERSION_STR));

const char node_modules_version[] = NODE_STRINGIFY(NODE_MODULE_VERSION);
READONLY_PROPERTY(
versions,
"modules",
FIXED_ONE_BYTE_STRING(env->isolate(), node_modules_version));
READONLY_PROPERTY(versions,
"nghttp2",
FIXED_ONE_BYTE_STRING(env->isolate(), NGHTTP2_VERSION));
const char node_napi_version[] = NODE_STRINGIFY(NAPI_VERSION);
READONLY_PROPERTY(
versions,
"napi",
FIXED_ONE_BYTE_STRING(env->isolate(), node_napi_version));

#if HAVE_OPENSSL
READONLY_PROPERTY(
versions,
"openssl",
OneByteString(env->isolate(), crypto::GetOpenSSLVersion().c_str()));
#endif
#define V(key) \
READONLY_STRING_PROPERTY(versions, #key, per_process::metadata.versions.key);
NODE_VERSIONS_KEYS(V)
#undef V

// process.arch
READONLY_PROPERTY(process, "arch", OneByteString(env->isolate(), NODE_ARCH));
Expand Down Expand Up @@ -1319,9 +1216,6 @@ void SetupProcessObject(Environment* env,
}


#undef READONLY_PROPERTY


void SignalExit(int signo) {
uv_tty_reset_mode();
#ifdef __FreeBSD__
Expand Down
58 changes: 15 additions & 43 deletions src/node_config.cc
Original file line number Diff line number Diff line change
Expand Up @@ -12,68 +12,40 @@ using v8::Isolate;
using v8::Local;
using v8::Number;
using v8::Object;
using v8::ReadOnly;
using v8::String;
using v8::Value;

// The config binding is used to provide an internal view of compile or runtime
// config options that are required internally by lib/*.js code. This is an
// alternative to dropping additional properties onto the process object as
// has been the practice previously in node.cc.

#define READONLY_BOOLEAN_PROPERTY(str) \
do { \
target->DefineOwnProperty(context, \
FIXED_ONE_BYTE_STRING(isolate, str), \
True(isolate), ReadOnly).FromJust(); \
} while (0)

#define READONLY_STRING_PROPERTY(obj, str, val) \
do { \
(obj)->DefineOwnProperty(context, \
FIXED_ONE_BYTE_STRING(isolate, str), \
String::NewFromUtf8( \
isolate, \
val.data(), \
v8::NewStringType::kNormal).ToLocalChecked(), \
ReadOnly).FromJust(); \
} while (0)


#define READONLY_PROPERTY(obj, name, value) \
do { \
obj->DefineOwnProperty(env->context(), \
FIXED_ONE_BYTE_STRING(isolate, name), \
value, ReadOnly).FromJust(); \
} while (0)

static void Initialize(Local<Object> target,
Local<Value> unused,
Local<Context> context) {
Environment* env = Environment::GetCurrent(context);
Isolate* isolate = env->isolate();

#ifdef NODE_FIPS_MODE
READONLY_BOOLEAN_PROPERTY("fipsMode");
READONLY_TRUE_PROPERTY(target, "fipsMode");
// TODO(addaleax): Use options parser variable instead.
if (per_process_opts->force_fips_crypto)
READONLY_BOOLEAN_PROPERTY("fipsForced");
READONLY_TRUE_PROPERTY(target, "fipsForced");
#endif

#ifdef NODE_HAVE_I18N_SUPPORT

READONLY_BOOLEAN_PROPERTY("hasIntl");
READONLY_TRUE_PROPERTY(target, "hasIntl");

#ifdef NODE_HAVE_SMALL_ICU
READONLY_BOOLEAN_PROPERTY("hasSmallICU");
READONLY_TRUE_PROPERTY(target, "hasSmallICU");
#endif // NODE_HAVE_SMALL_ICU

#if NODE_USE_V8_PLATFORM
READONLY_BOOLEAN_PROPERTY("hasTracing");
READONLY_TRUE_PROPERTY(target, "hasTracing");
#endif

#if !defined(NODE_WITHOUT_NODE_OPTIONS)
READONLY_BOOLEAN_PROPERTY("hasNodeOptions");
READONLY_TRUE_PROPERTY(target, "hasNodeOptions");
#endif

// TODO(addaleax): This seems to be an unused, private API. Remove it?
Expand All @@ -83,35 +55,35 @@ static void Initialize(Local<Object> target,
#endif // NODE_HAVE_I18N_SUPPORT

if (env->options()->preserve_symlinks)
READONLY_BOOLEAN_PROPERTY("preserveSymlinks");
READONLY_TRUE_PROPERTY(target, "preserveSymlinks");
if (env->options()->preserve_symlinks_main)
READONLY_BOOLEAN_PROPERTY("preserveSymlinksMain");
READONLY_TRUE_PROPERTY(target, "preserveSymlinksMain");

if (env->options()->experimental_modules) {
READONLY_BOOLEAN_PROPERTY("experimentalModules");
READONLY_TRUE_PROPERTY(target, "experimentalModules");
const std::string& userland_loader = env->options()->userland_loader;
if (!userland_loader.empty()) {
READONLY_STRING_PROPERTY(target, "userLoader", userland_loader);
}
}

if (env->options()->experimental_vm_modules)
READONLY_BOOLEAN_PROPERTY("experimentalVMModules");
READONLY_TRUE_PROPERTY(target, "experimentalVMModules");

if (env->options()->experimental_worker)
READONLY_BOOLEAN_PROPERTY("experimentalWorker");
READONLY_TRUE_PROPERTY(target, "experimentalWorker");

if (env->options()->experimental_repl_await)
READONLY_BOOLEAN_PROPERTY("experimentalREPLAwait");
READONLY_TRUE_PROPERTY(target, "experimentalREPLAwait");

if (env->options()->pending_deprecation)
READONLY_BOOLEAN_PROPERTY("pendingDeprecation");
READONLY_TRUE_PROPERTY(target, "pendingDeprecation");

if (env->options()->expose_internals)
READONLY_BOOLEAN_PROPERTY("exposeInternals");
READONLY_TRUE_PROPERTY(target, "exposeInternals");

if (env->abort_on_uncaught_exception())
READONLY_BOOLEAN_PROPERTY("shouldAbortOnUncaughtException");
READONLY_TRUE_PROPERTY(target, "shouldAbortOnUncaughtException");

READONLY_PROPERTY(target,
"bits",
Expand Down
49 changes: 49 additions & 0 deletions src/node_metadata.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
#include "node_metadata.h"
#include "ares.h"
#include "nghttp2/nghttp2ver.h"
#include "node.h"
#include "util.h"
#include "uv.h"
#include "v8.h"
#include "zlib.h"

#if HAVE_OPENSSL
#include "node_crypto.h"
#endif

#ifdef NODE_EXPERIMENTAL_HTTP
#include "llhttp.h"
#else /* !NODE_EXPERIMENTAL_HTTP */
#include "http_parser.h"
#endif /* NODE_EXPERIMENTAL_HTTP */

namespace node {

namespace per_process {
Metadata metadata;
}

Metadata::Versions::Versions() {
node = NODE_VERSION_STRING;
v8 = v8::V8::GetVersion();
uv = uv_version_string();
zlib = ZLIB_VERSION;
ares = ARES_VERSION_STR;
modules = NODE_STRINGIFY(NODE_MODULE_VERSION);
nghttp2 = NGHTTP2_VERSION;
napi = NODE_STRINGIFY(NAPI_VERSION);

#ifdef NODE_EXPERIMENTAL_HTTP
llhttp = NODE_STRINGIFY(LLHTTP_VERSION_MAJOR) "." NODE_STRINGIFY(
LLHTTP_VERSION_MINOR) "." NODE_STRINGIFY(LLHTTP_VERSION_PATCH);
#else /* !NODE_EXPERIMENTAL_HTTP */
http_parser = NODE_STRINGIFY(HTTP_PARSER_VERSION_MAJOR) "." NODE_STRINGIFY(
HTTP_PARSER_VERSION_MINOR) "." NODE_STRINGIFY(HTTP_PARSER_VERSION_PATCH);
#endif /* NODE_EXPERIMENTAL_HTTP */

#if HAVE_OPENSSL
openssl = crypto::GetOpenSSLVersion();
#endif
}

} // namespace node
Loading