From 263d13766f08fb3444c205ce7ecaaa3efd89546a Mon Sep 17 00:00:00 2001 From: Joyee Cheung Date: Wed, 19 Dec 2018 05:23:47 +0800 Subject: 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 Reviewed-By: Richard Lau Reviewed-By: Minwoo Jung Reviewed-By: James M Snell --- src/node_metadata.h | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) (limited to 'src/node_metadata.h') diff --git a/src/node_metadata.h b/src/node_metadata.h index 99ccc23cb2..3c3a430dd7 100644 --- a/src/node_metadata.h +++ b/src/node_metadata.h @@ -25,14 +25,38 @@ namespace node { #define NODE_VERSIONS_KEY_CRYPTO(V) #endif +#ifdef NODE_HAVE_I18N_SUPPORT +#define NODE_VERSIONS_KEY_INTL(V) \ + V(cldr) \ + V(icu) \ + V(tz) \ + V(unicode) +#else +#define NODE_VERSIONS_KEY_INTL(V) +#endif // NODE_HAVE_I18N_SUPPORT + #define NODE_VERSIONS_KEYS(V) \ NODE_VERSIONS_KEYS_BASE(V) \ - NODE_VERSIONS_KEY_CRYPTO(V) + NODE_VERSIONS_KEY_CRYPTO(V) \ + NODE_VERSIONS_KEY_INTL(V) class Metadata { public: + Metadata() = default; + Metadata(Metadata&) = delete; + Metadata(Metadata&&) = delete; + Metadata operator=(Metadata&) = delete; + Metadata operator=(Metadata&&) = delete; + struct Versions { Versions(); + +#ifdef NODE_HAVE_I18N_SUPPORT + // Must be called on the main thread after + // i18n::InitializeICUDirectory() + void InitializeIntlVersions(); +#endif // NODE_HAVE_I18N_SUPPORT + #define V(key) std::string key; NODE_VERSIONS_KEYS(V) #undef V -- cgit v1.2.3