summaryrefslogtreecommitdiff
path: root/src/node_metadata.cc
diff options
context:
space:
mode:
authorJoyee Cheung <joyeec9h3@gmail.com>2018-12-19 05:23:47 +0800
committerJoyee Cheung <joyeec9h3@gmail.com>2018-12-21 07:46:47 +0800
commit263d13766f08fb3444c205ce7ecaaa3efd89546a (patch)
tree05e0c1c66b4619090da44dbc08a7135f300ec1ac /src/node_metadata.cc
parenta29c93a1472947ed053b674cfd670a9d191594ea (diff)
downloadandroid-node-v8-263d13766f08fb3444c205ce7ecaaa3efd89546a.tar.gz
android-node-v8-263d13766f08fb3444c205ce7ecaaa3efd89546a.tar.bz2
android-node-v8-263d13766f08fb3444c205ce7ecaaa3efd89546a.zip
src: initialize ICU version in per_process::metadata.versions
Instead of - Initialize the ICU versions in JS land after consulting internalBinding('config').hasIntl - Joining the version keys in C++ - Splitting the keys in JS and call into C++ again to get the value for each of the keys Do: - Guard the initialization code behind `NODE_HAVE_I18N_SUPPORT` - Do the initialization in C++ right after ICU data is loaded - Initialize each version directly using ICU functions/constants, and put them in per_process::metadata.versions. These will be copied into `process.versions` naturally later. This way, the initialization of the versions won't be called in worker threads again. PR-URL: https://github.com/nodejs/node/pull/25115 Reviewed-By: Steven R Loomis <srloomis@us.ibm.com> Reviewed-By: Richard Lau <riclau@uk.ibm.com> Reviewed-By: Minwoo Jung <minwoo@nodesource.com> Reviewed-By: James M Snell <jasnell@gmail.com>
Diffstat (limited to 'src/node_metadata.cc')
-rw-r--r--src/node_metadata.cc31
1 files changed, 31 insertions, 0 deletions
diff --git a/src/node_metadata.cc b/src/node_metadata.cc
index a67e747563..ff8d408f5b 100644
--- a/src/node_metadata.cc
+++ b/src/node_metadata.cc
@@ -11,6 +11,13 @@
#include <openssl/opensslv.h>
#endif // HAVE_OPENSSL
+#ifdef NODE_HAVE_I18N_SUPPORT
+#include <unicode/timezone.h>
+#include <unicode/ulocdata.h>
+#include <unicode/uvernum.h>
+#include <unicode/uversion.h>
+#endif // NODE_HAVE_I18N_SUPPORT
+
namespace node {
namespace per_process {
@@ -34,6 +41,25 @@ std::string GetOpenSSLVersion() {
}
#endif // HAVE_OPENSSL
+#ifdef NODE_HAVE_I18N_SUPPORT
+void Metadata::Versions::InitializeIntlVersions() {
+ UErrorCode status = U_ZERO_ERROR;
+
+ const char* tz_version = icu::TimeZone::getTZDataVersion(status);
+ if (U_SUCCESS(status)) {
+ tz = tz_version;
+ }
+
+ char buf[U_MAX_VERSION_STRING_LENGTH];
+ UVersionInfo versionArray;
+ ulocdata_getCLDRVersion(versionArray, &status);
+ if (U_SUCCESS(status)) {
+ u_versionToString(versionArray, buf);
+ cldr = buf;
+ }
+}
+#endif // NODE_HAVE_I18N_SUPPORT
+
Metadata::Versions::Versions() {
node = NODE_VERSION_STRING;
v8 = v8::V8::GetVersion();
@@ -49,6 +75,11 @@ Metadata::Versions::Versions() {
#if HAVE_OPENSSL
openssl = GetOpenSSLVersion();
#endif
+
+#ifdef NODE_HAVE_I18N_SUPPORT
+ icu = U_ICU_VERSION;
+ unicode = U_UNICODE_VERSION;
+#endif // NODE_HAVE_I18N_SUPPORT
}
} // namespace node