From c87f32c549a1359652b3a002f1c518e4deef6c47 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C3=ABl=20Zasso?= Date: Mon, 3 Oct 2016 17:48:48 +0200 Subject: [PATCH] intl: add deprecation warning for v8BreakIterator Ref: https://github.com/nodejs/node/issues/8865 --- lib/internal/process.js | 19 ++++++++++--------- test/parallel/test-intl-v8BreakIterator.js | 3 +++ 2 files changed, 13 insertions(+), 9 deletions(-) diff --git a/lib/internal/process.js b/lib/internal/process.js index 8afb89dccac84b..441fb722edb153 100644 --- a/lib/internal/process.js +++ b/lib/internal/process.js @@ -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. diff --git a/test/parallel/test-intl-v8BreakIterator.js b/test/parallel/test-intl-v8BreakIterator.js index 91717d139466a2..f6922bcd9b7314 100644 --- a/test/parallel/test-intl-v8BreakIterator.js +++ b/test/parallel/test-intl-v8BreakIterator.js @@ -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