diff options
author | Joyee Cheung <joyeec9h3@gmail.com> | 2018-12-19 05:23:47 +0800 |
---|---|---|
committer | Joyee Cheung <joyeec9h3@gmail.com> | 2018-12-21 07:46:47 +0800 |
commit | 263d13766f08fb3444c205ce7ecaaa3efd89546a (patch) | |
tree | 05e0c1c66b4619090da44dbc08a7135f300ec1ac /src/node_i18n.cc | |
parent | a29c93a1472947ed053b674cfd670a9d191594ea (diff) | |
download | android-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_i18n.cc')
-rw-r--r-- | src/node_i18n.cc | 62 |
1 files changed, 0 insertions, 62 deletions
diff --git a/src/node_i18n.cc b/src/node_i18n.cc index d3e1b96616..c081bde93b 100644 --- a/src/node_i18n.cc +++ b/src/node_i18n.cc @@ -510,67 +510,6 @@ void ICUErrorName(const FunctionCallbackInfo<Value>& args) { NewStringType::kNormal).ToLocalChecked()); } -#define TYPE_ICU "icu" -#define TYPE_UNICODE "unicode" -#define TYPE_CLDR "cldr" -#define TYPE_TZ "tz" - -/** - * This is the workhorse function that deals with the actual version info. - * Get an ICU version. - * @param type the type of version to get. One of VERSION_TYPES - * @param buf optional buffer for result - * @param status ICU error status. If failure, assume result is undefined. - * @return version number, or NULL. May or may not be buf. - */ -const char* GetVersion(const char* type, - char buf[U_MAX_VERSION_STRING_LENGTH], - UErrorCode* status) { - if (!strcmp(type, TYPE_ICU)) { - return U_ICU_VERSION; - } else if (!strcmp(type, TYPE_UNICODE)) { - return U_UNICODE_VERSION; - } else if (!strcmp(type, TYPE_TZ)) { - return icu::TimeZone::getTZDataVersion(*status); - } else if (!strcmp(type, TYPE_CLDR)) { - UVersionInfo versionArray; - ulocdata_getCLDRVersion(versionArray, status); - if (U_SUCCESS(*status)) { - u_versionToString(versionArray, buf); - return buf; - } - } - // Fall through - unknown type or error case - return nullptr; -} - -void GetVersion(const FunctionCallbackInfo<Value>& args) { - Environment* env = Environment::GetCurrent(args); - if ( args.Length() == 0 ) { - // With no args - return a comma-separated list of allowed values - args.GetReturnValue().Set( - String::NewFromUtf8(env->isolate(), - TYPE_ICU "," - TYPE_UNICODE "," - TYPE_CLDR "," - TYPE_TZ, NewStringType::kNormal).ToLocalChecked()); - } else { - CHECK_GE(args.Length(), 1); - CHECK(args[0]->IsString()); - Utf8Value val(env->isolate(), args[0]); - UErrorCode status = U_ZERO_ERROR; - char buf[U_MAX_VERSION_STRING_LENGTH] = ""; // Possible output buffer. - const char* versionString = GetVersion(*val, buf, &status); - - if (U_SUCCESS(status) && versionString) { - // Success. - args.GetReturnValue().Set( - String::NewFromUtf8(env->isolate(), - versionString, NewStringType::kNormal).ToLocalChecked()); - } - } -} - } // anonymous namespace bool InitializeICUDirectory(const std::string& path) { @@ -868,7 +807,6 @@ void Initialize(Local<Object> target, env->SetMethod(target, "toUnicode", ToUnicode); env->SetMethod(target, "toASCII", ToASCII); env->SetMethod(target, "getStringWidth", GetStringWidth); - env->SetMethod(target, "getVersion", GetVersion); // One-shot converters env->SetMethod(target, "icuErrName", ICUErrorName); |