Commit 8c311273 authored by Frank Tang's avatar Frank Tang Committed by Commit Bot

[Intl] Rename position to index in Intl.Segmenter

Sync with
https://github.com/tc39/proposal-intl-segmenter/pull/55
and
https://github.com/tc39/test262/pull/1994

Bug: v8:8588
Change-Id: Ifc46779f156ea986e3dbe6a632a781bb7134112b
Reviewed-on: https://chromium-review.googlesource.com/c/1374997Reviewed-by: 's avatarSathya Gunasekaran <gsathya@chromium.org>
Commit-Queue: Frank Tang <ftang@chromium.org>
Cr-Commit-Position: refs/heads/master@{#58301}
parent 60657604
......@@ -4846,8 +4846,8 @@ void Genesis::InitializeGlobal_harmony_intl_segmenter() {
false);
SimpleInstallGetter(isolate(), prototype,
factory()->InternalizeUtf8String("position"),
Builtins::kSegmentIteratorPrototypePosition, false);
factory()->InternalizeUtf8String("index"),
Builtins::kSegmentIteratorPrototypeIndex, false);
SimpleInstallGetter(isolate(), prototype,
factory()->InternalizeUtf8String("breakType"),
......
......@@ -1474,8 +1474,8 @@ namespace internal {
CPP(SegmentIteratorPrototypeFollowing) \
/* ecma402 #sec-segment-iterator-prototype-preceding */ \
CPP(SegmentIteratorPrototypePreceding) \
/* ecma402 #sec-segment-iterator-prototype-position */ \
CPP(SegmentIteratorPrototypePosition) \
/* ecma402 #sec-segment-iterator-prototype-index */ \
CPP(SegmentIteratorPrototypeIndex) \
/* ecma402 #sec-segment-iterator-prototype-next */ \
CPP(SegmentIteratorPrototypeNext) \
/* ES #sec-string.prototype.normalize */ \
......
......@@ -962,13 +962,13 @@ BUILTIN(SegmentIteratorPrototypePreceding) {
return *isolate->factory()->ToBoolean(success.FromJust());
}
// ecma402 #sec-segment-iterator-prototype-position
BUILTIN(SegmentIteratorPrototypePosition) {
const char* const method = "get %SegmentIteratorPrototype%.position";
// ecma402 #sec-segment-iterator-prototype-index
BUILTIN(SegmentIteratorPrototypeIndex) {
const char* const method = "get %SegmentIteratorPrototype%.index";
HandleScope scope(isolate);
CHECK_RECEIVER(JSSegmentIterator, segment_iterator, method);
return *JSSegmentIterator::Position(isolate, segment_iterator);
return *JSSegmentIterator::Index(isolate, segment_iterator);
}
BUILTIN(SegmenterConstructor) {
......
......@@ -68,7 +68,7 @@ MaybeHandle<JSSegmentIterator> JSSegmentIterator::Create(
Intl::SetTextToBreakIterator(isolate, text, break_iterator);
segment_iterator->set_unicode_string(unicode_string);
// 4. Let iterator.[[SegmentIteratorPosition]] be 0.
// 4. Let iterator.[[SegmentIteratorIndex]] be 0.
// step 4 is stored inside break_iterator.
// 5. Let iterator.[[SegmentIteratorBreakType]] be undefined.
......@@ -108,7 +108,7 @@ Handle<Object> JSSegmentIterator::BreakType() const {
return GetReadOnlyRoots().undefined_value_handle();
case JSSegmenter::Granularity::LINE:
if (rule_status >= UBRK_LINE_SOFT && rule_status < UBRK_LINE_SOFT_LIMIT) {
// soft line breaks, positions at which a line break is acceptable but
// soft line breaks, index at which a line break is acceptable but
// not required
return GetReadOnlyRoots().soft_string_handle();
}
......@@ -138,8 +138,8 @@ Handle<Object> JSSegmentIterator::BreakType() const {
}
}
// ecma402 #sec-segment-iterator-prototype-position
Handle<Object> JSSegmentIterator::Position(
// ecma402 #sec-segment-iterator-prototype-index
Handle<Object> JSSegmentIterator::Index(
Isolate* isolate, Handle<JSSegmentIterator> segment_iterator) {
icu::BreakIterator* icu_break_iterator =
segment_iterator->icu_break_iterator()->raw();
......@@ -153,25 +153,25 @@ MaybeHandle<JSReceiver> JSSegmentIterator::Next(
Factory* factory = isolate->factory();
icu::BreakIterator* icu_break_iterator =
segment_iterator->icu_break_iterator()->raw();
// 3. Let _previousPosition be iterator.[[SegmentIteratorPosition]].
// 3. Let _previousIndex be iterator.[[SegmentIteratorIndex]].
int32_t prev = icu_break_iterator->current();
// 4. Let done be AdvanceSegmentIterator(iterator, forwards).
int32_t position = icu_break_iterator->next();
int32_t index = icu_break_iterator->next();
segment_iterator->set_is_break_type_set(true);
if (position == icu::BreakIterator::DONE) {
if (index == icu::BreakIterator::DONE) {
// 5. If done is true, return CreateIterResultObject(undefined, true).
return factory->NewJSIteratorResult(isolate->factory()->undefined_value(),
true);
}
// 6. Let newPosition be iterator.[[SegmentIteratorPosition]].
Handle<Object> new_position = factory->NewNumberFromInt(position);
// 6. Let newIndex be iterator.[[SegmentIteratorIndex]].
Handle<Object> new_index = factory->NewNumberFromInt(index);
// 8. Let segment be the substring of string from previousPosition to
// newPosition, inclusive of previousPosition and exclusive of newPosition.
// 8. Let segment be the substring of string from previousIndex to
// newIndex, inclusive of previousIndex and exclusive of newIndex.
Handle<String> segment;
ASSIGN_RETURN_ON_EXCEPTION(
isolate, segment, segment_iterator->GetSegment(isolate, prev, position),
JSReceiver);
ASSIGN_RETURN_ON_EXCEPTION(isolate, segment,
segment_iterator->GetSegment(isolate, prev, index),
JSReceiver);
// 9. Let breakType be iterator.[[SegmentIteratorBreakType]].
Handle<Object> break_type = segment_iterator->BreakType();
......@@ -190,10 +190,9 @@ MaybeHandle<JSReceiver> JSSegmentIterator::Next(
kDontThrow)
.FromJust());
// 13. Perform ! CreateDataProperty(result, "position", newPosition).
CHECK(JSReceiver::CreateDataProperty(isolate, result,
factory->position_string(), new_position,
kDontThrow)
// 13. Perform ! CreateDataProperty(result, "index", newIndex).
CHECK(JSReceiver::CreateDataProperty(isolate, result, factory->index_string(),
new_index, kDontThrow)
.FromJust());
// 14. Return CreateIterResultObject(result, false).
......
......@@ -48,8 +48,8 @@ class JSSegmentIterator : public JSObject {
Isolate* isolate, Handle<JSSegmentIterator> segment_iterator_holder,
Handle<Object> from);
// ecma402 #sec-segment-iterator-prototype-position
static Handle<Object> Position(
// ecma402 #sec-segment-iterator-prototype-index
static Handle<Object> Index(
Isolate* isolate, Handle<JSSegmentIterator> segment_iterator_holder);
Handle<String> GranularityAsString() const;
......
......@@ -28,11 +28,11 @@ for (const text of [
let segments = [];
while (!iter.following()) {
assertEquals(undefined, iter.breakType);
assertTrue(iter.position >= 0);
assertTrue(iter.position <= text.length);
assertTrue(iter.position > prev);
segments.push(text.substring(prev, iter.position));
prev = iter.position;
assertTrue(iter.index >= 0);
assertTrue(iter.index <= text.length);
assertTrue(iter.index > prev);
segments.push(text.substring(prev, iter.index));
prev = iter.index;
}
assertEquals(text, segments.join(""));
}
......@@ -37,8 +37,8 @@ for (const text of [
// manually advance the iter.
assertFalse(iter.following());
assertEquals(iter.breakType, v.breakType);
assertEquals(text.substring(prev, iter.position), v.segment);
prev = iter.position;
assertEquals(text.substring(prev, iter.index), v.segment);
prev = iter.index;
}
assertTrue(iter.following());
assertEquals(text, segments.join(''));
......
......@@ -32,9 +32,9 @@ for (const text of [
assertEquals("string", typeof v.segment);
assertTrue(v.segment.length > 0);
segments.push(v.segment);
assertEquals("number", typeof v.position);
assertTrue(oldPos < v.position);
oldPos = v.position;
assertEquals("number", typeof v.index);
assertTrue(oldPos < v.index);
oldPos = v.index;
}
assertEquals(text, segments.join(''));
}
......@@ -28,17 +28,17 @@ for (const text of [
let segments = [];
iter.preceding(prev)
assertEquals(undefined, iter.breakType)
assertTrue(iter.position >= 0);
assertTrue(iter.position < prev);
segments.push(text.substring(iter.position, prev));
prev = iter.position;
assertTrue(iter.index >= 0);
assertTrue(iter.index < prev);
segments.push(text.substring(iter.index, prev));
prev = iter.index;
while (!iter.preceding()) {
assertEquals(undefined, iter.breakType);
assertTrue(iter.position >= 0);
assertTrue(iter.position <= text.length);
assertTrue(iter.position < prev);
segments.push(text.substring(iter.position, prev));
prev = iter.position;
assertTrue(iter.index >= 0);
assertTrue(iter.index <= text.length);
assertTrue(iter.index < prev);
segments.push(text.substring(iter.index, prev));
prev = iter.index;
}
assertEquals(text, segments.reverse().join(""));
}
......@@ -25,5 +25,5 @@ for (const text of [
]) {
const iter = seg.segment(text);
assertEquals(undefined, iter.breakType);
assertEquals(0, iter.position);
assertEquals(0, iter.index);
}
......@@ -48,7 +48,7 @@ function checkGetterProperty(prototype, property) {
}
// Test the descriptor is correct for properties.
checkGetterProperty(prototype, 'position');
checkGetterProperty(prototype, 'index');
checkGetterProperty(prototype, 'breakType');
// Test the SegmentIteratorPrototype methods are called with same
......@@ -88,4 +88,4 @@ checkProperty(nextReturn, 'done');
checkProperty(nextReturn, 'value');
checkProperty(nextReturn.value, 'segment');
checkProperty(nextReturn.value, 'breakType');
checkProperty(nextReturn.value, 'position');
checkProperty(nextReturn.value, 'index');
......@@ -8,4 +8,4 @@ const segmenter = new Intl.Segmenter();
const text = "Hello World, Test 123! Foo Bar. How are you?";
const iter = segmenter.segment(text);
assertEquals(0, iter.position);
assertEquals(0, iter.index);
......@@ -9,7 +9,7 @@ for (const granularity of ["grapheme", "word", "sentence", "line"]) {
const segmenter = new Intl.Segmenter("en", { granularity });
const iter = segmenter.segment(text);
assertEquals("number", typeof iter.position);
assertEquals(0, iter.position);
assertEquals("number", typeof iter.index);
assertEquals(0, iter.index);
assertEquals(undefined, iter.breakType);
}
......@@ -28,11 +28,11 @@ for (const text of [
let segments = [];
while (!iter.following()) {
assertTrue(["soft", "hard"].includes(iter.breakType), iter.breakType);
assertTrue(iter.position >= 0);
assertTrue(iter.position <= text.length);
assertTrue(iter.position > prev);
segments.push(text.substring(prev, iter.position));
prev = iter.position;
assertTrue(iter.index >= 0);
assertTrue(iter.index <= text.length);
assertTrue(iter.index > prev);
segments.push(text.substring(prev, iter.index));
prev = iter.index;
}
assertEquals(text, segments.join(""));
}
......@@ -37,8 +37,8 @@ for (const text of [
// manually advance the iter.
assertFalse(iter.following());
assertEquals(iter.breakType, v.breakType);
assertEquals(text.substring(prev, iter.position), v.segment);
prev = iter.position;
assertEquals(text.substring(prev, iter.index), v.segment);
prev = iter.index;
}
assertTrue(iter.following());
assertEquals(text, segments.join(''));
......
......@@ -32,9 +32,9 @@ for (const text of [
assertEquals("string", typeof v.segment);
assertTrue(v.segment.length > 0);
segments.push(v.segment);
assertEquals("number", typeof v.position);
assertTrue(oldPos < v.position);
oldPos = v.position;
assertEquals("number", typeof v.index);
assertTrue(oldPos < v.index);
oldPos = v.index;
}
assertEquals(text, segments.join(''));
}
......@@ -28,17 +28,17 @@ for (const text of [
let segments = [];
iter.preceding(prev)
assertTrue(["soft", "hard"].includes(iter.breakType), iter.breakType);
assertTrue(iter.position >= 0);
assertTrue(iter.position < prev);
segments.push(text.substring(iter.position, prev));
prev = iter.position;
assertTrue(iter.index >= 0);
assertTrue(iter.index < prev);
segments.push(text.substring(iter.index, prev));
prev = iter.index;
while (!iter.preceding()) {
assertTrue(["soft", "hard"].includes(iter.breakType), iter.breakType);
assertTrue(iter.position >= 0);
assertTrue(iter.position <= text.length);
assertTrue(iter.position < prev);
segments.push(text.substring(iter.position, prev));
prev = iter.position;
assertTrue(iter.index >= 0);
assertTrue(iter.index <= text.length);
assertTrue(iter.index < prev);
segments.push(text.substring(iter.index, prev));
prev = iter.index;
}
assertEquals(text, segments.reverse().join(""));
}
......@@ -25,5 +25,5 @@ for (const text of [
]) {
const iter = seg.segment(text);
assertEquals(undefined, iter.breakType);
assertEquals(0, iter.position);
assertEquals(0, iter.index);
}
......@@ -28,11 +28,11 @@ for (const text of [
let segments = [];
while (!iter.following()) {
assertTrue(["sep", "term"].includes(iter.breakType), iter.breakType);
assertTrue(iter.position >= 0);
assertTrue(iter.position <= text.length);
assertTrue(iter.position > prev);
segments.push(text.substring(prev, iter.position));
prev = iter.position;
assertTrue(iter.index >= 0);
assertTrue(iter.index <= text.length);
assertTrue(iter.index > prev);
segments.push(text.substring(prev, iter.index));
prev = iter.index;
}
assertEquals(text, segments.join(""));
}
......@@ -37,8 +37,8 @@ for (const text of [
// manually advance the iter.
assertFalse(iter.following());
assertEquals(iter.breakType, v.breakType);
assertEquals(text.substring(prev, iter.position), v.segment);
prev = iter.position;
assertEquals(text.substring(prev, iter.index), v.segment);
prev = iter.index;
}
assertTrue(iter.following());
assertEquals(text, segments.join(''));
......
......@@ -32,9 +32,9 @@ for (const text of [
assertEquals("string", typeof v.segment);
assertTrue(v.segment.length > 0);
segments.push(v.segment);
assertEquals("number", typeof v.position);
assertTrue(oldPos < v.position);
oldPos = v.position;
assertEquals("number", typeof v.index);
assertTrue(oldPos < v.index);
oldPos = v.index;
}
assertEquals(text, segments.join(''));
}
......@@ -28,17 +28,17 @@ for (const text of [
let segments = [];
iter.preceding(prev);
assertTrue(["sep", "term"].includes(iter.breakType), iter.breakType);
assertTrue(iter.position >= 0);
assertTrue(iter.position < prev);
segments.push(text.substring(iter.position, prev));
prev = iter.position;
assertTrue(iter.index >= 0);
assertTrue(iter.index < prev);
segments.push(text.substring(iter.index, prev));
prev = iter.index;
while (!iter.preceding()) {
assertTrue(["sep", "term"].includes(iter.breakType), iter.breakType);
assertTrue(iter.position >= 0);
assertTrue(iter.position <= text.length);
assertTrue(iter.position < prev);
segments.push(text.substring(iter.position, prev));
prev = iter.position;
assertTrue(iter.index >= 0);
assertTrue(iter.index <= text.length);
assertTrue(iter.index < prev);
segments.push(text.substring(iter.index, prev));
prev = iter.index;
}
assertEquals(text, segments.reverse().join(""));
}
......@@ -25,5 +25,5 @@ for (const text of [
]) {
const iter = seg.segment(text);
assertEquals(undefined, iter.breakType);
assertEquals(0, iter.position);
assertEquals(0, iter.index);
}
......@@ -28,11 +28,11 @@ for (const text of [
let segments = [];
while (!iter.following()) {
assertTrue(["word", "none"].includes(iter.breakType), iter.breakType);
assertTrue(iter.position >= 0);
assertTrue(iter.position <= text.length);
assertTrue(iter.position > prev);
segments.push(text.substring(prev, iter.position));
prev = iter.position;
assertTrue(iter.index >= 0);
assertTrue(iter.index <= text.length);
assertTrue(iter.index > prev);
segments.push(text.substring(prev, iter.index));
prev = iter.index;
}
assertEquals(text, segments.join(""));
}
......@@ -37,8 +37,8 @@ for (const text of [
// manually advance the iter.
assertFalse(iter.following());
assertEquals(iter.breakType, v.breakType);
assertEquals(text.substring(prev, iter.position), v.segment);
prev = iter.position;
assertEquals(text.substring(prev, iter.index), v.segment);
prev = iter.index;
}
assertTrue(iter.following());
assertEquals(text, segments.join(''));
......
......@@ -32,9 +32,9 @@ for (const text of [
assertEquals("string", typeof v.segment);
assertTrue(v.segment.length > 0);
segments.push(v.segment);
assertEquals("number", typeof v.position);
assertTrue(oldPos < v.position);
oldPos = v.position;
assertEquals("number", typeof v.index);
assertTrue(oldPos < v.index);
oldPos = v.index;
}
assertEquals(text, segments.join(''));
}
......@@ -28,17 +28,17 @@ for (const text of [
let segments = [];
iter.preceding(prev);
assertTrue(["word", "none"].includes(iter.breakType), iter.breakType);
assertTrue(iter.position >= 0);
assertTrue(iter.position < prev);
segments.push(text.substring(iter.position, prev));
prev = iter.position;
assertTrue(iter.index >= 0);
assertTrue(iter.index < prev);
segments.push(text.substring(iter.index, prev));
prev = iter.index;
while (!iter.preceding()) {
assertTrue(["word", "none"].includes(iter.breakType), iter.breakType);
assertTrue(iter.position >= 0);
assertTrue(iter.position <= text.length);
assertTrue(iter.position < prev);
segments.push(text.substring(iter.position, prev));
prev = iter.position;
assertTrue(iter.index >= 0);
assertTrue(iter.index <= text.length);
assertTrue(iter.index < prev);
segments.push(text.substring(iter.index, prev));
prev = iter.index;
}
assertEquals(text, segments.reverse().join(""));
}
......@@ -25,5 +25,5 @@ for (const text of [
]) {
const iter = seg.segment(text);
assertEquals(undefined, iter.breakType);
assertEquals(0, iter.position);
assertEquals(0, iter.index);
}
......@@ -661,34 +661,6 @@
'language/expressions/await/for-await-of-interleaved': ['--harmony-await-optimization'],
'language/expressions/await/async-await-interleaved': ['--harmony-await-optimization'],
# https://bugs.chromium.org/p/v8/issues/detail?id=8588
'intl402/Segmenter/iterator/following': [FAIL],
'intl402/Segmenter/iterator/granularity': [FAIL],
'intl402/Segmenter/iterator/position': [FAIL],
'intl402/Segmenter/iterator/preceding': [FAIL],
'intl402/Segmenter/iterator/prototype': [FAIL],
'intl402/Segmenter/prototype/segment/segment-grapheme': [FAIL],
'intl402/Segmenter/prototype/segment/segment-grapheme-following': [FAIL],
'intl402/Segmenter/prototype/segment/segment-grapheme-iterable': [FAIL],
'intl402/Segmenter/prototype/segment/segment-grapheme-next': [FAIL],
'intl402/Segmenter/prototype/segment/segment-grapheme-preceding': [FAIL],
'intl402/Segmenter/prototype/segment/segment-line': [FAIL],
'intl402/Segmenter/prototype/segment/segment-line-following': [FAIL],
'intl402/Segmenter/prototype/segment/segment-line-iterable': [FAIL],
'intl402/Segmenter/prototype/segment/segment-line-next': [FAIL],
'intl402/Segmenter/prototype/segment/segment-line-preceding': [FAIL],
'intl402/Segmenter/prototype/segment/segment-sentence': [FAIL],
'intl402/Segmenter/prototype/segment/segment-sentence-following': [FAIL],
'intl402/Segmenter/prototype/segment/segment-sentence-iterable': [FAIL],
'intl402/Segmenter/prototype/segment/segment-sentence-next': [FAIL],
'intl402/Segmenter/prototype/segment/segment-sentence-preceding': [FAIL],
'intl402/Segmenter/prototype/segment/segment-tostring': [FAIL],
'intl402/Segmenter/prototype/segment/segment-word': [FAIL],
'intl402/Segmenter/prototype/segment/segment-word-following': [FAIL],
'intl402/Segmenter/prototype/segment/segment-word-iterable': [FAIL],
'intl402/Segmenter/prototype/segment/segment-word-next': [FAIL],
'intl402/Segmenter/prototype/segment/segment-word-preceding': [FAIL],
######################## NEEDS INVESTIGATION ###########################
# These test failures are specific to the intl402 suite and need investigation
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment