Skip to content

Commit

Permalink
intl: add deprecation warning for v8BreakIterator
Browse files Browse the repository at this point in the history
Fixes: #8865
PR-URL: #8908
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
  • Loading branch information
targos authored and jasnell committed Oct 7, 2016
1 parent b2534f1 commit 105e628
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 9 deletions.
19 changes: 10 additions & 9 deletions lib/internal/process.js
Original file line number Diff line number Diff line change
Expand Up @@ -118,16 +118,17 @@ function setupConfig(_source) {
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) {
if (typeof Intl !== 'undefined' && Intl.hasOwnProperty('v8BreakIterator')) {
const oldV8BreakIterator = Intl.v8BreakIterator;
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');
};
des.value = require('internal/util').deprecate(function v8BreakIterator() {
if (processConfig.hasSmallICU && !process.icu_data_dir) {
// 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);
}
// Don’t let icu_data_dir leak through.
Expand Down
3 changes: 3 additions & 0 deletions test/parallel/test-intl-v8BreakIterator.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ if (global.Intl === undefined || Intl.v8BreakIterator === undefined) {
return common.skip('no Intl');
}

const warning = 'Intl.v8BreakIterator is deprecated and will be removed soon.';
common.expectWarning('DeprecationWarning', warning);

try {
new Intl.v8BreakIterator();
// May succeed if data is available - OK
Expand Down

0 comments on commit 105e628

Please sign in to comment.