Skip to content

Commit 668ad44

Browse files
bnoordhuisaddaleax
authored andcommitted
intl: unexpose Intl.v8BreakIterator
It was never an official Ecma-402 API, it is about to be superseded by `Intl.Segmenter` and it's prone to crash under some circumstances. Searches don't turn up any usage in the wild and the recommendation from the V8 team is to remove it. Now seems like a good a time as any to do that. Fixes: #8865 Fixes: #14909 Refs: https://github.com/tc39/proposal-intl-segmenter Refs: https://chromium-review.googlesource.com/c/v8/v8/+/620755 PR-URL: #15238 Reviewed-By: James M Snell <[email protected]> Reviewed-By: Anna Henningsen <[email protected]>
1 parent 61e9ba1 commit 668ad44

File tree

7 files changed

+35
-32
lines changed

7 files changed

+35
-32
lines changed

doc/api/deprecations.md

+3-2
Original file line numberDiff line numberDiff line change
@@ -185,9 +185,10 @@ and should no longer be used.
185185
<a id="DEP0017"></a>
186186
### DEP0017: Intl.v8BreakIterator
187187

188-
Type: Runtime
188+
Type: End-of-Life
189189

190-
The `Intl.v8BreakIterator` is deprecated and will be removed or replaced soon.
190+
`Intl.v8BreakIterator` was a non-standard extension and has been removed.
191+
See [`Intl.Segmenter`](https://github.com/tc39/proposal-intl-segmenter).
191192

192193
<a id="DEP0018"></a>
193194
### DEP0018: Unhandled promise rejections

lib/internal/errors.js

-2
Original file line numberDiff line numberDiff line change
@@ -275,8 +275,6 @@ E('ERR_UNKNOWN_STREAM_TYPE', 'Unknown stream file type');
275275
E('ERR_VALUE_OUT_OF_RANGE', (start, end, value) => {
276276
return `The value of "${start}" must be ${end}. Received "${value}"`;
277277
});
278-
E('ERR_V8BREAKITERATOR', 'Full ICU data not installed. ' +
279-
'See https://github.com/nodejs/node/wiki/Intl');
280278
E('ERR_VALID_PERFORMANCE_ENTRY_TYPE',
281279
'At least one valid performance entry type is required');
282280
E('ERR_VALUE_OUT_OF_RANGE', 'The value of "%s" must be %s. Received "%s"');

lib/internal/process.js

-14
Original file line numberDiff line numberDiff line change
@@ -133,20 +133,6 @@ function setupConfig(_source) {
133133
if (value === 'false') return false;
134134
return value;
135135
});
136-
const processConfig = process.binding('config');
137-
if (typeof Intl !== 'undefined' && Intl.hasOwnProperty('v8BreakIterator')) {
138-
const oldV8BreakIterator = Intl.v8BreakIterator;
139-
const des = Object.getOwnPropertyDescriptor(Intl, 'v8BreakIterator');
140-
des.value = require('internal/util').deprecate(function v8BreakIterator() {
141-
if (processConfig.hasSmallICU && !processConfig.icuDataDir) {
142-
// Intl.v8BreakIterator() would crash w/ fatal error, so throw instead.
143-
throw new errors.Error('ERR_V8BREAKITERATOR');
144-
}
145-
return Reflect.construct(oldV8BreakIterator, arguments);
146-
}, 'Intl.v8BreakIterator is deprecated and will be removed soon.',
147-
'DEP0017');
148-
Object.defineProperty(Intl, 'v8BreakIterator', des);
149-
}
150136
}
151137

152138

src/node.cc

+18-1
Original file line numberDiff line numberDiff line change
@@ -4586,11 +4586,28 @@ void FreeEnvironment(Environment* env) {
45864586
}
45874587

45884588

4589+
Local<Context> NewContext(Isolate* isolate,
4590+
Local<ObjectTemplate> object_template) {
4591+
auto context = Context::New(isolate, nullptr, object_template);
4592+
if (context.IsEmpty()) return context;
4593+
HandleScope handle_scope(isolate);
4594+
auto intl_key = FIXED_ONE_BYTE_STRING(isolate, "Intl");
4595+
auto break_iter_key = FIXED_ONE_BYTE_STRING(isolate, "v8BreakIterator");
4596+
Local<Value> intl_v;
4597+
Local<Object> intl;
4598+
if (context->Global()->Get(context, intl_key).ToLocal(&intl_v) &&
4599+
intl_v->ToObject(context).ToLocal(&intl)) {
4600+
intl->Delete(context, break_iter_key).FromJust();
4601+
}
4602+
return context;
4603+
}
4604+
4605+
45894606
inline int Start(Isolate* isolate, IsolateData* isolate_data,
45904607
int argc, const char* const* argv,
45914608
int exec_argc, const char* const* exec_argv) {
45924609
HandleScope handle_scope(isolate);
4593-
Local<Context> context = Context::New(isolate);
4610+
Local<Context> context = NewContext(isolate);
45944611
Context::Scope context_scope(context);
45954612
Environment env(isolate_data, context);
45964613
CHECK_EQ(0, uv_key_create(&thread_local_env));

src/node_contextify.cc

+1-1
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,7 @@ class ContextifyContext {
240240
CreateDataWrapper(env));
241241
object_template->SetHandler(config);
242242

243-
Local<Context> ctx = Context::New(env->isolate(), nullptr, object_template);
243+
Local<Context> ctx = NewContext(env->isolate(), object_template);
244244

245245
if (ctx.IsEmpty()) {
246246
env->ThrowError("Could not instantiate context");

src/node_internals.h

+8
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,14 @@ inline v8::Local<TypeName> PersistentToLocal(
125125
v8::Isolate* isolate,
126126
const v8::Persistent<TypeName>& persistent);
127127

128+
// Creates a new context with Node.js-specific tweaks. Currently, it removes
129+
// the `v8BreakIterator` property from the global `Intl` object if present.
130+
// See https://github.com/nodejs/node/issues/14909 for more info.
131+
v8::Local<v8::Context> NewContext(
132+
v8::Isolate* isolate,
133+
v8::Local<v8::ObjectTemplate> object_template =
134+
v8::Local<v8::ObjectTemplate>());
135+
128136
// Convert a struct sockaddr to a { address: '1.2.3.4', port: 1234 } JS object.
129137
// Sets address and port properties on the info object and returns it.
130138
// If |info| is omitted, a new object is returned.
+5-12
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,10 @@
11
'use strict';
22
const common = require('../common');
3+
const assert = require('assert');
4+
const vm = require('vm');
35

4-
if (!common.hasIntl || Intl.v8BreakIterator === undefined)
6+
if (typeof Intl === 'undefined')
57
common.skip('missing Intl');
68

7-
const assert = require('assert');
8-
const warning = 'Intl.v8BreakIterator is deprecated and will be removed soon.';
9-
common.expectWarning('DeprecationWarning', warning);
10-
11-
try {
12-
new Intl.v8BreakIterator();
13-
// May succeed if data is available - OK
14-
} catch (e) {
15-
// May throw this error if ICU data is not available - OK
16-
assert.throws(() => new Intl.v8BreakIterator(), /ICU data/);
17-
}
9+
assert(!('v8BreakIterator' in Intl));
10+
assert(!vm.runInNewContext('"v8BreakIterator" in Intl'));

0 commit comments

Comments
 (0)