Use better error messages for dateStyle/timeStyle
Bug: v8:10880 Change-Id: I7a9ba96e4b0c83565c4749101082c661e21d5ef1 Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2400598 Reviewed-by: Jakob Kummerow <jkummerow@chromium.org> Reviewed-by: Frank Tang <ftang@chromium.org> Commit-Queue: Frank Tang <ftang@chromium.org> Cr-Commit-Position: refs/heads/master@{#69844}
This commit is contained in:
parent
4e47acccc8
commit
5d988ea326
@ -315,6 +315,7 @@ namespace internal {
|
||||
T(BigIntDivZero, "Division by zero") \
|
||||
T(BigIntNegativeExponent, "Exponent must be positive") \
|
||||
T(BigIntTooBig, "Maximum BigInt size exceeded") \
|
||||
T(CantSetOptionXWhenYIsUsed, "Can't set option % when % is used") \
|
||||
T(DateRange, "Provided date is not in valid range.") \
|
||||
T(ExpectedLocation, \
|
||||
"Expected letters optionally connected with underscores or hyphens for " \
|
||||
|
@ -1744,13 +1744,32 @@ MaybeHandle<JSDateTimeFormat> JSDateTimeFormat::New(
|
||||
// iii. If p is not undefined, then
|
||||
// 1. Throw a TypeError exception.
|
||||
if (skeleton.length() > 0) {
|
||||
THROW_NEW_ERROR(isolate,
|
||||
NewTypeError(MessageTemplate::kInvalid,
|
||||
factory->NewStringFromStaticChars("option"),
|
||||
date_style != DateTimeStyle::kUndefined
|
||||
? factory->dateStyle_string()
|
||||
: factory->timeStyle_string()),
|
||||
JSDateTimeFormat);
|
||||
std::string prop;
|
||||
for (const auto& item : GetPatternItems()) {
|
||||
for (const auto& pair : item.pairs) {
|
||||
if (skeleton.find(pair.pattern) != std::string::npos) {
|
||||
prop.assign(item.property);
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!prop.empty()) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (prop.empty() && skeleton.find("S") != std::string::npos) {
|
||||
prop.assign("fractionalSecondDigits");
|
||||
}
|
||||
if (!prop.empty()) {
|
||||
THROW_NEW_ERROR(
|
||||
isolate,
|
||||
NewTypeError(MessageTemplate::kCantSetOptionXWhenYIsUsed,
|
||||
factory->NewStringFromAsciiChecked(prop.c_str()),
|
||||
date_style != DateTimeStyle::kUndefined
|
||||
? factory->dateStyle_string()
|
||||
: factory->timeStyle_string()),
|
||||
JSDateTimeFormat);
|
||||
}
|
||||
UNREACHABLE();
|
||||
}
|
||||
// b. Let pattern be DateTimeStylePattern(dateStyle, timeStyle,
|
||||
// dataLocaleData, hc).
|
||||
|
@ -84,7 +84,7 @@ bytecodes: [
|
||||
B(Mov), R(this), R(0),
|
||||
B(Mov), R(context), R(2),
|
||||
/* 48 E> */ B(CallRuntime), U16(Runtime::kAddPrivateBrand), R(0), U8(3),
|
||||
/* 53 S> */ B(Wide), B(LdaSmi), I16(266),
|
||||
/* 53 S> */ B(Wide), B(LdaSmi), I16(267),
|
||||
B(Star), R(3),
|
||||
B(LdaConstant), U8(0),
|
||||
B(Star), R(4),
|
||||
@ -115,7 +115,7 @@ bytecodes: [
|
||||
B(Mov), R(this), R(0),
|
||||
B(Mov), R(context), R(2),
|
||||
/* 41 E> */ B(CallRuntime), U16(Runtime::kAddPrivateBrand), R(0), U8(3),
|
||||
/* 46 S> */ B(Wide), B(LdaSmi), I16(265),
|
||||
/* 46 S> */ B(Wide), B(LdaSmi), I16(266),
|
||||
B(Star), R(3),
|
||||
B(LdaConstant), U8(0),
|
||||
B(Star), R(4),
|
||||
@ -146,7 +146,7 @@ bytecodes: [
|
||||
B(Mov), R(this), R(0),
|
||||
B(Mov), R(context), R(2),
|
||||
/* 48 E> */ B(CallRuntime), U16(Runtime::kAddPrivateBrand), R(0), U8(3),
|
||||
/* 53 S> */ B(Wide), B(LdaSmi), I16(266),
|
||||
/* 53 S> */ B(Wide), B(LdaSmi), I16(267),
|
||||
B(Star), R(3),
|
||||
B(LdaConstant), U8(0),
|
||||
B(Star), R(4),
|
||||
@ -177,7 +177,7 @@ bytecodes: [
|
||||
B(Mov), R(this), R(0),
|
||||
B(Mov), R(context), R(2),
|
||||
/* 41 E> */ B(CallRuntime), U16(Runtime::kAddPrivateBrand), R(0), U8(3),
|
||||
/* 46 S> */ B(Wide), B(LdaSmi), I16(265),
|
||||
/* 46 S> */ B(Wide), B(LdaSmi), I16(266),
|
||||
B(Star), R(4),
|
||||
B(LdaConstant), U8(0),
|
||||
B(Star), R(5),
|
||||
|
@ -57,7 +57,7 @@ bytecodes: [
|
||||
B(Mov), R(this), R(0),
|
||||
B(Mov), R(context), R(2),
|
||||
/* 44 E> */ B(CallRuntime), U16(Runtime::kAddPrivateBrand), R(0), U8(3),
|
||||
/* 49 S> */ B(Wide), B(LdaSmi), I16(264),
|
||||
/* 49 S> */ B(Wide), B(LdaSmi), I16(265),
|
||||
B(Star), R(3),
|
||||
B(LdaConstant), U8(0),
|
||||
B(Star), R(4),
|
||||
@ -89,7 +89,7 @@ bytecodes: [
|
||||
B(Mov), R(this), R(0),
|
||||
B(Mov), R(context), R(2),
|
||||
/* 44 E> */ B(CallRuntime), U16(Runtime::kAddPrivateBrand), R(0), U8(3),
|
||||
/* 49 S> */ B(Wide), B(LdaSmi), I16(264),
|
||||
/* 49 S> */ B(Wide), B(LdaSmi), I16(265),
|
||||
B(Star), R(3),
|
||||
B(LdaConstant), U8(0),
|
||||
B(Star), R(4),
|
||||
|
@ -25,7 +25,7 @@ bytecodes: [
|
||||
B(TestReferenceEqual), R(this),
|
||||
B(Mov), R(this), R(1),
|
||||
B(JumpIfTrue), U8(18),
|
||||
B(Wide), B(LdaSmi), I16(262),
|
||||
B(Wide), B(LdaSmi), I16(263),
|
||||
B(Star), R(2),
|
||||
B(LdaConstant), U8(0),
|
||||
B(Star), R(3),
|
||||
@ -56,7 +56,7 @@ frame size: 2
|
||||
parameter count: 1
|
||||
bytecode array length: 16
|
||||
bytecodes: [
|
||||
/* 56 S> */ B(Wide), B(LdaSmi), I16(264),
|
||||
/* 56 S> */ B(Wide), B(LdaSmi), I16(265),
|
||||
B(Star), R(0),
|
||||
B(LdaConstant), U8(0),
|
||||
B(Star), R(1),
|
||||
@ -83,7 +83,7 @@ frame size: 2
|
||||
parameter count: 1
|
||||
bytecode array length: 16
|
||||
bytecodes: [
|
||||
/* 56 S> */ B(Wide), B(LdaSmi), I16(264),
|
||||
/* 56 S> */ B(Wide), B(LdaSmi), I16(265),
|
||||
B(Star), R(0),
|
||||
B(LdaConstant), U8(0),
|
||||
B(Star), R(1),
|
||||
@ -122,7 +122,7 @@ bytecodes: [
|
||||
/* 94 E> */ B(TestReferenceEqual), R(this),
|
||||
B(Mov), R(this), R(0),
|
||||
B(JumpIfTrue), U8(18),
|
||||
B(Wide), B(LdaSmi), I16(262),
|
||||
B(Wide), B(LdaSmi), I16(263),
|
||||
B(Star), R(2),
|
||||
B(LdaConstant), U8(0),
|
||||
B(Star), R(3),
|
||||
@ -144,7 +144,7 @@ bytecodes: [
|
||||
/* 109 E> */ B(TestReferenceEqual), R(this),
|
||||
B(Mov), R(this), R(1),
|
||||
B(JumpIfTrue), U8(18),
|
||||
B(Wide), B(LdaSmi), I16(263),
|
||||
B(Wide), B(LdaSmi), I16(264),
|
||||
B(Star), R(3),
|
||||
B(LdaConstant), U8(0),
|
||||
B(Star), R(4),
|
||||
@ -159,7 +159,7 @@ bytecodes: [
|
||||
/* 133 E> */ B(TestReferenceEqual), R(this),
|
||||
B(Mov), R(this), R(0),
|
||||
B(JumpIfTrue), U8(18),
|
||||
B(Wide), B(LdaSmi), I16(262),
|
||||
B(Wide), B(LdaSmi), I16(263),
|
||||
B(Star), R(2),
|
||||
B(LdaConstant), U8(0),
|
||||
B(Star), R(3),
|
||||
@ -189,7 +189,7 @@ frame size: 2
|
||||
parameter count: 1
|
||||
bytecode array length: 16
|
||||
bytecodes: [
|
||||
/* 60 S> */ B(Wide), B(LdaSmi), I16(266),
|
||||
/* 60 S> */ B(Wide), B(LdaSmi), I16(267),
|
||||
B(Star), R(0),
|
||||
B(LdaConstant), U8(0),
|
||||
B(Star), R(1),
|
||||
@ -215,7 +215,7 @@ frame size: 2
|
||||
parameter count: 1
|
||||
bytecode array length: 16
|
||||
bytecodes: [
|
||||
/* 53 S> */ B(Wide), B(LdaSmi), I16(265),
|
||||
/* 53 S> */ B(Wide), B(LdaSmi), I16(266),
|
||||
B(Star), R(0),
|
||||
B(LdaConstant), U8(0),
|
||||
B(Star), R(1),
|
||||
@ -241,7 +241,7 @@ frame size: 2
|
||||
parameter count: 1
|
||||
bytecode array length: 16
|
||||
bytecodes: [
|
||||
/* 60 S> */ B(Wide), B(LdaSmi), I16(266),
|
||||
/* 60 S> */ B(Wide), B(LdaSmi), I16(267),
|
||||
B(Star), R(0),
|
||||
B(LdaConstant), U8(0),
|
||||
B(Star), R(1),
|
||||
@ -267,7 +267,7 @@ frame size: 3
|
||||
parameter count: 1
|
||||
bytecode array length: 16
|
||||
bytecodes: [
|
||||
/* 46 S> */ B(Wide), B(LdaSmi), I16(265),
|
||||
/* 46 S> */ B(Wide), B(LdaSmi), I16(266),
|
||||
B(Star), R(1),
|
||||
B(LdaConstant), U8(0),
|
||||
B(Star), R(2),
|
||||
|
@ -44,10 +44,10 @@ assertThrows(
|
||||
() => (new Intl.DateTimeFormat(
|
||||
"en", {timeStyle: "short", fractionalSecondDigits: 3})),
|
||||
TypeError,
|
||||
"Invalid option : timeStyle");
|
||||
"Can't set option fractionalSecondDigits when timeStyle is used");
|
||||
|
||||
assertThrows(
|
||||
() => (new Intl.DateTimeFormat(
|
||||
"en", {dateStyle: "short", fractionalSecondDigits: 3})),
|
||||
TypeError,
|
||||
"Invalid option : dateStyle");
|
||||
"Can't set option fractionalSecondDigits when dateStyle is used");
|
||||
|
@ -14,6 +14,7 @@ let opt = {
|
||||
day: '2-digit',
|
||||
hour: '2-digit',
|
||||
minute: '2-digit',
|
||||
fractionalSecondDigits: 2,
|
||||
};
|
||||
|
||||
let keys = Object.keys(opt);
|
||||
@ -25,10 +26,10 @@ testTimeStyle.timeStyle = 'long';
|
||||
for (key of keys) {
|
||||
assertThrows(
|
||||
() => new Intl.DateTimeFormat('en', testDateStyle),
|
||||
TypeError, "Invalid option : dateStyle");
|
||||
TypeError, "Can't set option " + key + " when dateStyle is used");
|
||||
assertThrows(
|
||||
() => new Intl.DateTimeFormat('en', testTimeStyle),
|
||||
TypeError, "Invalid option : timeStyle");
|
||||
TypeError, "Can't set option " + key + " when timeStyle is used");
|
||||
testDateStyle[key] = undefined;
|
||||
testTimeStyle[key] = undefined;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user