src: make --icu-data-dir= switch testable
Move some code around so we can properly test whether the switch actually does anything. PR-URL: https://github.com/nodejs/node/pull/11255 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Sam Roberts <vieuxtech@gmail.com>
This commit is contained in:
parent
75019dfa67
commit
46345b9374
@ -124,7 +124,7 @@ function setupConfig(_source) {
|
|||||||
const oldV8BreakIterator = Intl.v8BreakIterator;
|
const oldV8BreakIterator = Intl.v8BreakIterator;
|
||||||
const des = Object.getOwnPropertyDescriptor(Intl, 'v8BreakIterator');
|
const des = Object.getOwnPropertyDescriptor(Intl, 'v8BreakIterator');
|
||||||
des.value = require('internal/util').deprecate(function v8BreakIterator() {
|
des.value = require('internal/util').deprecate(function v8BreakIterator() {
|
||||||
if (processConfig.hasSmallICU && !process.icu_data_dir) {
|
if (processConfig.hasSmallICU && !processConfig.icuDataDir) {
|
||||||
// Intl.v8BreakIterator() would crash w/ fatal error, so throw instead.
|
// Intl.v8BreakIterator() would crash w/ fatal error, so throw instead.
|
||||||
throw new Error('v8BreakIterator: full ICU data not installed. ' +
|
throw new Error('v8BreakIterator: full ICU data not installed. ' +
|
||||||
'See https://github.com/nodejs/node/wiki/Intl');
|
'See https://github.com/nodejs/node/wiki/Intl');
|
||||||
@ -134,8 +134,6 @@ function setupConfig(_source) {
|
|||||||
'DEP0017');
|
'DEP0017');
|
||||||
Object.defineProperty(Intl, 'v8BreakIterator', des);
|
Object.defineProperty(Intl, 'v8BreakIterator', des);
|
||||||
}
|
}
|
||||||
// Don’t let icu_data_dir leak through.
|
|
||||||
delete process.icu_data_dir;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
13
src/node.cc
13
src/node.cc
@ -156,7 +156,7 @@ static const char* trace_enabled_categories = nullptr;
|
|||||||
|
|
||||||
#if defined(NODE_HAVE_I18N_SUPPORT)
|
#if defined(NODE_HAVE_I18N_SUPPORT)
|
||||||
// Path to ICU data (for i18n / Intl)
|
// Path to ICU data (for i18n / Intl)
|
||||||
static std::string icu_data_dir; // NOLINT(runtime/string)
|
std::string icu_data_dir; // NOLINT(runtime/string)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// used by C++ modules as well
|
// used by C++ modules as well
|
||||||
@ -3095,17 +3095,6 @@ void SetupProcessObject(Environment* env,
|
|||||||
"ares",
|
"ares",
|
||||||
FIXED_ONE_BYTE_STRING(env->isolate(), ARES_VERSION_STR));
|
FIXED_ONE_BYTE_STRING(env->isolate(), ARES_VERSION_STR));
|
||||||
|
|
||||||
#if defined(NODE_HAVE_I18N_SUPPORT) && defined(U_ICU_VERSION)
|
|
||||||
// ICU-related versions are now handled on the js side, see bootstrap_node.js
|
|
||||||
|
|
||||||
if (!icu_data_dir.empty()) {
|
|
||||||
// Did the user attempt (via env var or parameter) to set an ICU path?
|
|
||||||
READONLY_PROPERTY(process,
|
|
||||||
"icu_data_dir",
|
|
||||||
OneByteString(env->isolate(), icu_data_dir.c_str()));
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
const char node_modules_version[] = NODE_STRINGIFY(NODE_MODULE_VERSION);
|
const char node_modules_version[] = NODE_STRINGIFY(NODE_MODULE_VERSION);
|
||||||
READONLY_PROPERTY(
|
READONLY_PROPERTY(
|
||||||
versions,
|
versions,
|
||||||
|
@ -39,8 +39,11 @@ void InitConfig(Local<Object> target,
|
|||||||
READONLY_BOOLEAN_PROPERTY("hasSmallICU");
|
READONLY_BOOLEAN_PROPERTY("hasSmallICU");
|
||||||
#endif // NODE_HAVE_SMALL_ICU
|
#endif // NODE_HAVE_SMALL_ICU
|
||||||
|
|
||||||
if (flag_icu_data_dir)
|
target->DefineOwnProperty(env->context(),
|
||||||
READONLY_BOOLEAN_PROPERTY("usingICUDataDir");
|
OneByteString(env->isolate(), "icuDataDir"),
|
||||||
|
OneByteString(env->isolate(), icu_data_dir.data()))
|
||||||
|
.FromJust();
|
||||||
|
|
||||||
#endif // NODE_HAVE_I18N_SUPPORT
|
#endif // NODE_HAVE_I18N_SUPPORT
|
||||||
|
|
||||||
if (config_preserve_symlinks)
|
if (config_preserve_symlinks)
|
||||||
|
@ -70,8 +70,6 @@ using v8::Object;
|
|||||||
using v8::String;
|
using v8::String;
|
||||||
using v8::Value;
|
using v8::Value;
|
||||||
|
|
||||||
bool flag_icu_data_dir = false;
|
|
||||||
|
|
||||||
namespace i18n {
|
namespace i18n {
|
||||||
|
|
||||||
const size_t kStorageSize = 1024;
|
const size_t kStorageSize = 1024;
|
||||||
@ -415,7 +413,6 @@ bool InitializeICUDirectory(const std::string& path) {
|
|||||||
#endif // !NODE_HAVE_SMALL_ICU
|
#endif // !NODE_HAVE_SMALL_ICU
|
||||||
return (status == U_ZERO_ERROR);
|
return (status == U_ZERO_ERROR);
|
||||||
} else {
|
} else {
|
||||||
flag_icu_data_dir = true;
|
|
||||||
u_setDataDirectory(path.c_str());
|
u_setDataDirectory(path.c_str());
|
||||||
return true; // No error.
|
return true; // No error.
|
||||||
}
|
}
|
||||||
|
@ -10,7 +10,7 @@
|
|||||||
|
|
||||||
namespace node {
|
namespace node {
|
||||||
|
|
||||||
extern bool flag_icu_data_dir;
|
extern std::string icu_data_dir; // NOLINT(runtime/string)
|
||||||
|
|
||||||
namespace i18n {
|
namespace i18n {
|
||||||
|
|
||||||
|
7
test/parallel/test-intl-no-icu-data.js
Normal file
7
test/parallel/test-intl-no-icu-data.js
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
// Flags: --icu-data-dir=test/fixtures/empty/
|
||||||
|
'use strict';
|
||||||
|
require('../common');
|
||||||
|
const assert = require('assert');
|
||||||
|
|
||||||
|
// No-op when ICU case mappings are unavailable.
|
||||||
|
assert.strictEqual('ç'.toLocaleUpperCase('el'), 'ç');
|
Loading…
x
Reference in New Issue
Block a user