Commit 5bd57783 authored by Frank Tang's avatar Frank Tang Committed by Commit Bot

[Intl] Adding volume units.

Add 'fluid-ounce','gallon', 'liter', and 'milliliter'
Also roll ICU to 682a2309

Sync with https://github.com/tc39/proposal-unified-intl-numberformat/pull/48


Bug: v8:9475
Change-Id: If45a20f17f5973b860893b0f70e724cc93c6550a
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/1699759
Commit-Queue: Frank Tang <ftang@chromium.org>
Reviewed-by: 's avatarJungshik Shin <jshin@chromium.org>
Reviewed-by: 's avatarAdam Klein <adamk@chromium.org>
Reviewed-by: 's avatarMichael Achenbach <machenbach@chromium.org>
Cr-Commit-Position: refs/heads/master@{#62903}
parent 61e2b67e
......@@ -61,7 +61,7 @@ deps = {
'v8/third_party/depot_tools':
Var('chromium_url') + '/chromium/tools/depot_tools.git' + '@' + 'ee7b9dda90e409fb92031d511151debe5db7db9f',
'v8/third_party/icu':
Var('chromium_url') + '/chromium/deps/icu.git' + '@' + 'fd97d4326fac6da84452b2d5fe75ff0949368dab',
Var('chromium_url') + '/chromium/deps/icu.git' + '@' + '682a230923933a7157a41b88c7804b6b7d2abdfa',
'v8/third_party/instrumented_libraries':
Var('chromium_url') + '/chromium/src/third_party/instrumented_libraries.git' + '@' + 'b1c3ca20848c117eb935b02c25d441f03e6fbc5e',
'v8/buildtools':
......
......@@ -172,16 +172,21 @@ std::map<const std::string, icu::MeasureUnit> CreateUnitMap() {
status = U_ZERO_ERROR;
// See the list in ecma402 #sec-issanctionedsimpleunitidentifier
std::set<std::string> sanctioned(
{"acre", "bit", "byte", "celsius",
"centimeter", "day", "degree", "fahrenheit",
"foot", "gigabit", "gigabyte", "gram",
"hectare", "hour", "inch", "kilobit",
"kilobyte", "kilogram", "kilometer", "megabit",
"megabyte", "meter", "mile", "mile-scandinavian",
"millimeter", "millisecond", "minute", "month",
"ounce", "percent", "petabyte", "pound",
"second", "stone", "terabit", "terabyte",
"week", "yard", "year"});
{"acre", "bit", "byte",
"celsius", "centimeter", "day",
"degree", "fahrenheit", "fluid-ounce",
"foot", "gallon", "gigabit",
"gigabyte", "gram", "hectare",
"hour", "inch", "kilobit",
"kilobyte", "kilogram", "kilometer",
"liter", "megabit", "megabyte",
"meter", "mile", "mile-scandinavian",
"millimeter", "milliliter", "millisecond",
"minute", "month", "ounce",
"percent", "petabyte", "pound",
"second", "stone", "terabit",
"terabyte", "week", "yard",
"year"});
std::vector<icu::MeasureUnit> units(total);
total = icu::MeasureUnit::getAvailable(units.data(), total, status);
CHECK(U_SUCCESS(status));
......
......@@ -24,6 +24,7 @@ assertEquals(undefined, nf.resolvedOptions().unit);
assertThrows(() => new Intl.NumberFormat("en", {style: 'unit'}), TypeError);
const validUnits = [
// IsSanctionedSimpleUnitIdentifier
'acre',
'bit',
'byte',
......@@ -32,7 +33,9 @@ const validUnits = [
'day',
'degree',
'fahrenheit',
'fluid-ounce',
'foot',
'gallon',
'gigabit',
'gigabyte',
'gram',
......@@ -43,12 +46,14 @@ const validUnits = [
'kilobyte',
'kilogram',
'kilometer',
'liter',
'megabit',
'megabyte',
'meter',
'mile-scandinavian',
'mile',
'millimeter',
'milliliter',
'millisecond',
'minute',
'month',
......@@ -68,6 +73,9 @@ const validUnits = [
'meter-per-second',
'yard-per-second',
'yard-per-hour',
// -per- in IsWellFormedUnitIdentifier
'liter-per-kilometer',
'mile-per-gallon',
];
for (const unit of validUnits) {
......@@ -103,12 +111,10 @@ assertThrows(() => c('day-person'), RangeError);
assertThrows(() => c('deciliter'), RangeError);
assertThrows(() => c('decimeter'), RangeError);
assertThrows(() => c('fathom'), RangeError);
assertThrows(() => c('fluid-ounce'), RangeError);
assertThrows(() => c('foodcalorie'), RangeError);
assertThrows(() => c('furlong'), RangeError);
assertThrows(() => c('g-force'), RangeError);
assertThrows(() => c('gallon-imperial'), RangeError);
assertThrows(() => c('gallon'), RangeError);
assertThrows(() => c('generic'), RangeError);
assertThrows(() => c('gigahertz'), RangeError);
assertThrows(() => c('gigawatt'), RangeError);
......@@ -128,8 +134,6 @@ assertThrows(() => c('kilowatt'), RangeError);
assertThrows(() => c('knot'), RangeError);
assertThrows(() => c('light-year'), RangeError);
assertThrows(() => c('liter-per-100kilometers'), RangeError);
assertThrows(() => c('liter-per-kilometer'), RangeError);
assertThrows(() => c('liter'), RangeError);
assertThrows(() => c('lux'), RangeError);
assertThrows(() => c('megahertz'), RangeError);
assertThrows(() => c('megaliter'), RangeError);
......@@ -140,12 +144,10 @@ assertThrows(() => c('microgram'), RangeError);
assertThrows(() => c('micrometer'), RangeError);
assertThrows(() => c('microsecond'), RangeError);
assertThrows(() => c('mile-per-gallon-imperial'), RangeError);
assertThrows(() => c('mile-per-gallon'), RangeError);
assertThrows(() => c('milliampere'), RangeError);
assertThrows(() => c('millibar'), RangeError);
assertThrows(() => c('milligram-per-deciliter'), RangeError);
assertThrows(() => c('milligram'), RangeError);
assertThrows(() => c('milliliter'), RangeError);
assertThrows(() => c('millimeter-of-mercury'), RangeError);
assertThrows(() => c('millimole-per-liter'), RangeError);
assertThrows(() => c('milliwatt'), RangeError);
......
// Copyright 2019 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-numberformat-unified
// Test format of all valid units won't throw exception.
let validList = [
// IsSanctionedSimpleUnitIdentifier
'acre',
'bit',
'byte',
'celsius',
'centimeter',
'day',
'degree',
'fahrenheit',
'fluid-ounce',
'foot',
'gallon',
'gigabit',
'gigabyte',
'gram',
'hectare',
'hour',
'inch',
'kilobit',
'kilobyte',
'kilogram',
'kilometer',
'liter',
'megabit',
'megabyte',
'meter',
'mile',
'mile-scandinavian',
'millimeter',
'milliliter',
'millisecond',
'minute',
'month',
'ounce',
'percent',
'petabyte',
'pound',
'second',
'stone',
'terabit',
'terabyte',
'week',
'yard',
'year',
// -per- in IsWellFormedUnitIdentifier
'liter-per-kilometer',
'mile-per-gallon',
];
for (let unit of validList) {
let nf = new Intl.NumberFormat("en", {style: "unit", unit});
assertDoesNotThrow(() => nf.format(123.45),
"unit: '" + unit + "' should not throw");
}
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