diff --git a/implementation-contributed/v8/intl/intl.status b/implementation-contributed/v8/intl/intl.status index 42807597a0..799c627c1b 100644 --- a/implementation-contributed/v8/intl/intl.status +++ b/implementation-contributed/v8/intl/intl.status @@ -32,10 +32,33 @@ # https://bugs.chromium.org/p/v8/issues/detail?id=6891 'segmenter/segment': [FAIL], + 'segmenter/segment-grapheme': [FAIL], + 'segmenter/segment-grapheme-following': [FAIL], + 'segmenter/segment-grapheme-iterable': [FAIL], + 'segmenter/segment-grapheme-next': [FAIL], + 'segmenter/segment-grapheme-preceding': [FAIL], 'segmenter/segment-iterator': [FAIL], + 'segmenter/segment-iterator-breakType': [FAIL], 'segmenter/segment-iterator-following': [FAIL], 'segmenter/segment-iterator-next': [FAIL], + 'segmenter/segment-iterator-position': [FAIL], 'segmenter/segment-iterator-preceding': [FAIL], + 'segmenter/segment-line': [FAIL], + 'segmenter/segment-line-following': [FAIL], + 'segmenter/segment-line-following-modes': [FAIL], + 'segmenter/segment-line-iterable': [FAIL], + 'segmenter/segment-line-next': [FAIL], + 'segmenter/segment-line-preceding': [FAIL], + 'segmenter/segment-sentence': [FAIL], + 'segmenter/segment-sentence-following': [FAIL], + 'segmenter/segment-sentence-iterable': [FAIL], + 'segmenter/segment-sentence-next': [FAIL], + 'segmenter/segment-sentence-preceding': [FAIL], + 'segmenter/segment-word': [FAIL], + 'segmenter/segment-word-following': [FAIL], + 'segmenter/segment-word-iterable': [FAIL], + 'segmenter/segment-word-next': [FAIL], + 'segmenter/segment-word-preceding': [FAIL], }], # ALWAYS ['variant == no_wasm_traps', { diff --git a/implementation-contributed/v8/intl/list-format/constructor.js b/implementation-contributed/v8/intl/list-format/constructor.js index 33a85fd79f..2ef2c5088b 100644 --- a/implementation-contributed/v8/intl/list-format/constructor.js +++ b/implementation-contributed/v8/intl/list-format/constructor.js @@ -54,8 +54,7 @@ assertDoesNotThrow( assertDoesNotThrow( () => new Intl.ListFormat(['sr'], {style: 'short'})); -assertDoesNotThrow( - () => new Intl.ListFormat(['sr'], {style: 'narrow'})); +assertThrows(() => new Intl.ListFormat(['sr'], {style: 'narrow'}), RangeError); assertThrows( () => new Intl.ListFormat(['sr'], {style: 'giant'}), @@ -67,8 +66,9 @@ assertDoesNotThrow( assertDoesNotThrow( () => new Intl.ListFormat(['sr'], {type: 'conjunction', style: 'short'})); -assertDoesNotThrow( - () => new Intl.ListFormat(['sr'], {type: 'conjunction', style: 'narrow'})); +assertThrows( + () => new Intl.ListFormat(['sr'], {type: 'conjunction', style: 'narrow'}), + RangeError); assertDoesNotThrow( () => new Intl.ListFormat(['sr'], {type: 'disjunction', style: 'long'})); @@ -76,8 +76,9 @@ assertDoesNotThrow( assertDoesNotThrow( () => new Intl.ListFormat(['sr'], {type: 'disjunction', style: 'short'})); -assertDoesNotThrow( - () => new Intl.ListFormat(['sr'], {type: 'disjunction', style: 'narrow'})); +assertThrows( + () => new Intl.ListFormat(['sr'], {type: 'disjunction', style: 'narrow'}), + RangeError); assertDoesNotThrow( () => new Intl.ListFormat(['sr'], {type: 'unit', style: 'long'})); diff --git a/implementation-contributed/v8/intl/list-format/format-en.js b/implementation-contributed/v8/intl/list-format/format-en.js index 21eb99d06d..d628537990 100644 --- a/implementation-contributed/v8/intl/list-format/format-en.js +++ b/implementation-contributed/v8/intl/list-format/format-en.js @@ -14,13 +14,14 @@ let enLongConjunction = new Intl.ListFormat( ["en"], {style: "long", type: 'conjunction'}); assertEquals('', enLongConjunction.format()); - assertEquals('', enLongConjunction.format([])); +assertEquals('', enLongConjunction.format([])); assertEquals('a', enLongConjunction.format(['a'])); assertEquals('b', enLongConjunction.format(['b'])); assertEquals('a and b', enLongConjunction.format(['a', 'b'])); assertEquals('a, b, and c', enLongConjunction.format(['a', 'b', 'c'])); assertEquals('a, b, c, and d', enLongConjunction.format(['a', 'b', 'c', 'd'])); -assertEquals('a, b, c, d, and and', enLongConjunction.format(['a', 'b', 'c', 'd', 'and'])); +assertEquals('a, b, c, d, and and', + enLongConjunction.format(['a', 'b', 'c', 'd', 'and'])); let enLongDisjunction = new Intl.ListFormat( ["en"], {style: "long", type: 'disjunction'}); @@ -32,7 +33,8 @@ assertEquals('b', enLongDisjunction.format(['b'])); assertEquals('a or b', enLongDisjunction.format(['a', 'b'])); assertEquals('a, b, or c', enLongDisjunction.format(['a', 'b', 'c'])); assertEquals('a, b, c, or d', enLongDisjunction.format(['a', 'b', 'c', 'd'])); -assertEquals('a, b, c, d, or or', enLongDisjunction.format(['a', 'b', 'c', 'd', 'or'])); +assertEquals('a, b, c, d, or or', + enLongDisjunction.format(['a', 'b', 'c', 'd', 'or'])); let enLongUnit = new Intl.ListFormat( ["en"], {style: "long", type: 'unit'}); @@ -56,7 +58,8 @@ assertEquals('b', enShortConjunction.format(['b'])); assertEquals('a and b', enShortConjunction.format(['a', 'b'])); assertEquals('a, b, and c', enShortConjunction.format(['a', 'b', 'c'])); assertEquals('a, b, c, and d', enShortConjunction.format(['a', 'b', 'c', 'd'])); -assertEquals('a, b, c, d, and and', enShortConjunction.format(['a', 'b', 'c', 'd', 'and'])); +assertEquals('a, b, c, d, and and', + enShortConjunction.format(['a', 'b', 'c', 'd', 'and'])); let enShortDisjunction = new Intl.ListFormat( ["en"], {style: "short", type: 'disjunction'}); @@ -82,30 +85,6 @@ assertEquals('a, b, c', enShortUnit.format(['a', 'b', 'c'])); assertEquals('a, b, c, d', enShortUnit.format(['a', 'b', 'c', 'd'])); assertEquals('a, b, c, d, or', enShortUnit.format(['a', 'b', 'c', 'd', 'or'])); -let enNarrowConjunction = new Intl.ListFormat( - ["en"], {style: "narrow", type: 'conjunction'}); - -assertEquals('', enNarrowConjunction.format()); -assertEquals('', enNarrowConjunction.format([])); -assertEquals('a', enNarrowConjunction.format(['a'])); -assertEquals('b', enNarrowConjunction.format(['b'])); -assertEquals('a and b', enNarrowConjunction.format(['a', 'b'])); -assertEquals('a, b, and c', enNarrowConjunction.format(['a', 'b', 'c'])); -assertEquals('a, b, c, and d', enNarrowConjunction.format(['a', 'b', 'c', 'd'])); -assertEquals('a, b, c, d, and and', enNarrowConjunction.format(['a', 'b', 'c', 'd', 'and'])); - -let enNarrowDisjunction = new Intl.ListFormat( - ["en"], {style: "narrow", type: 'disjunction'}); - -assertEquals('', enNarrowDisjunction.format()); -assertEquals('', enNarrowDisjunction.format([])); -assertEquals('a', enNarrowDisjunction.format(['a'])); -assertEquals('b', enNarrowDisjunction.format(['b'])); -assertEquals('a or b', enNarrowDisjunction.format(['a', 'b'])); -assertEquals('a, b, or c', enNarrowDisjunction.format(['a', 'b', 'c'])); -assertEquals('a, b, c, or d', enNarrowDisjunction.format(['a', 'b', 'c', 'd'])); -assertEquals('a, b, c, d, or or', enNarrowDisjunction.format(['a', 'b', 'c', 'd', 'or'])); - let enNarrowUnit = new Intl.ListFormat( ["en"], {style: "narrow", type: 'unit'}); diff --git a/implementation-contributed/v8/intl/list-format/format-to-parts.js b/implementation-contributed/v8/intl/list-format/format-to-parts.js index 83473b6d0b..64eac823ba 100644 --- a/implementation-contributed/v8/intl/list-format/format-to-parts.js +++ b/implementation-contributed/v8/intl/list-format/format-to-parts.js @@ -77,16 +77,22 @@ testFormatter(new Intl.ListFormat()); testFormatter(new Intl.ListFormat(["en"])); testFormatter(new Intl.ListFormat(["en"], {style: 'long'})); testFormatter(new Intl.ListFormat(["en"], {style: 'short'})); -testFormatter(new Intl.ListFormat(["en"], {style: 'narrow'})); +assertThrows(() => new Intl.ListFormat(["en"], {style: 'narrow'}), RangeError); testFormatter(new Intl.ListFormat(["en"], {type: 'conjunction'})); testFormatter(new Intl.ListFormat(["en"], {type: 'disjunction'})); testFormatter(new Intl.ListFormat(["en"], {type: 'unit'})); testFormatter(new Intl.ListFormat(["en"], {style: 'long', type: 'conjunction'})); -testFormatter(new Intl.ListFormat(["en"], {style: 'short', type: 'conjunction'})); -testFormatter(new Intl.ListFormat(["en"], {style: 'narrow', type: 'conjunction'})); +testFormatter( + new Intl.ListFormat(["en"], {style: 'short', type: 'conjunction'})); +assertThrows( + () => new Intl.ListFormat( + ["en"], {style: 'narrow', type: 'conjunction'}), RangeError); testFormatter(new Intl.ListFormat(["en"], {style: 'long', type: 'disjunction'})); -testFormatter(new Intl.ListFormat(["en"], {style: 'short', type: 'disjunction'})); -testFormatter(new Intl.ListFormat(["en"], {style: 'narrow', type: 'disjunction'})); +testFormatter( + new Intl.ListFormat(["en"], {style: 'short', type: 'disjunction'})); +assertThrows( + () => new Intl.ListFormat( + ["en"], {style: 'narrow', type: 'disjunction'}), RangeError); testFormatter(new Intl.ListFormat(["en"], {style: 'long', type: 'unit'})); testFormatter(new Intl.ListFormat(["en"], {style: 'short', type: 'unit'})); testFormatter(new Intl.ListFormat(["en"], {style: 'narrow', type: 'unit'})); diff --git a/implementation-contributed/v8/intl/list-format/format.js b/implementation-contributed/v8/intl/list-format/format.js index 677cb22496..fef05c38e0 100644 --- a/implementation-contributed/v8/intl/list-format/format.js +++ b/implementation-contributed/v8/intl/list-format/format.js @@ -48,16 +48,19 @@ testFormatter(new Intl.ListFormat()); testFormatter(new Intl.ListFormat(["en"])); testFormatter(new Intl.ListFormat(["en"], {style: 'long'})); testFormatter(new Intl.ListFormat(["en"], {style: 'short'})); -testFormatter(new Intl.ListFormat(["en"], {style: 'narrow'})); +assertThrows(() => new Intl.ListFormat( + ["en"], {style: 'narrow'}), RangeError); testFormatter(new Intl.ListFormat(["en"], {type: 'conjunction'})); testFormatter(new Intl.ListFormat(["en"], {type: 'disjunction'})); testFormatter(new Intl.ListFormat(["en"], {type: 'unit'})); testFormatter(new Intl.ListFormat(["en"], {style: 'long', type: 'conjunction'})); testFormatter(new Intl.ListFormat(["en"], {style: 'short', type: 'conjunction'})); -testFormatter(new Intl.ListFormat(["en"], {style: 'narrow', type: 'conjunction'})); +assertThrows(() => new Intl.ListFormat( + ["en"], {style: 'narrow', type: 'conjunction'}), RangeError); testFormatter(new Intl.ListFormat(["en"], {style: 'long', type: 'disjunction'})); testFormatter(new Intl.ListFormat(["en"], {style: 'short', type: 'disjunction'})); -testFormatter(new Intl.ListFormat(["en"], {style: 'narrow', type: 'disjunction'})); +assertThrows(() => new Intl.ListFormat( + ["en"], {style: 'narrow', type: 'disjunction'}), RangeError); testFormatter(new Intl.ListFormat(["en"], {style: 'long', type: 'unit'})); testFormatter(new Intl.ListFormat(["en"], {style: 'short', type: 'unit'})); testFormatter(new Intl.ListFormat(["en"], {style: 'narrow', type: 'unit'})); diff --git a/implementation-contributed/v8/intl/list-format/resolved-options.js b/implementation-contributed/v8/intl/list-format/resolved-options.js index 270eb33e45..cca85d2141 100644 --- a/implementation-contributed/v8/intl/list-format/resolved-options.js +++ b/implementation-contributed/v8/intl/list-format/resolved-options.js @@ -21,16 +21,6 @@ assertEquals( (new Intl.ListFormat(['sr'], {style: 'short'})) .resolvedOptions().type); -assertEquals( - 'narrow', - (new Intl.ListFormat(['sr'], {style: 'narrow'})) - .resolvedOptions().style); - -assertEquals( - 'conjunction', - (new Intl.ListFormat(['sr'], {style: 'narrow'})) - .resolvedOptions().type); - assertEquals( 'long', (new Intl.ListFormat(['sr'], {style: 'long'})) @@ -71,6 +61,26 @@ assertEquals( (new Intl.ListFormat(['sr'], {type: 'unit'})) .resolvedOptions().style); +assertEquals( + 'conjunction', + (new Intl.ListFormat(['sr'], {style: 'long', type: 'conjunction'})) + .resolvedOptions().type); + +assertEquals( + 'long', + (new Intl.ListFormat(['sr'], {style: 'long', type: 'conjunction'})) + .resolvedOptions().style); + +assertEquals( + 'conjunction', + (new Intl.ListFormat(['sr'], {style: 'short', type: 'conjunction'})) + .resolvedOptions().type); + +assertEquals( + 'short', + (new Intl.ListFormat(['sr'], {style: 'short', type: 'conjunction'})) + .resolvedOptions().style); + assertEquals( 'disjunction', (new Intl.ListFormat(['sr'], {style: 'long', type: 'disjunction'})) @@ -91,16 +101,6 @@ assertEquals( (new Intl.ListFormat(['sr'], {style: 'short', type: 'disjunction'})) .resolvedOptions().style); -assertEquals( - 'disjunction', - (new Intl.ListFormat(['sr'], {style: 'narrow', type: 'disjunction'})) - .resolvedOptions().type); - -assertEquals( - 'narrow', - (new Intl.ListFormat(['sr'], {style: 'narrow', type: 'disjunction'})) - .resolvedOptions().style); - assertEquals( 'unit', (new Intl.ListFormat(['sr'], {style: 'long', type: 'unit'})) diff --git a/implementation-contributed/v8/intl/segmenter/segment-grapheme-following.js b/implementation-contributed/v8/intl/segmenter/segment-grapheme-following.js new file mode 100644 index 0000000000..0a824c0fb3 --- /dev/null +++ b/implementation-contributed/v8/intl/segmenter/segment-grapheme-following.js @@ -0,0 +1,38 @@ +// Copyright 2018 the V8 project authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Flags: --harmony-intl-segmenter + +const seg = new Intl.Segmenter([], {granularity: "grapheme"}) +for (const text of [ + "Hello world!", // English + " Hello world! ", // English with space before/after + " Hello world? Foo bar!", // English + "Jedovatou mambu objevila žena v zahrádkářské kolonii.", // Czech + "Việt Nam: Nhất thể hóa sẽ khác Trung Quốc?", // Vietnamese + "Σοβαρές ενστάσεις Κομισιόν για τον προϋπολογισμό της Ιταλίας", // Greek + "Решение Индии о покупке российских С-400 расценили как вызов США", // Russian + "הרופא שהציל נשים והנערה ששועבדה ע", // Hebrew, + "ترامب للملك سلمان: أنا جاد للغاية.. عليك دفع المزيد", // Arabic + "भारत की एस 400 मिसाइल के मुकाबले पाक की थाड, जानें कौन कितना ताकतवर", // Hindi + "ரெட் அலர்ட் எச்சரிக்கை; புதுச்சேரியில் நாளை அரசு விடுமுறை!", // Tamil + "'ఉత్తర్వులు అందే వరకు ఓటర్ల తుది జాబితాను వెబ్‌సైట్లో పెట్టవద్దు'", // Telugu + "台北》抹黑柯P失敗?朱學恒酸:姚文智氣pupu嗆大老闆", // Chinese + "วัดไทรตีระฆังเบาลงช่วงเข้าพรรษา เจ้าอาวาสเผยคนร้องเรียนรับผลกรรมแล้ว", // Thai + "九州北部の一部が暴風域に入りました(日直予報士 2018年10月06日) - 日本気象協会 tenki.jp", // Japanese + "법원 “다스 지분 처분권·수익권 모두 MB가 보유”", // Korean + ]) { + const iter = seg.segment(text); + let prev = 0; + 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; + } + assertEquals(text, segments.join("")); +} diff --git a/implementation-contributed/v8/intl/segmenter/segment-grapheme-iterable.js b/implementation-contributed/v8/intl/segmenter/segment-grapheme-iterable.js new file mode 100644 index 0000000000..50cf5db57f --- /dev/null +++ b/implementation-contributed/v8/intl/segmenter/segment-grapheme-iterable.js @@ -0,0 +1,45 @@ +// Copyright 2018 the V8 project authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Flags: --harmony-intl-segmenter + +const seg = new Intl.Segmenter([], {granularity: "grapheme"}) +for (const text of [ + "Hello world!", // English + " Hello world! ", // English with space before/after + " Hello world? Foo bar!", // English + "Jedovatou mambu objevila žena v zahrádkářské kolonii.", // Czech + "Việt Nam: Nhất thể hóa sẽ khác Trung Quốc?", // Vietnamese + "Σοβαρές ενστάσεις Κομισιόν για τον προϋπολογισμό της Ιταλίας", // Greek + "Решение Индии о покупке российских С-400 расценили как вызов США", // Russian + "הרופא שהציל נשים והנערה ששועבדה ע", // Hebrew, + "ترامب للملك سلمان: أنا جاد للغاية.. عليك دفع المزيد", // Arabic + "भारत की एस 400 मिसाइल के मुकाबले पाक की थाड, जानें कौन कितना ताकतवर", // Hindi + "ரெட் அலர்ட் எச்சரிக்கை; புதுச்சேரியில் நாளை அரசு விடுமுறை!", // Tamil + "'ఉత్తర్వులు అందే వరకు ఓటర్ల తుది జాబితాను వెబ్‌సైట్లో పెట్టవద్దు'", // Telugu + "台北》抹黑柯P失敗?朱學恒酸:姚文智氣pupu嗆大老闆", // Chinese + "วัดไทรตีระฆังเบาลงช่วงเข้าพรรษา เจ้าอาวาสเผยคนร้องเรียนรับผลกรรมแล้ว", // Thai + "九州北部の一部が暴風域に入りました(日直予報士 2018年10月06日) - 日本気象協会 tenki.jp", // Japanese + "법원 “다스 지분 처분권·수익권 모두 MB가 보유”", // Korean + ]) { + let segments = []; + // Create another %SegmentIterator% to compare with result from the one that + // created in the for of loop. + let iter = seg.segment(text); + let prev = 0; + for (const v of seg.segment(text)) { + assertEquals(undefined, v.breakType); + assertEquals("string", typeof v.segment); + assertTrue(v.segment.length > 0); + segments.push(v.segment); + + // manually advance the iter. + assertFalse(iter.following()); + assertEquals(iter.breakType, v.breakType); + assertEquals(text.substring(prev, iter.position), v.segment); + prev = iter.position; + } + assertTrue(iter.following()); + assertEquals(text, segments.join('')); +} diff --git a/implementation-contributed/v8/intl/segmenter/segment-grapheme-next.js b/implementation-contributed/v8/intl/segmenter/segment-grapheme-next.js new file mode 100644 index 0000000000..f9adc27c13 --- /dev/null +++ b/implementation-contributed/v8/intl/segmenter/segment-grapheme-next.js @@ -0,0 +1,36 @@ +// Copyright 2018 the V8 project authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Flags: --harmony-intl-segmenter + +const seg = new Intl.Segmenter([], {granularity: "grapheme"}) +for (const text of [ + "Hello world!", // English + " Hello world! ", // English with space before/after + " Hello world? Foo bar!", // English + "Jedovatou mambu objevila žena v zahrádkářské kolonii.", // Czech + "Việt Nam: Nhất thể hóa sẽ khác Trung Quốc?", // Vietnamese + "Σοβαρές ενστάσεις Κομισιόν για τον προϋπολογισμό της Ιταλίας", // Greek + "Решение Индии о покупке российских С-400 расценили как вызов США", // Russian + "הרופא שהציל נשים והנערה ששועבדה ע", // Hebrew, + "ترامب للملك سلمان: أنا جاد للغاية.. عليك دفع المزيد", // Arabic + "भारत की एस 400 मिसाइल के मुकाबले पाक की थाड, जानें कौन कितना ताकतवर", // Hindi + "ரெட் அலர்ட் எச்சரிக்கை; புதுச்சேரியில் நாளை அரசு விடுமுறை!", // Tamil + "'ఉత్తర్వులు అందే వరకు ఓటర్ల తుది జాబితాను వెబ్‌సైట్లో పెట్టవద్దు'", // Telugu + "台北》抹黑柯P失敗?朱學恒酸:姚文智氣pupu嗆大老闆", // Chinese + "วัดไทรตีระฆังเบาลงช่วงเข้าพรรษา เจ้าอาวาสเผยคนร้องเรียนรับผลกรรมแล้ว", // Thai + "九州北部の一部が暴風域に入りました(日直予報士 2018年10月06日) - 日本気象協会 tenki.jp", // Japanese + "법원 “다스 지분 처분권·수익권 모두 MB가 보유”", // Korean + ]) { + const iter = seg.segment(text); + let segments = []; + for (let result = iter.next(); !result.done; result = iter.next()) { + const v = result.value; + assertEquals(undefined, v.breakType); + assertEquals("string", typeof v.segment); + assertTrue(v.segment.length > 0); + segments.push(v.segment); + } + assertEquals(text, segments.join('')); +} diff --git a/implementation-contributed/v8/intl/segmenter/segment-grapheme-preceding.js b/implementation-contributed/v8/intl/segmenter/segment-grapheme-preceding.js new file mode 100644 index 0000000000..0031c22d2d --- /dev/null +++ b/implementation-contributed/v8/intl/segmenter/segment-grapheme-preceding.js @@ -0,0 +1,44 @@ +// Copyright 2018 the V8 project authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Flags: --harmony-intl-segmenter + +const seg = new Intl.Segmenter([], {granularity: "grapheme"}) +for (const text of [ + "Hello world!", // English + " Hello world! ", // English with space before/after + " Hello world? Foo bar!", // English + "Jedovatou mambu objevila žena v zahrádkářské kolonii.", // Czech + "Việt Nam: Nhất thể hóa sẽ khác Trung Quốc?", // Vietnamese + "Σοβαρές ενστάσεις Κομισιόν για τον προϋπολογισμό της Ιταλίας", // Greek + "Решение Индии о покупке российских С-400 расценили как вызов США", // Russian + "הרופא שהציל נשים והנערה ששועבדה ע", // Hebrew, + "ترامب للملك سلمان: أنا جاد للغاية.. عليك دفع المزيد", // Arabic + "भारत की एस 400 मिसाइल के मुकाबले पाक की थाड, जानें कौन कितना ताकतवर", // Hindi + "ரெட் அலர்ட் எச்சரிக்கை; புதுச்சேரியில் நாளை அரசு விடுமுறை!", // Tamil + "'ఉత్తర్వులు అందే వరకు ఓటర్ల తుది జాబితాను వెబ్‌సైట్లో పెట్టవద్దు'", // Telugu + "台北》抹黑柯P失敗?朱學恒酸:姚文智氣pupu嗆大老闆", // Chinese + "วัดไทรตีระฆังเบาลงช่วงเข้าพรรษา เจ้าอาวาสเผยคนร้องเรียนรับผลกรรมแล้ว", // Thai + "九州北部の一部が暴風域に入りました(日直予報士 2018年10月06日) - 日本気象協会 tenki.jp", // Japanese + "법원 “다스 지분 처분권·수익권 모두 MB가 보유”", // Korean + ]) { + const iter = seg.segment(text); + let prev = text.length; + 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; + 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; + } + assertEquals(text, segments.reverse().join("")); +} diff --git a/implementation-contributed/v8/intl/segmenter/segment-grapheme.js b/implementation-contributed/v8/intl/segmenter/segment-grapheme.js new file mode 100644 index 0000000000..6b7e6eaf10 --- /dev/null +++ b/implementation-contributed/v8/intl/segmenter/segment-grapheme.js @@ -0,0 +1,29 @@ +// Copyright 2018 the V8 project authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Flags: --harmony-intl-segmenter + +const seg = new Intl.Segmenter([], {granularity: "grapheme"}) +for (const text of [ + "Hello world!", // English + " Hello world! ", // English with space before/after + " Hello world? Foo bar!", // English + "Jedovatou mambu objevila žena v zahrádkářské kolonii.", // Czech + "Việt Nam: Nhất thể hóa sẽ khác Trung Quốc?", // Vietnamese + "Σοβαρές ενστάσεις Κομισιόν για τον προϋπολογισμό της Ιταλίας", // Greek + "Решение Индии о покупке российских С-400 расценили как вызов США", // Russian + "הרופא שהציל נשים והנערה ששועבדה ע", // Hebrew, + "ترامب للملك سلمان: أنا جاد للغاية.. عليك دفع المزيد", // Arabic + "भारत की एस 400 मिसाइल के मुकाबले पाक की थाड, जानें कौन कितना ताकतवर", // Hindi + "ரெட் அலர்ட் எச்சரிக்கை; புதுச்சேரியில் நாளை அரசு விடுமுறை!", // Tamil + "'ఉత్తర్వులు అందే వరకు ఓటర్ల తుది జాబితాను వెబ్‌సైట్లో పెట్టవద్దు'", // Telugu + "台北》抹黑柯P失敗?朱學恒酸:姚文智氣pupu嗆大老闆", // Chinese + "วัดไทรตีระฆังเบาลงช่วงเข้าพรรษา เจ้าอาวาสเผยคนร้องเรียนรับผลกรรมแล้ว", // Thai + "九州北部の一部が暴風域に入りました(日直予報士 2018年10月06日) - 日本気象協会 tenki.jp", // Japanese + "법원 “다스 지분 처분권·수익권 모두 MB가 보유”", // Korean + ]) { + const iter = seg.segment(text); + assertEquals(undefined, iter.breakType); + assertEquals(0, iter.position); +} diff --git a/implementation-contributed/v8/intl/segmenter/segment-iterator-breakType.js b/implementation-contributed/v8/intl/segmenter/segment-iterator-breakType.js new file mode 100644 index 0000000000..ea5f523519 --- /dev/null +++ b/implementation-contributed/v8/intl/segmenter/segment-iterator-breakType.js @@ -0,0 +1,11 @@ +// Copyright 2018 the V8 project authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Flags: --harmony-intl-segmenter + +const segmenter = new Intl.Segmenter(); +const text = "Hello World, Test 123! Foo Bar. How are you?"; +const iter = segmenter.segment(text); + +assertEquals(undefined, iter.breakType); diff --git a/implementation-contributed/v8/intl/segmenter/segment-iterator-position.js b/implementation-contributed/v8/intl/segmenter/segment-iterator-position.js new file mode 100644 index 0000000000..93c529a53e --- /dev/null +++ b/implementation-contributed/v8/intl/segmenter/segment-iterator-position.js @@ -0,0 +1,11 @@ +// Copyright 2018 the V8 project authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Flags: --harmony-intl-segmenter + +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); diff --git a/implementation-contributed/v8/intl/segmenter/segment-iterator.js b/implementation-contributed/v8/intl/segmenter/segment-iterator.js index 0d0c31b405..45cb67ab5a 100644 --- a/implementation-contributed/v8/intl/segmenter/segment-iterator.js +++ b/implementation-contributed/v8/intl/segmenter/segment-iterator.js @@ -4,10 +4,17 @@ // Flags: --harmony-intl-segmenter -const segmenter = new Intl.Segmenter(); +let descriptor; const text = "Hello World, Test 123! Foo Bar. How are you?"; -const iter = segmenter.segment(text); +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("strig", typeof iter.breakType); + assertEquals("number", typeof iter.position); + assertEquals(0, iter.position); + if (granularity === "grapheme") { + assertEquals(undefined, iter.breakType); + } else { + assertEquals("string", typeof iter.breakType); + } +} diff --git a/implementation-contributed/v8/intl/segmenter/segment-line-following-modes.js b/implementation-contributed/v8/intl/segmenter/segment-line-following-modes.js new file mode 100644 index 0000000000..75e90f3bf4 --- /dev/null +++ b/implementation-contributed/v8/intl/segmenter/segment-line-following-modes.js @@ -0,0 +1,57 @@ +// Copyright 2018 the V8 project authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Flags: --harmony-intl-segmenter + +let breakCounts = {}; +for (const locale of ["en", "fr", "ja", "zh", "ko"]) { + for (const lineBreakStyle of ["strict", "normal", "loose"]) { + const seg = new Intl.Segmenter( + [locale], {granularity: "line", lineBreakStyle: lineBreakStyle}); + let opportunity = 0; + for (const text of [ + // We know the following data caused different line break results between + // different modes. + // https://www.w3.org/TR/css-text-3/#propdef-line-break + // Japanese small kana or the Katakana-Hiragana prolonged sound mark + "あぁーぃーあーいーぁーぃー", + // hyphens: + // ‐ U+2010, – U+2013, 〜 U+301C, ゠ U+30A0 + "ABC‐DEF–GHI〜JKL゠MNO", + // iteration marks: + // 々 U+3005, 〻 U+303B, ゝ U+309D, ゞ U+309E, ヽ U+30FD, ヾ U+30FE + "あ々あ〻あゝあゞあヽあヾあ", + // centered punctuation marks: + // ・ U+30FB, : U+FF1A, ; U+FF1B, ・ U+FF65, ‼ U+203C + "ABC・DEF:GHI;JKL・MNO‼PQR", + // centered punctuation marks: + // ⁇ U+2047, ⁈ U+2048, ⁉ U+2049, ! U+FF01, ? U+FF1F + "ABC⁇DEF⁈GHI⁉JKL!MNO?PQR", + ]) { + const iter = seg.segment(text); + while (!iter.following()) { + opportunity++; + } + } + breakCounts[locale + "-" + lineBreakStyle] = opportunity; + } +} +// In Japanese +// Just test the break count in loose mode is greater than normal mode. +assertTrue(breakCounts["ja-loose"] > breakCounts["ja-normal"]); +// and test the break count in normal mode is greater than strict mode. +assertTrue(breakCounts["ja-normal"] > breakCounts["ja-strict"]); +// In Chinese +// Just test the break count in loose mode is greater than normal mode. +assertTrue(breakCounts["zh-loose"] > breakCounts["zh-normal"]); +// and test the break count in normal mode is greater than strict mode. +assertTrue(breakCounts["zh-normal"] > breakCounts["zh-strict"]); +// In English, French and Korean +assertEquals(breakCounts["en-loose"], breakCounts["en-normal"]); +assertEquals(breakCounts["fr-loose"], breakCounts["fr-normal"]); +assertEquals(breakCounts["ko-loose"], breakCounts["ko-normal"]); +// and test the break count in normal mode is greater than strict mode. +assertTrue(breakCounts["en-normal"] > breakCounts["en-strict"]); +assertTrue(breakCounts["fr-normal"] > breakCounts["fr-strict"]); +assertTrue(breakCounts["ko-normal"] > breakCounts["ko-strict"]); diff --git a/implementation-contributed/v8/intl/segmenter/segment-line-following.js b/implementation-contributed/v8/intl/segmenter/segment-line-following.js new file mode 100644 index 0000000000..010f1cf7bb --- /dev/null +++ b/implementation-contributed/v8/intl/segmenter/segment-line-following.js @@ -0,0 +1,38 @@ +// Copyright 2018 the V8 project authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Flags: --harmony-intl-segmenter + +const seg = new Intl.Segmenter([], {granularity: "line"}) +for (const text of [ + "Hello world!", // English + " Hello world! ", // English with space before/after + " Hello world? Foo bar!", // English + "Jedovatou mambu objevila žena v zahrádkářské kolonii.", // Czech + "Việt Nam: Nhất thể hóa sẽ khác Trung Quốc?", // Vietnamese + "Σοβαρές ενστάσεις Κομισιόν για τον προϋπολογισμό της Ιταλίας", // Greek + "Решение Индии о покупке российских С-400 расценили как вызов США", // Russian + "הרופא שהציל נשים והנערה ששועבדה ע", // Hebrew, + "ترامب للملك سلمان: أنا جاد للغاية.. عليك دفع المزيد", // Arabic + "भारत की एस 400 मिसाइल के मुकाबले पाक की थाड, जानें कौन कितना ताकतवर", // Hindi + "ரெட் அலர்ட் எச்சரிக்கை; புதுச்சேரியில் நாளை அரசு விடுமுறை!", // Tamil + "'ఉత్తర్వులు అందే వరకు ఓటర్ల తుది జాబితాను వెబ్‌సైట్లో పెట్టవద్దు'", // Telugu + "台北》抹黑柯P失敗?朱學恒酸:姚文智氣pupu嗆大老闆", // Chinese + "วัดไทรตีระฆังเบาลงช่วงเข้าพรรษา เจ้าอาวาสเผยคนร้องเรียนรับผลกรรมแล้ว", // Thai + "九州北部の一部が暴風域に入りました(日直予報士 2018年10月06日) - 日本気象協会 tenki.jp", // Japanese + "법원 “다스 지분 처분권·수익권 모두 MB가 보유”", // Korean + ]) { + const iter = seg.segment(text); + let prev = 0; + 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; + } + assertEquals(text, segments.join("")); +} diff --git a/implementation-contributed/v8/intl/segmenter/segment-line-iterable.js b/implementation-contributed/v8/intl/segmenter/segment-line-iterable.js new file mode 100644 index 0000000000..0fb682c37e --- /dev/null +++ b/implementation-contributed/v8/intl/segmenter/segment-line-iterable.js @@ -0,0 +1,45 @@ +// Copyright 2018 the V8 project authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Flags: --harmony-intl-segmenter + +const seg = new Intl.Segmenter([], {granularity: "line"}) +for (const text of [ + "Hello world!", // English + " Hello world! ", // English with space before/after + " Hello world? Foo bar!", // English + "Jedovatou mambu objevila žena v zahrádkářské kolonii.", // Czech + "Việt Nam: Nhất thể hóa sẽ khác Trung Quốc?", // Vietnamese + "Σοβαρές ενστάσεις Κομισιόν για τον προϋπολογισμό της Ιταλίας", // Greek + "Решение Индии о покупке российских С-400 расценили как вызов США", // Russian + "הרופא שהציל נשים והנערה ששועבדה ע", // Hebrew, + "ترامب للملك سلمان: أنا جاد للغاية.. عليك دفع المزيد", // Arabic + "भारत की एस 400 मिसाइल के मुकाबले पाक की थाड, जानें कौन कितना ताकतवर", // Hindi + "ரெட் அலர்ட் எச்சரிக்கை; புதுச்சேரியில் நாளை அரசு விடுமுறை!", // Tamil + "'ఉత్తర్వులు అందే వరకు ఓటర్ల తుది జాబితాను వెబ్‌సైట్లో పెట్టవద్దు'", // Telugu + "台北》抹黑柯P失敗?朱學恒酸:姚文智氣pupu嗆大老闆", // Chinese + "วัดไทรตีระฆังเบาลงช่วงเข้าพรรษา เจ้าอาวาสเผยคนร้องเรียนรับผลกรรมแล้ว", // Thai + "九州北部の一部が暴風域に入りました(日直予報士 2018年10月06日) - 日本気象協会 tenki.jp", // Japanese + "법원 “다스 지분 처분권·수익권 모두 MB가 보유”", // Korean + ]) { + let segments = []; + // Create another %SegmentIterator% to compare with result from the one that + // created in the for of loop. + let iter = seg.segment(text); + let prev = 0; + for (const v of seg.segment(text)) { + assertTrue(["soft", "hard"].includes(v.breakType), v.breakType); + assertEquals("string", typeof v.segment); + assertTrue(v.segment.length > 0); + segments.push(v.segment); + + // manually advance the iter. + assertFalse(iter.following()); + assertEquals(iter.breakType, v.breakType); + assertEquals(text.substring(prev, iter.position), v.segment); + prev = iter.position; + } + assertTrue(iter.following()); + assertEquals(text, segments.join('')); +} diff --git a/implementation-contributed/v8/intl/segmenter/segment-line-next.js b/implementation-contributed/v8/intl/segmenter/segment-line-next.js new file mode 100644 index 0000000000..ecfb7eca82 --- /dev/null +++ b/implementation-contributed/v8/intl/segmenter/segment-line-next.js @@ -0,0 +1,36 @@ +// Copyright 2018 the V8 project authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Flags: --harmony-intl-segmenter + +const seg = new Intl.Segmenter([], {granularity: "line"}) +for (const text of [ + "Hello world!", // English + " Hello world! ", // English with space before/after + " Hello world? Foo bar!", // English + "Jedovatou mambu objevila žena v zahrádkářské kolonii.", // Czech + "Việt Nam: Nhất thể hóa sẽ khác Trung Quốc?", // Vietnamese + "Σοβαρές ενστάσεις Κομισιόν για τον προϋπολογισμό της Ιταλίας", // Greek + "Решение Индии о покупке российских С-400 расценили как вызов США", // Russian + "הרופא שהציל נשים והנערה ששועבדה ע", // Hebrew, + "ترامب للملك سلمان: أنا جاد للغاية.. عليك دفع المزيد", // Arabic + "भारत की एस 400 मिसाइल के मुकाबले पाक की थाड, जानें कौन कितना ताकतवर", // Hindi + "ரெட் அலர்ட் எச்சரிக்கை; புதுச்சேரியில் நாளை அரசு விடுமுறை!", // Tamil + "'ఉత్తర్వులు అందే వరకు ఓటర్ల తుది జాబితాను వెబ్‌సైట్లో పెట్టవద్దు'", // Telugu + "台北》抹黑柯P失敗?朱學恒酸:姚文智氣pupu嗆大老闆", // Chinese + "วัดไทรตีระฆังเบาลงช่วงเข้าพรรษา เจ้าอาวาสเผยคนร้องเรียนรับผลกรรมแล้ว", // Thai + "九州北部の一部が暴風域に入りました(日直予報士 2018年10月06日) - 日本気象協会 tenki.jp", // Japanese + "법원 “다스 지분 처분권·수익권 모두 MB가 보유”", // Korean + ]) { + const iter = seg.segment(text); + let segments = []; + for (let result = iter.next(); !result.done; result = iter.next()) { + const v = result.value; + assertTrue(["soft", "hard"].includes(iter.breakType), iter.breakType); + assertEquals("string", typeof v.segment); + assertTrue(v.segment.length > 0); + segments.push(v.segment); + } + assertEquals(text, segments.join('')); +} diff --git a/implementation-contributed/v8/intl/segmenter/segment-line-preceding.js b/implementation-contributed/v8/intl/segmenter/segment-line-preceding.js new file mode 100644 index 0000000000..3491a21b9b --- /dev/null +++ b/implementation-contributed/v8/intl/segmenter/segment-line-preceding.js @@ -0,0 +1,44 @@ +// Copyright 2018 the V8 project authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Flags: --harmony-intl-segmenter + +const seg = new Intl.Segmenter([], {granularity: "line"}) +for (const text of [ + "Hello world!", // English + " Hello world! ", // English with space before/after + " Hello world? Foo bar!", // English + "Jedovatou mambu objevila žena v zahrádkářské kolonii.", // Czech + "Việt Nam: Nhất thể hóa sẽ khác Trung Quốc?", // Vietnamese + "Σοβαρές ενστάσεις Κομισιόν για τον προϋπολογισμό της Ιταλίας", // Greek + "Решение Индии о покупке российских С-400 расценили как вызов США", // Russian + "הרופא שהציל נשים והנערה ששועבדה ע", // Hebrew, + "ترامب للملك سلمان: أنا جاد للغاية.. عليك دفع المزيد", // Arabic + "भारत की एस 400 मिसाइल के मुकाबले पाक की थाड, जानें कौन कितना ताकतवर", // Hindi + "ரெட் அலர்ட் எச்சரிக்கை; புதுச்சேரியில் நாளை அரசு விடுமுறை!", // Tamil + "'ఉత్తర్వులు అందే వరకు ఓటర్ల తుది జాబితాను వెబ్‌సైట్లో పెట్టవద్దు'", // Telugu + "台北》抹黑柯P失敗?朱學恒酸:姚文智氣pupu嗆大老闆", // Chinese + "วัดไทรตีระฆังเบาลงช่วงเข้าพรรษา เจ้าอาวาสเผยคนร้องเรียนรับผลกรรมแล้ว", // Thai + "九州北部の一部が暴風域に入りました(日直予報士 2018年10月06日) - 日本気象協会 tenki.jp", // Japanese + "법원 “다스 지분 처분권·수익권 모두 MB가 보유”", // Korean + ]) { + const iter = seg.segment(text); + let prev = text.length; + 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; + 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; + } + assertEquals(text, segments.reverse().join("")); +} diff --git a/implementation-contributed/v8/intl/segmenter/segment-line.js b/implementation-contributed/v8/intl/segmenter/segment-line.js new file mode 100644 index 0000000000..cbaa44356f --- /dev/null +++ b/implementation-contributed/v8/intl/segmenter/segment-line.js @@ -0,0 +1,29 @@ +// Copyright 2018 the V8 project authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Flags: --harmony-intl-segmenter + +const seg = new Intl.Segmenter([], {granularity: "line"}) +for (const text of [ + "Hello world!", // English + " Hello world! ", // English with space before/after + " Hello world? Foo bar!", // English + "Jedovatou mambu objevila žena v zahrádkářské kolonii.", // Czech + "Việt Nam: Nhất thể hóa sẽ khác Trung Quốc?", // Vietnamese + "Σοβαρές ενστάσεις Κομισιόν για τον προϋπολογισμό της Ιταλίας", // Greek + "Решение Индии о покупке российских С-400 расценили как вызов США", // Russian + "הרופא שהציל נשים והנערה ששועבדה ע", // Hebrew, + "ترامب للملك سلمان: أنا جاد للغاية.. عليك دفع المزيد", // Arabic + "भारत की एस 400 मिसाइल के मुकाबले पाक की थाड, जानें कौन कितना ताकतवर", // Hindi + "ரெட் அலர்ட் எச்சரிக்கை; புதுச்சேரியில் நாளை அரசு விடுமுறை!", // Tamil + "'ఉత్తర్వులు అందే వరకు ఓటర్ల తుది జాబితాను వెబ్‌సైట్లో పెట్టవద్దు'", // Telugu + "台北》抹黑柯P失敗?朱學恒酸:姚文智氣pupu嗆大老闆", // Chinese + "วัดไทรตีระฆังเบาลงช่วงเข้าพรรษา เจ้าอาวาสเผยคนร้องเรียนรับผลกรรมแล้ว", // Thai + "九州北部の一部が暴風域に入りました(日直予報士 2018年10月06日) - 日本気象協会 tenki.jp", // Japanese + "법원 “다스 지분 처분권·수익권 모두 MB가 보유”", // Korean + ]) { + const iter = seg.segment(text); + assertTrue(["soft", "hard"].includes(iter.breakType), iter.breakType); + assertEquals(0, iter.position); +} diff --git a/implementation-contributed/v8/intl/segmenter/segment-sentence-following.js b/implementation-contributed/v8/intl/segmenter/segment-sentence-following.js new file mode 100644 index 0000000000..4acae8ba3c --- /dev/null +++ b/implementation-contributed/v8/intl/segmenter/segment-sentence-following.js @@ -0,0 +1,38 @@ +// Copyright 2018 the V8 project authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Flags: --harmony-intl-segmenter + +const seg = new Intl.Segmenter([], {granularity: "sentence"}) +for (const text of [ + "Hello world!", // English + " Hello world! ", // English with space before/after + " Hello world? Foo bar!", // English + "Jedovatou mambu objevila žena v zahrádkářské kolonii.", // Czech + "Việt Nam: Nhất thể hóa sẽ khác Trung Quốc?", // Vietnamese + "Σοβαρές ενστάσεις Κομισιόν για τον προϋπολογισμό της Ιταλίας", // Greek + "Решение Индии о покупке российских С-400 расценили как вызов США", // Russian + "הרופא שהציל נשים והנערה ששועבדה ע", // Hebrew, + "ترامب للملك سلمان: أنا جاد للغاية.. عليك دفع المزيد", // Arabic + "भारत की एस 400 मिसाइल के मुकाबले पाक की थाड, जानें कौन कितना ताकतवर", // Hindi + "ரெட் அலர்ட் எச்சரிக்கை; புதுச்சேரியில் நாளை அரசு விடுமுறை!", // Tamil + "'ఉత్తర్వులు అందే వరకు ఓటర్ల తుది జాబితాను వెబ్‌సైట్లో పెట్టవద్దు'", // Telugu + "台北》抹黑柯P失敗?朱學恒酸:姚文智氣pupu嗆大老闆", // Chinese + "วัดไทรตีระฆังเบาลงช่วงเข้าพรรษา เจ้าอาวาสเผยคนร้องเรียนรับผลกรรมแล้ว", // Thai + "九州北部の一部が暴風域に入りました(日直予報士 2018年10月06日) - 日本気象協会 tenki.jp", // Japanese + "법원 “다스 지분 처분권·수익권 모두 MB가 보유”", // Korean + ]) { + const iter = seg.segment(text); + let prev = 0; + 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; + } + assertEquals(text, segments.join("")); +} diff --git a/implementation-contributed/v8/intl/segmenter/segment-sentence-iterable.js b/implementation-contributed/v8/intl/segmenter/segment-sentence-iterable.js new file mode 100644 index 0000000000..6bd3969c2b --- /dev/null +++ b/implementation-contributed/v8/intl/segmenter/segment-sentence-iterable.js @@ -0,0 +1,45 @@ +// Copyright 2018 the V8 project authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Flags: --harmony-intl-segmenter + +const seg = new Intl.Segmenter([], {granularity: "sentence"}) +for (const text of [ + "Hello world!", // English + " Hello world! ", // English with space before/after + " Hello world? Foo bar!", // English + "Jedovatou mambu objevila žena v zahrádkářské kolonii.", // Czech + "Việt Nam: Nhất thể hóa sẽ khác Trung Quốc?", // Vietnamese + "Σοβαρές ενστάσεις Κομισιόν για τον προϋπολογισμό της Ιταλίας", // Greek + "Решение Индии о покупке российских С-400 расценили как вызов США", // Russian + "הרופא שהציל נשים והנערה ששועבדה ע", // Hebrew, + "ترامب للملك سلمان: أنا جاد للغاية.. عليك دفع المزيد", // Arabic + "भारत की एस 400 मिसाइल के मुकाबले पाक की थाड, जानें कौन कितना ताकतवर", // Hindi + "ரெட் அலர்ட் எச்சரிக்கை; புதுச்சேரியில் நாளை அரசு விடுமுறை!", // Tamil + "'ఉత్తర్వులు అందే వరకు ఓటర్ల తుది జాబితాను వెబ్‌సైట్లో పెట్టవద్దు'", // Telugu + "台北》抹黑柯P失敗?朱學恒酸:姚文智氣pupu嗆大老闆", // Chinese + "วัดไทรตีระฆังเบาลงช่วงเข้าพรรษา เจ้าอาวาสเผยคนร้องเรียนรับผลกรรมแล้ว", // Thai + "九州北部の一部が暴風域に入りました(日直予報士 2018年10月06日) - 日本気象協会 tenki.jp", // Japanese + "법원 “다스 지분 처분권·수익권 모두 MB가 보유”", // Korean + ]) { + let segments = []; + // Create another %SegmentIterator% to compare with result from the one that + // created in the for of loop. + let iter = seg.segment(text); + let prev = 0; + for (const v of seg.segment(text)) { + assertTrue(["sep", "term"].includes(v.breakType), v.breakType); + assertEquals("string", typeof v.segment); + assertTrue(v.segment.length > 0); + segments.push(v.segment); + + // manually advance the iter. + assertFalse(iter.following()); + assertEquals(iter.breakType, v.breakType); + assertEquals(text.substring(prev, iter.position), v.segment); + prev = iter.position; + } + assertTrue(iter.following()); + assertEquals(text, segments.join('')); +} diff --git a/implementation-contributed/v8/intl/segmenter/segment-sentence-next.js b/implementation-contributed/v8/intl/segmenter/segment-sentence-next.js new file mode 100644 index 0000000000..071f00cfdf --- /dev/null +++ b/implementation-contributed/v8/intl/segmenter/segment-sentence-next.js @@ -0,0 +1,36 @@ +// Copyright 2018 the V8 project authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Flags: --harmony-intl-segmenter + +const seg = new Intl.Segmenter([], {granularity: "sentence"}) +for (const text of [ + "Hello world!", // English + " Hello world! ", // English with space before/after + " Hello world? Foo bar!", // English + "Jedovatou mambu objevila žena v zahrádkářské kolonii.", // Czech + "Việt Nam: Nhất thể hóa sẽ khác Trung Quốc?", // Vietnamese + "Σοβαρές ενστάσεις Κομισιόν για τον προϋπολογισμό της Ιταλίας", // Greek + "Решение Индии о покупке российских С-400 расценили как вызов США", // Russian + "הרופא שהציל נשים והנערה ששועבדה ע", // Hebrew, + "ترامب للملك سلمان: أنا جاد للغاية.. عليك دفع المزيد", // Arabic + "भारत की एस 400 मिसाइल के मुकाबले पाक की थाड, जानें कौन कितना ताकतवर", // Hindi + "ரெட் அலர்ட் எச்சரிக்கை; புதுச்சேரியில் நாளை அரசு விடுமுறை!", // Tamil + "'ఉత్తర్వులు అందే వరకు ఓటర్ల తుది జాబితాను వెబ్‌సైట్లో పెట్టవద్దు'", // Telugu + "台北》抹黑柯P失敗?朱學恒酸:姚文智氣pupu嗆大老闆", // Chinese + "วัดไทรตีระฆังเบาลงช่วงเข้าพรรษา เจ้าอาวาสเผยคนร้องเรียนรับผลกรรมแล้ว", // Thai + "九州北部の一部が暴風域に入りました(日直予報士 2018年10月06日) - 日本気象協会 tenki.jp", // Japanese + "법원 “다스 지분 처분권·수익권 모두 MB가 보유”", // Korean + ]) { + const iter = seg.segment(text); + let segments = []; + for (let result = iter.next(); !result.done; result = iter.next()) { + const v = result.value; + assertTrue(["sep", "term"].includes(iter.breakType), iter.breakType); + assertEquals("string", typeof v.segment); + assertTrue(v.segment.length > 0); + segments.push(v.segment); + } + assertEquals(text, segments.join('')); +} diff --git a/implementation-contributed/v8/intl/segmenter/segment-sentence-preceding.js b/implementation-contributed/v8/intl/segmenter/segment-sentence-preceding.js new file mode 100644 index 0000000000..291b315312 --- /dev/null +++ b/implementation-contributed/v8/intl/segmenter/segment-sentence-preceding.js @@ -0,0 +1,44 @@ +// Copyright 2018 the V8 project authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Flags: --harmony-intl-segmenter + +const seg = new Intl.Segmenter([], {granularity: "sentence"}) +for (const text of [ + "Hello world!", // English + " Hello world! ", // English with space before/after + " Hello world? Foo bar!", // English + "Jedovatou mambu objevila žena v zahrádkářské kolonii.", // Czech + "Việt Nam: Nhất thể hóa sẽ khác Trung Quốc?", // Vietnamese + "Σοβαρές ενστάσεις Κομισιόν για τον προϋπολογισμό της Ιταλίας", // Greek + "Решение Индии о покупке российских С-400 расценили как вызов США", // Russian + "הרופא שהציל נשים והנערה ששועבדה ע", // Hebrew, + "ترامب للملك سلمان: أنا جاد للغاية.. عليك دفع المزيد", // Arabic + "भारत की एस 400 मिसाइल के मुकाबले पाक की थाड, जानें कौन कितना ताकतवर", // Hindi + "ரெட் அலர்ட் எச்சரிக்கை; புதுச்சேரியில் நாளை அரசு விடுமுறை!", // Tamil + "'ఉత్తర్వులు అందే వరకు ఓటర్ల తుది జాబితాను వెబ్‌సైట్లో పెట్టవద్దు'", // Telugu + "台北》抹黑柯P失敗?朱學恒酸:姚文智氣pupu嗆大老闆", // Chinese + "วัดไทรตีระฆังเบาลงช่วงเข้าพรรษา เจ้าอาวาสเผยคนร้องเรียนรับผลกรรมแล้ว", // Thai + "九州北部の一部が暴風域に入りました(日直予報士 2018年10月06日) - 日本気象協会 tenki.jp", // Japanese + "법원 “다스 지분 처분권·수익권 모두 MB가 보유”", // Korean + ]) { + const iter = seg.segment(text); + let prev = text.length; + 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; + 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; + } + assertEquals(text, segments.reverse().join("")); +} diff --git a/implementation-contributed/v8/intl/segmenter/segment-sentence.js b/implementation-contributed/v8/intl/segmenter/segment-sentence.js new file mode 100644 index 0000000000..b258d61998 --- /dev/null +++ b/implementation-contributed/v8/intl/segmenter/segment-sentence.js @@ -0,0 +1,29 @@ +// Copyright 2018 the V8 project authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Flags: --harmony-intl-segmenter + +const seg = new Intl.Segmenter([], {granularity: "sentence"}) +for (const text of [ + "Hello world!", // English + " Hello world! ", // English with space before/after + " Hello world? Foo bar!", // English + "Jedovatou mambu objevila žena v zahrádkářské kolonii.", // Czech + "Việt Nam: Nhất thể hóa sẽ khác Trung Quốc?", // Vietnamese + "Σοβαρές ενστάσεις Κομισιόν για τον προϋπολογισμό της Ιταλίας", // Greek + "Решение Индии о покупке российских С-400 расценили как вызов США", // Russian + "הרופא שהציל נשים והנערה ששועבדה ע", // Hebrew, + "ترامب للملك سلمان: أنا جاد للغاية.. عليك دفع المزيد", // Arabic + "भारत की एस 400 मिसाइल के मुकाबले पाक की थाड, जानें कौन कितना ताकतवर", // Hindi + "ரெட் அலர்ட் எச்சரிக்கை; புதுச்சேரியில் நாளை அரசு விடுமுறை!", // Tamil + "'ఉత్తర్వులు అందే వరకు ఓటర్ల తుది జాబితాను వెబ్‌సైట్లో పెట్టవద్దు'", // Telugu + "台北》抹黑柯P失敗?朱學恒酸:姚文智氣pupu嗆大老闆", // Chinese + "วัดไทรตีระฆังเบาลงช่วงเข้าพรรษา เจ้าอาวาสเผยคนร้องเรียนรับผลกรรมแล้ว", // Thai + "九州北部の一部が暴風域に入りました(日直予報士 2018年10月06日) - 日本気象協会 tenki.jp", // Japanese + "법원 “다스 지분 처분권·수익권 모두 MB가 보유”", // Korean + ]) { + const iter = seg.segment(text); + assertTrue(["sep", "term"].includes(iter.breakType), iter.breakType); + assertEquals(0, iter.position); +} diff --git a/implementation-contributed/v8/intl/segmenter/segment-word-following.js b/implementation-contributed/v8/intl/segmenter/segment-word-following.js new file mode 100644 index 0000000000..5f2872e581 --- /dev/null +++ b/implementation-contributed/v8/intl/segmenter/segment-word-following.js @@ -0,0 +1,38 @@ +// Copyright 2018 the V8 project authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Flags: --harmony-intl-segmenter + +const seg = new Intl.Segmenter([], {granularity: "word"}) +for (const text of [ + "Hello world!", // English + " Hello world! ", // English with space before/after + " Hello world? Foo bar!", // English + "Jedovatou mambu objevila žena v zahrádkářské kolonii.", // Czech + "Việt Nam: Nhất thể hóa sẽ khác Trung Quốc?", // Vietnamese + "Σοβαρές ενστάσεις Κομισιόν για τον προϋπολογισμό της Ιταλίας", // Greek + "Решение Индии о покупке российских С-400 расценили как вызов США", // Russian + "הרופא שהציל נשים והנערה ששועבדה ע", // Hebrew, + "ترامب للملك سلمان: أنا جاد للغاية.. عليك دفع المزيد", // Arabic + "भारत की एस 400 मिसाइल के मुकाबले पाक की थाड, जानें कौन कितना ताकतवर", // Hindi + "ரெட் அலர்ட் எச்சரிக்கை; புதுச்சேரியில் நாளை அரசு விடுமுறை!", // Tamil + "'ఉత్తర్వులు అందే వరకు ఓటర్ల తుది జాబితాను వెబ్‌సైట్లో పెట్టవద్దు'", // Telugu + "台北》抹黑柯P失敗?朱學恒酸:姚文智氣pupu嗆大老闆", // Chinese + "วัดไทรตีระฆังเบาลงช่วงเข้าพรรษา เจ้าอาวาสเผยคนร้องเรียนรับผลกรรมแล้ว", // Thai + "九州北部の一部が暴風域に入りました(日直予報士 2018年10月06日) - 日本気象協会 tenki.jp", // Japanese + "법원 “다스 지분 처분권·수익권 모두 MB가 보유”", // Korean + ]) { + const iter = seg.segment(text); + let prev = 0; + 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; + } + assertEquals(text, segments.join("")); +} diff --git a/implementation-contributed/v8/intl/segmenter/segment-word-iterable.js b/implementation-contributed/v8/intl/segmenter/segment-word-iterable.js new file mode 100644 index 0000000000..120f46842d --- /dev/null +++ b/implementation-contributed/v8/intl/segmenter/segment-word-iterable.js @@ -0,0 +1,45 @@ +// Copyright 2018 the V8 project authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Flags: --harmony-intl-segmenter + +const seg = new Intl.Segmenter([], {granularity: "word"}) +for (const text of [ + "Hello world!", // English + " Hello world! ", // English with space before/after + " Hello world? Foo bar!", // English + "Jedovatou mambu objevila žena v zahrádkářské kolonii.", // Czech + "Việt Nam: Nhất thể hóa sẽ khác Trung Quốc?", // Vietnamese + "Σοβαρές ενστάσεις Κομισιόν για τον προϋπολογισμό της Ιταλίας", // Greek + "Решение Индии о покупке российских С-400 расценили как вызов США", // Russian + "הרופא שהציל נשים והנערה ששועבדה ע", // Hebrew, + "ترامب للملك سلمان: أنا جاد للغاية.. عليك دفع المزيد", // Arabic + "भारत की एस 400 मिसाइल के मुकाबले पाक की थाड, जानें कौन कितना ताकतवर", // Hindi + "ரெட் அலர்ட் எச்சரிக்கை; புதுச்சேரியில் நாளை அரசு விடுமுறை!", // Tamil + "'ఉత్తర్వులు అందే వరకు ఓటర్ల తుది జాబితాను వెబ్‌సైట్లో పెట్టవద్దు'", // Telugu + "台北》抹黑柯P失敗?朱學恒酸:姚文智氣pupu嗆大老闆", // Chinese + "วัดไทรตีระฆังเบาลงช่วงเข้าพรรษา เจ้าอาวาสเผยคนร้องเรียนรับผลกรรมแล้ว", // Thai + "九州北部の一部が暴風域に入りました(日直予報士 2018年10月06日) - 日本気象協会 tenki.jp", // Japanese + "법원 “다스 지분 처분권·수익권 모두 MB가 보유”", // Korean + ]) { + let segments = []; + // Create another %SegmentIterator% to compare with result from the one that + // created in the for of loop. + let iter = seg.segment(text); + let prev = 0; + for (const v of seg.segment(text)) { + assertTrue(["word", "none"].includes(v.breakType), v.breakType); + assertEquals("string", typeof v.segment); + assertTrue(v.segment.length > 0); + segments.push(v.segment); + + // manually advance the iter. + assertFalse(iter.following()); + assertEquals(iter.breakType, v.breakType); + assertEquals(text.substring(prev, iter.position), v.segment); + prev = iter.position; + } + assertTrue(iter.following()); + assertEquals(text, segments.join('')); +} diff --git a/implementation-contributed/v8/intl/segmenter/segment-word-next.js b/implementation-contributed/v8/intl/segmenter/segment-word-next.js new file mode 100644 index 0000000000..a88e9366ef --- /dev/null +++ b/implementation-contributed/v8/intl/segmenter/segment-word-next.js @@ -0,0 +1,36 @@ +// Copyright 2018 the V8 project authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Flags: --harmony-intl-segmenter + +const seg = new Intl.Segmenter([], {granularity: "word"}) +for (const text of [ + "Hello world!", // English + " Hello world! ", // English with space before/after + " Hello world? Foo bar!", // English + "Jedovatou mambu objevila žena v zahrádkářské kolonii.", // Czech + "Việt Nam: Nhất thể hóa sẽ khác Trung Quốc?", // Vietnamese + "Σοβαρές ενστάσεις Κομισιόν για τον προϋπολογισμό της Ιταλίας", // Greek + "Решение Индии о покупке российских С-400 расценили как вызов США", // Russian + "הרופא שהציל נשים והנערה ששועבדה ע", // Hebrew, + "ترامب للملك سلمان: أنا جاد للغاية.. عليك دفع المزيد", // Arabic + "भारत की एस 400 मिसाइल के मुकाबले पाक की थाड, जानें कौन कितना ताकतवर", // Hindi + "ரெட் அலர்ட் எச்சரிக்கை; புதுச்சேரியில் நாளை அரசு விடுமுறை!", // Tamil + "'ఉత్తర్వులు అందే వరకు ఓటర్ల తుది జాబితాను వెబ్‌సైట్లో పెట్టవద్దు'", // Telugu + "台北》抹黑柯P失敗?朱學恒酸:姚文智氣pupu嗆大老闆", // Chinese + "วัดไทรตีระฆังเบาลงช่วงเข้าพรรษา เจ้าอาวาสเผยคนร้องเรียนรับผลกรรมแล้ว", // Thai + "九州北部の一部が暴風域に入りました(日直予報士 2018年10月06日) - 日本気象協会 tenki.jp", // Japanese + "법원 “다스 지분 처분권·수익권 모두 MB가 보유”", // Korean + ]) { + const iter = seg.segment(text); + let segments = []; + for (let result = iter.next(); !result.done; result = iter.next()) { + const v = result.value; + assertTrue(["word", "none"].includes(iter.breakType), iter.breakType); + assertEquals("string", typeof v.segment); + assertTrue(v.segment.length > 0); + segments.push(v.segment); + } + assertEquals(text, segments.join('')); +} diff --git a/implementation-contributed/v8/intl/segmenter/segment-word-preceding.js b/implementation-contributed/v8/intl/segmenter/segment-word-preceding.js new file mode 100644 index 0000000000..fee750f345 --- /dev/null +++ b/implementation-contributed/v8/intl/segmenter/segment-word-preceding.js @@ -0,0 +1,44 @@ +// Copyright 2018 the V8 project authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Flags: --harmony-intl-segmenter + +const seg = new Intl.Segmenter([], {granularity: "word"}) +for (const text of [ + "Hello world!", // English + " Hello world! ", // English with space before/after + " Hello world? Foo bar!", // English + "Jedovatou mambu objevila žena v zahrádkářské kolonii.", // Czech + "Việt Nam: Nhất thể hóa sẽ khác Trung Quốc?", // Vietnamese + "Σοβαρές ενστάσεις Κομισιόν για τον προϋπολογισμό της Ιταλίας", // Greek + "Решение Индии о покупке российских С-400 расценили как вызов США", // Russian + "הרופא שהציל נשים והנערה ששועבדה ע", // Hebrew, + "ترامب للملك سلمان: أنا جاد للغاية.. عليك دفع المزيد", // Arabic + "भारत की एस 400 मिसाइल के मुकाबले पाक की थाड, जानें कौन कितना ताकतवर", // Hindi + "ரெட் அலர்ட் எச்சரிக்கை; புதுச்சேரியில் நாளை அரசு விடுமுறை!", // Tamil + "'ఉత్తర్వులు అందే వరకు ఓటర్ల తుది జాబితాను వెబ్‌సైట్లో పెట్టవద్దు'", // Telugu + "台北》抹黑柯P失敗?朱學恒酸:姚文智氣pupu嗆大老闆", // Chinese + "วัดไทรตีระฆังเบาลงช่วงเข้าพรรษา เจ้าอาวาสเผยคนร้องเรียนรับผลกรรมแล้ว", // Thai + "九州北部の一部が暴風域に入りました(日直予報士 2018年10月06日) - 日本気象協会 tenki.jp", // Japanese + "법원 “다스 지분 처분권·수익권 모두 MB가 보유”", // Korean + ]) { + const iter = seg.segment(text); + let prev = text.length; + 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; + 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; + } + assertEquals(text, segments.reverse().join("")); +} diff --git a/implementation-contributed/v8/intl/segmenter/supported-locale.js b/implementation-contributed/v8/intl/segmenter/supported-locale.js index 24825a2759..9197b6a815 100644 --- a/implementation-contributed/v8/intl/segmenter/supported-locale.js +++ b/implementation-contributed/v8/intl/segmenter/supported-locale.js @@ -9,14 +9,14 @@ assertEquals( "Intl.Segmenter.supportedLocalesOf should be a function" ); -var undef = Intl.Segmenter.supportedLocalesOf(); +const undef = Intl.Segmenter.supportedLocalesOf(); assertEquals([], undef); -var empty = Intl.Segmenter.supportedLocalesOf([]); +const empty = Intl.Segmenter.supportedLocalesOf([]); assertEquals([], empty); -var strLocale = Intl.Segmenter.supportedLocalesOf("sr"); +const strLocale = Intl.Segmenter.supportedLocalesOf("sr"); assertEquals("sr", strLocale[0]); -var multiLocale = ["sr-Thai-RS", "de", "zh-CN"]; +const multiLocale = ["sr-Thai-RS", "de", "zh-CN"]; assertEquals(multiLocale, Intl.Segmenter.supportedLocalesOf(multiLocale)); diff --git a/implementation-contributed/v8/mjsunit/array-functions-prototype-misc.js b/implementation-contributed/v8/mjsunit/array-functions-prototype-misc.js index dd95e2d266..0aff0a2304 100644 --- a/implementation-contributed/v8/mjsunit/array-functions-prototype-misc.js +++ b/implementation-contributed/v8/mjsunit/array-functions-prototype-misc.js @@ -170,20 +170,6 @@ for (var use_real_arrays = 0; use_real_arrays <= 1; use_real_arrays++) { assertEquals("concat", join); join = ba.join(''); assertEquals("catcon", join); - - var sparse = []; - sparse[pos + 1000] = 'is '; - sparse[pos + 271828] = 'time '; - sparse[pos + 31415] = 'the '; - sparse[pos + 012260199] = 'all '; - sparse[-1] = 'foo'; - sparse[pos + 22591927] = 'good '; - sparse[pos + 1618033] = 'for '; - sparse[pos + 91] = ': Now '; - sparse[pos + 86720199] = 'men.'; - sparse.hest = 'fisk'; - - assertEquals("baz: Now is the time for all good men.", sparse.join('')); } a = new_function(pos); diff --git a/implementation-contributed/v8/mjsunit/array-join.js b/implementation-contributed/v8/mjsunit/array-join.js index 0c949e769a..1d5ab30ebc 100644 --- a/implementation-contributed/v8/mjsunit/array-join.js +++ b/implementation-contributed/v8/mjsunit/array-join.js @@ -25,6 +25,17 @@ // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +assertSame(',', [null, undefined].join()); +assertSame('1.5,2.5', [1.5, 2.5].join()); +assertSame(',1.5,', [,1.5,,].join()); + +var obj = { + toString() { + return 'a'; + } +}; +assertSame('1,1.5,a,', [1, 1.5, obj, ,].join()); + // Test that array join calls toString on subarrays. var a = [[1,2],3,4,[5,6]]; assertEquals('1,2345,6', a.join('')); @@ -82,9 +93,6 @@ assertEquals(246244, a.join("oo").length); a = new Array(Math.pow(2,32) - 1); // Max length. assertEquals("", a.join("")); -a[123123123] = "o"; -a[1255215215] = "p"; -assertEquals("op", a.join("")); a = new Array(100001); for (var i = 0; i < a.length; i++) a[i] = undefined; diff --git a/implementation-contributed/v8/mjsunit/harmony/public-static-class-fields.js b/implementation-contributed/v8/mjsunit/harmony/public-static-class-fields.js index 3de3e2d9d2..0334a87786 100644 --- a/implementation-contributed/v8/mjsunit/harmony/public-static-class-fields.js +++ b/implementation-contributed/v8/mjsunit/harmony/public-static-class-fields.js @@ -457,3 +457,16 @@ y()(); assertEquals(1, X.p); } + +{ + let p = { z: class { static y = this.name } } + assertEquals(p.z.y, 'z'); + + let q = { ["z"]: class { static y = this.name } } + assertEquals(q.z.y, 'z'); + + const C = class { + static x = this.name; + } + assertEquals(C.x, 'C'); +} diff --git a/implementation-contributed/v8/mjsunit/harmony/weakrefs/basics.js b/implementation-contributed/v8/mjsunit/harmony/weakrefs/basics.js index 4cd80cff6d..3402bbec2e 100644 --- a/implementation-contributed/v8/mjsunit/harmony/weakrefs/basics.js +++ b/implementation-contributed/v8/mjsunit/harmony/weakrefs/basics.js @@ -31,8 +31,84 @@ assertEquals(wc.toString(), "[object WeakCell]"); assertNotSame(wc.__proto__, Object.prototype); assertSame(wc.__proto__.__proto__, Object.prototype); + assertEquals(wc.holdings, undefined); + let desc = Object.getOwnPropertyDescriptor(wc.__proto__, "holdings"); + assertEquals(true, desc.configurable); + assertEquals(false, desc.enumerable); + assertEquals("function", typeof desc.get); + assertEquals(undefined, desc.set); +})(); + +(function TestMakeCellWithHoldings() { + let wf = new WeakFactory(); + let obj = {a: 1}; + let holdings = {b: 2}; + let wc = wf.makeCell(obj, holdings); + assertSame(wc.holdings, holdings); +})(); + +(function TestMakeCellWithHoldingsSetHoldings() { + let wf = new WeakFactory(); + let obj = {a: 1}; + let holdings = {b: 2}; + let wc = wf.makeCell(obj, holdings); + assertSame(wc.holdings, holdings); + wc.holdings = 5; + assertSame(wc.holdings, holdings); +})(); + +(function TestMakeCellWithHoldingsSetHoldingsStrict() { + "use strict"; + let wf = new WeakFactory(); + let obj = {a: 1}; + let holdings = {b: 2}; + let wc = wf.makeCell(obj, holdings); + assertSame(wc.holdings, holdings); + assertThrows(() => { wc.holdings = 5; }, TypeError); + assertSame(wc.holdings, holdings); +})(); + +(function TestMakeCellWithNonObject() { + let wf = new WeakFactory(); + let message = "WeakFactory.makeCell: target must be an object"; + assertThrows(() => wf.makeCell(), TypeError, message); + assertThrows(() => wf.makeCell(1), TypeError, message); + assertThrows(() => wf.makeCell(false), TypeError, message); + assertThrows(() => wf.makeCell("foo"), TypeError, message); + assertThrows(() => wf.makeCell(Symbol()), TypeError, message); +})(); + +(function TestMakeCellWithProxy() { + let handler = {}; + let obj = {}; + let proxy = new Proxy(obj, handler); + let wf = new WeakFactory(); + let wc = wf.makeCell(proxy); +})(); + +(function TestMakeCellTargetAndHoldingsSameValue() { + let wf = new WeakFactory(); + let obj = {a: 1}; + // SameValue(target, holdings) not ok + assertThrows(() => wf.makeCell(obj, obj), TypeError, + "WeakFactory.makeCell: target and holdings must not be same"); + // target == holdings ok + let holdings = {a: 1}; + let wc = wf.makeCell(obj, holdings); })(); (function TestMakeCellWithoutWeakFactory() { assertThrows(() => WeakFactory.prototype.makeCell.call({}, {}), TypeError); + // Does not throw: + let wf = new WeakFactory(); + WeakFactory.prototype.makeCell.call(wf, {}); +})(); + +(function TestHoldingsWithoutWeakCell() { + let wf = new WeakFactory(); + let wc = wf.makeCell({}); + let holdings_getter = Object.getOwnPropertyDescriptor(wc.__proto__, "holdings").get; + assertThrows(() => holdings_getter.call({}), TypeError); + // Does not throw: + holdings_getter.call(wc); })(); diff --git a/implementation-contributed/v8/mjsunit/harmony/weakrefs/iterating-weak-cells.js b/implementation-contributed/v8/mjsunit/harmony/weakrefs/iterating-weak-cells.js index 4761a2840e..3dd10d3ee6 100644 --- a/implementation-contributed/v8/mjsunit/harmony/weakrefs/iterating-weak-cells.js +++ b/implementation-contributed/v8/mjsunit/harmony/weakrefs/iterating-weak-cells.js @@ -13,10 +13,14 @@ let cleanup = function(iter) { } assertEquals(cells.length, 2); if (cells[0] == wc1) { + assertEquals(cells[0].holdings, 1); assertEquals(cells[1], wc2); + assertEquals(cells[1].holdings, 2); } else { assertEquals(cells[0], wc2); + assertEquals(cells[0].holdings, 2); assertEquals(cells[1], wc1); + assertEquals(cells[1].holdings, 1); } cleanup_called = true; } @@ -24,8 +28,8 @@ let cleanup = function(iter) { let wf = new WeakFactory(cleanup); let o1 = {}; let o2 = {}; -let wc1 = wf.makeCell(o1); -let wc2 = wf.makeCell(o2); +let wc1 = wf.makeCell(o1, 1); +let wc2 = wf.makeCell(o2, 2); gc(); assertFalse(cleanup_called);