intl: Don't crash if v8BreakIterator not available
If the undocumented v8BreakIterator does not have data available, monkeypatch it to throw an error instead of crashing. Fixes: https://github.com/nodejs/node/issues/3111 PR-URL: https://github.com/nodejs/node/pull/4253 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
This commit is contained in:
parent
bc8b525440
commit
cd752e8463
@ -117,6 +117,21 @@ function setupConfig(_source) {
|
|||||||
if (value === 'false') return false;
|
if (value === 'false') return false;
|
||||||
return value;
|
return value;
|
||||||
});
|
});
|
||||||
|
const processConfig = process.binding('config');
|
||||||
|
// Intl.v8BreakIterator() would crash w/ fatal error, so throw instead.
|
||||||
|
if (processConfig.hasIntl &&
|
||||||
|
processConfig.hasSmallICU &&
|
||||||
|
Intl.hasOwnProperty('v8BreakIterator') &&
|
||||||
|
!process.icu_data_dir) {
|
||||||
|
const des = Object.getOwnPropertyDescriptor(Intl, 'v8BreakIterator');
|
||||||
|
des.value = function v8BreakIterator() {
|
||||||
|
throw new Error('v8BreakIterator: full ICU data not installed. ' +
|
||||||
|
'See https://github.com/nodejs/node/wiki/Intl');
|
||||||
|
};
|
||||||
|
Object.defineProperty(Intl, 'v8BreakIterator', des);
|
||||||
|
}
|
||||||
|
// Don’t let icu_data_dir leak through.
|
||||||
|
delete process.icu_data_dir;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -2976,6 +2976,13 @@ void SetupProcessObject(Environment* env,
|
|||||||
READONLY_PROPERTY(versions,
|
READONLY_PROPERTY(versions,
|
||||||
"icu",
|
"icu",
|
||||||
OneByteString(env->isolate(), U_ICU_VERSION));
|
OneByteString(env->isolate(), U_ICU_VERSION));
|
||||||
|
|
||||||
|
if (icu_data_dir != nullptr) {
|
||||||
|
// 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));
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
const char node_modules_version[] = NODE_STRINGIFY(NODE_MODULE_VERSION);
|
const char node_modules_version[] = NODE_STRINGIFY(NODE_MODULE_VERSION);
|
||||||
|
15
test/parallel/test-intl-v8BreakIterator.js
Normal file
15
test/parallel/test-intl-v8BreakIterator.js
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
'use strict';
|
||||||
|
require('../common');
|
||||||
|
const assert = require('assert');
|
||||||
|
|
||||||
|
if (global.Intl === undefined || Intl.v8BreakIterator === undefined) {
|
||||||
|
return console.log('1..0 # Skipped: no Intl');
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
new Intl.v8BreakIterator();
|
||||||
|
// May succeed if data is available - OK
|
||||||
|
} catch (e) {
|
||||||
|
// May throw this error if ICU data is not available - OK
|
||||||
|
assert.throws(() => new Intl.v8BreakIterator(), /ICU data/);
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user