summaryrefslogtreecommitdiff
path: root/deps/v8/test/intl
diff options
context:
space:
mode:
authorTimothy Gu <timothygu99@gmail.com>2018-05-18 11:36:50 -0700
committerMyles Borins <mylesborins@google.com>2018-06-01 09:59:32 +0200
commita60ab57c3cf35bf29dfec2837cf072085f13783b (patch)
treedc8796e8c3538046623b8aa7111a595336ac7f69 /deps/v8/test/intl
parentf781758d41a2fe76d3c8060accea77917bc29812 (diff)
downloadandroid-node-v8-a60ab57c3cf35bf29dfec2837cf072085f13783b.tar.gz
android-node-v8-a60ab57c3cf35bf29dfec2837cf072085f13783b.tar.bz2
android-node-v8-a60ab57c3cf35bf29dfec2837cf072085f13783b.zip
deps: cherry-pick 6989b3f6d7 from V8 upstream
Original commit message: Fix default Intl language tag handling With certain ICU data bundles (such as the Node.js "small-icu"), %GetDefaultICULocale() may return a more specific language tag (e.g. "en-US") than what's available (e.g. "en"). In those cases, consider the more specific language tag supported. This CL also resolves the following Node.js issue: https://github.com/nodejs/node/issues/15223 Bug: v8:7024 Cq-Include-Trybots: luci.v8.try:v8_linux_noi18n_rel_ng Change-Id: Ifda0776b3418734d5caa8af4e50c17cda95add73 Reviewed-on: https://chromium-review.googlesource.com/668350 Commit-Queue: Daniel Ehrenberg <littledan@chromium.org> Reviewed-by: Daniel Ehrenberg <littledan@chromium.org> Cr-Commit-Position: refs/heads/master@{#52716} PR-URL: https://github.com/nodejs/node/pull/20826 Fixes: https://github.com/nodejs/node/issues/15223 Refs: https://github.com/v8/v8/commit/6989b3f6d7d6a5e68127332296723317917821eb Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Anatoli Papirovski <apapirovski@mac.com> Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Diffstat (limited to 'deps/v8/test/intl')
-rw-r--r--deps/v8/test/intl/assert.js41
-rw-r--r--deps/v8/test/intl/break-iterator/default-locale.js4
-rw-r--r--deps/v8/test/intl/break-iterator/wellformed-unsupported-locale.js2
-rw-r--r--deps/v8/test/intl/collator/default-locale.js11
-rw-r--r--deps/v8/test/intl/collator/wellformed-unsupported-locale.js2
-rw-r--r--deps/v8/test/intl/date-format/default-locale.js4
-rw-r--r--deps/v8/test/intl/date-format/wellformed-unsupported-locale.js2
-rw-r--r--deps/v8/test/intl/number-format/default-locale.js4
-rw-r--r--deps/v8/test/intl/number-format/wellformed-unsupported-locale.js2
9 files changed, 58 insertions, 14 deletions
diff --git a/deps/v8/test/intl/assert.js b/deps/v8/test/intl/assert.js
index d8cc85849f..c11e7c0bbf 100644
--- a/deps/v8/test/intl/assert.js
+++ b/deps/v8/test/intl/assert.js
@@ -133,6 +133,16 @@ function assertFalse(value, user_message = '') {
/**
+ * Throws if value is null.
+ */
+function assertNotNull(value, user_message = '') {
+ if (value === null) {
+ fail("not null", value, user_message);
+ }
+}
+
+
+/**
* Runs code() and asserts that it throws the specified exception.
*/
function assertThrows(code, type_opt, cause_opt) {
@@ -189,3 +199,34 @@ function assertInstanceof(obj, type) {
(actualTypeName ? ' but of < ' + actualTypeName + '>' : ''));
}
}
+
+
+/**
+ * Split a BCP 47 language tag into locale and extension.
+ */
+function splitLanguageTag(tag) {
+ var extRe = /(-[0-9A-Za-z](-[0-9A-Za-z]{2,8})+)+$/;
+ var match = %regexp_internal_match(extRe, tag);
+ if (match) {
+ return { locale: tag.slice(0, match.index), extension: match[0] };
+ }
+
+ return { locale: tag, extension: '' };
+}
+
+
+/**
+ * Throw if |parent| is not a more general language tag of |child|, nor |child|
+ * itself, per BCP 47 rules.
+ */
+function assertLanguageTag(child, parent) {
+ var childSplit = splitLanguageTag(child);
+ var parentSplit = splitLanguageTag(parent);
+
+ // Do not compare extensions at this moment, as %GetDefaultICULocale()
+ // doesn't always output something we support.
+ if (childSplit.locale !== parentSplit.locale &&
+ !childSplit.locale.startsWith(parentSplit.locale + '-')) {
+ fail(child, parent, 'language tag comparison');
+ }
+}
diff --git a/deps/v8/test/intl/break-iterator/default-locale.js b/deps/v8/test/intl/break-iterator/default-locale.js
index d8d5aeadb2..e1a42a100a 100644
--- a/deps/v8/test/intl/break-iterator/default-locale.js
+++ b/deps/v8/test/intl/break-iterator/default-locale.js
@@ -37,8 +37,8 @@ assertFalse(options.locale === 'und');
assertFalse(options.locale === '');
assertFalse(options.locale === undefined);
-// Then check for equality.
-assertEquals(options.locale, %GetDefaultICULocale());
+// Then check for legitimacy.
+assertLanguageTag(%GetDefaultICULocale(), options.locale);
var iteratorNone = new Intl.v8BreakIterator();
assertEquals(options.locale, iteratorNone.resolvedOptions().locale);
diff --git a/deps/v8/test/intl/break-iterator/wellformed-unsupported-locale.js b/deps/v8/test/intl/break-iterator/wellformed-unsupported-locale.js
index 5ac8fbcd41..ffa44aef08 100644
--- a/deps/v8/test/intl/break-iterator/wellformed-unsupported-locale.js
+++ b/deps/v8/test/intl/break-iterator/wellformed-unsupported-locale.js
@@ -29,4 +29,4 @@
var iterator = Intl.v8BreakIterator(['xx']);
-assertEquals(iterator.resolvedOptions().locale, %GetDefaultICULocale());
+assertLanguageTag(%GetDefaultICULocale(), iterator.resolvedOptions().locale);
diff --git a/deps/v8/test/intl/collator/default-locale.js b/deps/v8/test/intl/collator/default-locale.js
index db9b1e7330..5fc6ff4665 100644
--- a/deps/v8/test/intl/collator/default-locale.js
+++ b/deps/v8/test/intl/collator/default-locale.js
@@ -37,8 +37,8 @@ assertFalse(options.locale === 'und');
assertFalse(options.locale === '');
assertFalse(options.locale === undefined);
-// Then check for equality.
-assertEquals(options.locale, %GetDefaultICULocale());
+// Then check for legitimacy.
+assertLanguageTag(%GetDefaultICULocale(), options.locale);
var collatorNone = new Intl.Collator();
assertEquals(options.locale, collatorNone.resolvedOptions().locale);
@@ -48,5 +48,8 @@ var collatorBraket = new Intl.Collator({});
assertEquals(options.locale, collatorBraket.resolvedOptions().locale);
var collatorWithOptions = new Intl.Collator(undefined, {usage: 'search'});
-assertEquals(%GetDefaultICULocale() + '-u-co-search',
- collatorWithOptions.resolvedOptions().locale);
+assertLanguageTag(%GetDefaultICULocale(),
+ collatorWithOptions.resolvedOptions().locale);
+assertNotNull(
+ %regexp_internal_match(/-u(-[a-zA-Z]+-[a-zA-Z]+)*-co-search/,
+ collatorWithOptions.resolvedOptions().locale));
diff --git a/deps/v8/test/intl/collator/wellformed-unsupported-locale.js b/deps/v8/test/intl/collator/wellformed-unsupported-locale.js
index 3963d47a61..ad89e3e220 100644
--- a/deps/v8/test/intl/collator/wellformed-unsupported-locale.js
+++ b/deps/v8/test/intl/collator/wellformed-unsupported-locale.js
@@ -29,4 +29,4 @@
var collator = Intl.Collator(['xx']);
-assertEquals(collator.resolvedOptions().locale, %GetDefaultICULocale());
+assertLanguageTag(%GetDefaultICULocale(), collator.resolvedOptions().locale);
diff --git a/deps/v8/test/intl/date-format/default-locale.js b/deps/v8/test/intl/date-format/default-locale.js
index 8e9b7fcec3..2d79e895b5 100644
--- a/deps/v8/test/intl/date-format/default-locale.js
+++ b/deps/v8/test/intl/date-format/default-locale.js
@@ -37,8 +37,8 @@ assertFalse(options.locale === 'und');
assertFalse(options.locale === '');
assertFalse(options.locale === undefined);
-// Then check for equality.
-assertEquals(options.locale, %GetDefaultICULocale());
+// Then check for legitimacy.
+assertLanguageTag(%GetDefaultICULocale(), options.locale);
var dtfNone = new Intl.DateTimeFormat();
assertEquals(options.locale, dtfNone.resolvedOptions().locale);
diff --git a/deps/v8/test/intl/date-format/wellformed-unsupported-locale.js b/deps/v8/test/intl/date-format/wellformed-unsupported-locale.js
index 6f063abbd1..b812164832 100644
--- a/deps/v8/test/intl/date-format/wellformed-unsupported-locale.js
+++ b/deps/v8/test/intl/date-format/wellformed-unsupported-locale.js
@@ -29,4 +29,4 @@
var dtf = Intl.DateTimeFormat(['xx']);
-assertEquals(dtf.resolvedOptions().locale, %GetDefaultICULocale());
+assertLanguageTag(%GetDefaultICULocale(), dtf.resolvedOptions().locale);
diff --git a/deps/v8/test/intl/number-format/default-locale.js b/deps/v8/test/intl/number-format/default-locale.js
index cd67ba724f..a24aec2333 100644
--- a/deps/v8/test/intl/number-format/default-locale.js
+++ b/deps/v8/test/intl/number-format/default-locale.js
@@ -37,8 +37,8 @@ assertFalse(options.locale === 'und');
assertFalse(options.locale === '');
assertFalse(options.locale === undefined);
-// Then check for equality.
-assertEquals(options.locale, %GetDefaultICULocale());
+// Then check for legitimacy.
+assertLanguageTag(%GetDefaultICULocale(), options.locale);
var nfNone = new Intl.NumberFormat();
assertEquals(options.locale, nfNone.resolvedOptions().locale);
diff --git a/deps/v8/test/intl/number-format/wellformed-unsupported-locale.js b/deps/v8/test/intl/number-format/wellformed-unsupported-locale.js
index 195eba4c19..c51753928e 100644
--- a/deps/v8/test/intl/number-format/wellformed-unsupported-locale.js
+++ b/deps/v8/test/intl/number-format/wellformed-unsupported-locale.js
@@ -29,4 +29,4 @@
var nf = Intl.NumberFormat(['xx']);
-assertEquals(nf.resolvedOptions().locale, %GetDefaultICULocale());
+assertLanguageTag(%GetDefaultICULocale(), nf.resolvedOptions().locale);