fix intl issues

Signed-off-by: liujia178 <liujia178@huawei.com>
This commit is contained in:
liujia178 2024-06-24 16:06:08 +08:00
parent f242284f87
commit d08e19f0c3
6 changed files with 38 additions and 10 deletions

View File

@ -64,7 +64,7 @@ JSTaggedValue BuiltinsDateTimeFormat::DateTimeFormatConstructor(EcmaRuntimeCallI
// a. Perform ? DefinePropertyOrThrow(this, %Intl%.[[FallbackSymbol]], PropertyDescriptor{ [[Value]]:
// dateTimeFormat, [[Writable]]: false, [[Enumerable]]: false, [[Configurable]]: false }).
// b. Return this.
if (newTarget->IsUndefined() && thisValue->IsJSObject()) {
if (GetNewTarget(argv)->IsUndefined() && thisValue->IsJSObject()) {
bool isInstanceOf = JSObject::InstanceOf(thread, thisValue, env->GetDateTimeFormatFunction());
RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread);
if (isInstanceOf) {
@ -281,10 +281,6 @@ JSTaggedValue BuiltinsDateTimeFormat::FormatRange(EcmaRuntimeCallInfo *argv)
JSTaggedNumber valueY = JSTaggedValue::ToNumber(thread, endDate);
RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread);
double y = valueY.GetNumber();
// 7. If x is greater than y, throw a RangeError exception.
if (x > y) {
THROW_RANGE_ERROR_AND_RETURN(thread, "x is greater than y", JSTaggedValue::Exception());
}
// 8. Return ? FormatDateTimeRange(dtf, x, y)
JSHandle<JSDateTimeFormat> dtf = JSHandle<JSDateTimeFormat>::Cast(thisValue);

View File

@ -66,7 +66,7 @@ JSTaggedValue BuiltinsNumberFormat::NumberFormatConstructor(EcmaRuntimeCallInfo
// a. Perform ? DefinePropertyOrThrow(this, %Intl%.[[FallbackSymbol]], PropertyDescriptor{
// [[Value]]: numberFormat, [[Writable]]: false, [[Enumerable]]: false, [[Configurable]]: false }).
// b. Return this.
if (newTarget->IsUndefined() && thisValue->IsJSObject()) {
if (GetNewTarget(argv)->IsUndefined() && thisValue->IsJSObject()) {
bool isInstanceOf = JSObject::InstanceOf(thread, thisValue, env->GetNumberFormatFunction());
RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread);
if (isInstanceOf) {

View File

@ -390,7 +390,7 @@ JSHandle<JSDateTimeFormat> JSDateTimeFormat::InitializeDateTimeFormat(JSThread *
if (!numberingSystem->IsUndefined()) {
JSHandle<EcmaString> nsEcmaStr = JSHandle<EcmaString>::Cast(numberingSystem);
nsStr = intl::LocaleHelper::ConvertToStdString(nsEcmaStr);
if (!JSLocale::IsWellNumberingSystem(nsStr)) {
if (!JSLocale::IsNormativeNumberingSystem(nsStr)) {
THROW_RANGE_ERROR_AND_RETURN(thread, "invalid numberingSystem", dateTimeFormat);
}
}
@ -428,7 +428,7 @@ JSHandle<JSDateTimeFormat> JSDateTimeFormat::InitializeDateTimeFormat(JSThread *
ASSERT_PRINT(!icuLocale.isBogus(), "icuLocale is bogus");
UErrorCode status = U_ZERO_ERROR;
if (numberingSystem->IsUndefined()) {
if (numberingSystem->IsUndefined() || !JSLocale::IsWellNumberingSystem(nsStr)) {
std::string numberingSystemStr = JSLocale::GetNumberingSystem(icuLocale);
auto result = factory->NewFromStdString(numberingSystemStr);
dateTimeFormat->SetNumberingSystem(thread, result);

View File

@ -13,3 +13,12 @@
true
true
true
true
true
true
true
true
true
true
true

View File

@ -32,3 +32,28 @@ try {
} catch (err) {
print(err instanceof TypeError);
}
{
let noThrow = true;
try {
new Intl.DateTimeFormat("en", { numberingSystem: "invalid" });
} catch (e) {
noThrow = false;
}
print(noThrow);
}
{
let constructors = [
{c: Intl.DateTimeFormat, f: "format"},
{c: Intl.NumberFormat, f: "format"},
];
for (let {c, f} of constructors) {
let o = Object.create(c.prototype);
print(o instanceof c);
print(o == c.call(o));
print(o[f] == o[f]);
print(o instanceof c);
}
}

View File

@ -1672,12 +1672,10 @@
"intl/relative-time-format/format-en.js",
"intl/date-format/format-range.js",
"intl/date-format/date_style_time_style_hour_cycle.js",
"intl/date-format/check-numbering-system.js",
"intl/date-format/time_style_hour_cycle.js",
"intl/date-format/format_range_hour_cycle.js",
"intl/date-format/en-format-range-to-parts.js",
"intl/general/getCanonicalLocales.js",
"intl/general/constructor.js",
"intl/number-format/rounding-mode-table-v3.js",
"intl/number-format/rounding-increment-value-v3.js",
"intl/number-format/use-grouping-v3.js",