Skip to content

Commit 11339cf

Browse files
bnoordhuiskrydos
authored andcommitted
src: make --icu-data-dir= switch testable
Move some code around so we can properly test whether the switch actually does anything. PR-URL: nodejs#11255 Reviewed-By: James M Snell <[email protected]> Reviewed-By: Sam Roberts <[email protected]>
1 parent 246654b commit 11339cf

File tree

6 files changed

+15
-21
lines changed

6 files changed

+15
-21
lines changed

lib/internal/process.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ function setupConfig(_source) {
124124
const oldV8BreakIterator = Intl.v8BreakIterator;
125125
const des = Object.getOwnPropertyDescriptor(Intl, 'v8BreakIterator');
126126
des.value = require('internal/util').deprecate(function v8BreakIterator() {
127-
if (processConfig.hasSmallICU && !process.icu_data_dir) {
127+
if (processConfig.hasSmallICU && !processConfig.icuDataDir) {
128128
// Intl.v8BreakIterator() would crash w/ fatal error, so throw instead.
129129
throw new Error('v8BreakIterator: full ICU data not installed. ' +
130130
'See https://github.com/nodejs/node/wiki/Intl');
@@ -134,8 +134,6 @@ function setupConfig(_source) {
134134
'DEP0017');
135135
Object.defineProperty(Intl, 'v8BreakIterator', des);
136136
}
137-
// Don’t let icu_data_dir leak through.
138-
delete process.icu_data_dir;
139137
}
140138

141139

src/node.cc

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ static const char* trace_enabled_categories = nullptr;
156156

157157
#if defined(NODE_HAVE_I18N_SUPPORT)
158158
// Path to ICU data (for i18n / Intl)
159-
static std::string icu_data_dir; // NOLINT(runtime/string)
159+
std::string icu_data_dir; // NOLINT(runtime/string)
160160
#endif
161161

162162
// used by C++ modules as well
@@ -3095,17 +3095,6 @@ void SetupProcessObject(Environment* env,
30953095
"ares",
30963096
FIXED_ONE_BYTE_STRING(env->isolate(), ARES_VERSION_STR));
30973097

3098-
#if defined(NODE_HAVE_I18N_SUPPORT) && defined(U_ICU_VERSION)
3099-
// ICU-related versions are now handled on the js side, see bootstrap_node.js
3100-
3101-
if (!icu_data_dir.empty()) {
3102-
// Did the user attempt (via env var or parameter) to set an ICU path?
3103-
READONLY_PROPERTY(process,
3104-
"icu_data_dir",
3105-
OneByteString(env->isolate(), icu_data_dir.c_str()));
3106-
}
3107-
#endif
3108-
31093098
const char node_modules_version[] = NODE_STRINGIFY(NODE_MODULE_VERSION);
31103099
READONLY_PROPERTY(
31113100
versions,

src/node_config.cc

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,11 @@ void InitConfig(Local<Object> target,
3939
READONLY_BOOLEAN_PROPERTY("hasSmallICU");
4040
#endif // NODE_HAVE_SMALL_ICU
4141

42-
if (flag_icu_data_dir)
43-
READONLY_BOOLEAN_PROPERTY("usingICUDataDir");
42+
target->DefineOwnProperty(env->context(),
43+
OneByteString(env->isolate(), "icuDataDir"),
44+
OneByteString(env->isolate(), icu_data_dir.data()))
45+
.FromJust();
46+
4447
#endif // NODE_HAVE_I18N_SUPPORT
4548

4649
if (config_preserve_symlinks)

src/node_i18n.cc

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -70,8 +70,6 @@ using v8::Object;
7070
using v8::String;
7171
using v8::Value;
7272

73-
bool flag_icu_data_dir = false;
74-
7573
namespace i18n {
7674

7775
const size_t kStorageSize = 1024;
@@ -415,7 +413,6 @@ bool InitializeICUDirectory(const std::string& path) {
415413
#endif // !NODE_HAVE_SMALL_ICU
416414
return (status == U_ZERO_ERROR);
417415
} else {
418-
flag_icu_data_dir = true;
419416
u_setDataDirectory(path.c_str());
420417
return true; // No error.
421418
}

src/node_i18n.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
namespace node {
1212

13-
extern bool flag_icu_data_dir;
13+
extern std::string icu_data_dir; // NOLINT(runtime/string)
1414

1515
namespace i18n {
1616

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
// Flags: --icu-data-dir=test/fixtures/empty/
2+
'use strict';
3+
require('../common');
4+
const assert = require('assert');
5+
6+
// No-op when ICU case mappings are unavailable.
7+
assert.strictEqual('ç'.toLocaleUpperCase('el'), 'ç');

0 commit comments

Comments
 (0)