dfab3f44e8
Change NumberFormat.prototpe.resolvedOptions to return new options in v3. Also fix a heap allocation assertion bug in GetStringOrBooleanOption while the useGrouping option is an invalid argument. https://github.com/tc39/proposal-intl-numberformat-v3 https://chromestatus.com/guide/edit/5707621009981440 Design Doc: https://docs.google.com/document/d/19jAogPBb6W4Samt8NWGZKu47iv0_KoQhBvLgQH3xvr8/edit Bug: v8:10776 Change-Id: Iaeeb0398b77394db3c941a2706d44b734a1f9d8c Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/3427298 Reviewed-by: Shu-yu Guo <syg@chromium.org> Commit-Queue: Frank Tang <ftang@chromium.org> Cr-Commit-Position: refs/heads/main@{#79161}
61 lines
1.5 KiB
JavaScript
61 lines
1.5 KiB
JavaScript
// Copyright 2021 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-number-format-v3
|
|
|
|
let validRoundingMode = [
|
|
"ceil",
|
|
"floor",
|
|
"expand",
|
|
"halfCeil",
|
|
"halfExpand",
|
|
"halfFloor",
|
|
"halfTrunc",
|
|
"halfEven",
|
|
"trunc",
|
|
];
|
|
|
|
let invalidRoundingMode = [
|
|
"ceiling",
|
|
"down",
|
|
"Down",
|
|
"flooring",
|
|
"halfDown",
|
|
"halfUp",
|
|
"halfup",
|
|
"halfeven",
|
|
"halfdown",
|
|
"half-up",
|
|
"half-even",
|
|
"half-down",
|
|
"up",
|
|
"Up",
|
|
];
|
|
|
|
validRoundingMode.forEach(function(roundingMode) {
|
|
let nf = new Intl.NumberFormat(undefined, {roundingMode});
|
|
assertEquals(roundingMode, nf.resolvedOptions().roundingMode);
|
|
});
|
|
|
|
invalidRoundingMode.forEach(function(roundingMode) {
|
|
assertThrows(() => {
|
|
let nf = new Intl.NumberFormat(undefined, {roundingMode}); });
|
|
});
|
|
|
|
// Check default is "halfExpand"
|
|
assertEquals("halfExpand", (new Intl.NumberFormat().resolvedOptions().roundingMode));
|
|
assertEquals("halfExpand", (new Intl.NumberFormat(
|
|
undefined, {roundingMode: undefined}).resolvedOptions().roundingMode));
|
|
|
|
// Check roundingMode is read once after reading signDisplay
|
|
|
|
let read = [];
|
|
let options = {
|
|
get signDisplay() { read.push('signDisplay'); return undefined; },
|
|
get roundingMode() { read.push('roundingMode'); return undefined; },
|
|
};
|
|
|
|
assertDoesNotThrow(() => new Intl.NumberFormat(undefined, options));
|
|
assertEquals("signDisplay,roundingMode", read.join(","));
|