intl: add deprecation warning for v8BreakIterator

Fixes: https://github.com/nodejs/node/issues/8865
PR-URL: https://github.com/nodejs/node/pull/8908
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
This commit is contained in:
Michaël Zasso 2016-10-03 17:48:48 +02:00 committed by James M Snell
parent b2534f11c6
commit 105e628f84
2 changed files with 13 additions and 9 deletions

View File

@ -118,16 +118,17 @@ function setupConfig(_source) {
return value; return value;
}); });
const processConfig = process.binding('config'); const processConfig = process.binding('config');
// Intl.v8BreakIterator() would crash w/ fatal error, so throw instead. if (typeof Intl !== 'undefined' && Intl.hasOwnProperty('v8BreakIterator')) {
if (processConfig.hasIntl && const oldV8BreakIterator = Intl.v8BreakIterator;
processConfig.hasSmallICU &&
Intl.hasOwnProperty('v8BreakIterator') &&
!process.icu_data_dir) {
const des = Object.getOwnPropertyDescriptor(Intl, 'v8BreakIterator'); const des = Object.getOwnPropertyDescriptor(Intl, 'v8BreakIterator');
des.value = function v8BreakIterator() { des.value = require('internal/util').deprecate(function v8BreakIterator() {
throw new Error('v8BreakIterator: full ICU data not installed. ' + if (processConfig.hasSmallICU && !process.icu_data_dir) {
'See https://github.com/nodejs/node/wiki/Intl'); // Intl.v8BreakIterator() would crash w/ fatal error, so throw instead.
}; throw new Error('v8BreakIterator: full ICU data not installed. ' +
'See https://github.com/nodejs/node/wiki/Intl');
}
return Reflect.construct(oldV8BreakIterator, arguments);
}, 'Intl.v8BreakIterator is deprecated and will be removed soon.');
Object.defineProperty(Intl, 'v8BreakIterator', des); Object.defineProperty(Intl, 'v8BreakIterator', des);
} }
// Dont let icu_data_dir leak through. // Dont let icu_data_dir leak through.

View File

@ -6,6 +6,9 @@ if (global.Intl === undefined || Intl.v8BreakIterator === undefined) {
return common.skip('no Intl'); return common.skip('no Intl');
} }
const warning = 'Intl.v8BreakIterator is deprecated and will be removed soon.';
common.expectWarning('DeprecationWarning', warning);
try { try {
new Intl.v8BreakIterator(); new Intl.v8BreakIterator();
// May succeed if data is available - OK // May succeed if data is available - OK