mirror of
https://github.com/RGBCube/serenity
synced 2025-07-23 20:27:35 +00:00
LibJS: Move IsValidDurationRecord check to ToDurationRecord
This is an editorial change in the Intl.DurationFormat proposal. See:
fb21723
This commit is contained in:
parent
0086a3acdb
commit
85f079dc6b
2 changed files with 14 additions and 18 deletions
|
@ -173,7 +173,11 @@ ThrowCompletionOr<Temporal::DurationRecord> to_duration_record(VM& vm, Value inp
|
||||||
if (!any)
|
if (!any)
|
||||||
return vm.throw_completion<TypeError>(ErrorType::TemporalInvalidDurationLikeObject);
|
return vm.throw_completion<TypeError>(ErrorType::TemporalInvalidDurationLikeObject);
|
||||||
|
|
||||||
// 6. Return result.
|
// 6. If IsValidDurationRecord(result) is false, throw a RangeError exception.
|
||||||
|
if (!is_valid_duration_record(result))
|
||||||
|
return vm.throw_completion<RangeError>(ErrorType::TemporalInvalidDurationLikeObject);
|
||||||
|
|
||||||
|
// 7. Return result.
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -42,23 +42,19 @@ JS_DEFINE_NATIVE_FUNCTION(DurationFormatPrototype::format)
|
||||||
// 3. Let record be ? ToDurationRecord(duration).
|
// 3. Let record be ? ToDurationRecord(duration).
|
||||||
auto record = TRY(to_duration_record(vm, vm.argument(0)));
|
auto record = TRY(to_duration_record(vm, vm.argument(0)));
|
||||||
|
|
||||||
// 4. If IsValidDurationRecord(record) is false, throw a RangeError exception.
|
// 4. Let parts be PartitionDurationFormatPattern(df, record).
|
||||||
if (!is_valid_duration_record(record))
|
|
||||||
return vm.throw_completion<RangeError>(ErrorType::TemporalInvalidDurationLikeObject);
|
|
||||||
|
|
||||||
// 5. Let parts be PartitionDurationFormatPattern(df, record).
|
|
||||||
auto parts = partition_duration_format_pattern(vm, *duration_format, record);
|
auto parts = partition_duration_format_pattern(vm, *duration_format, record);
|
||||||
|
|
||||||
// 6. Let result be a new empty String.
|
// 5. Let result be a new empty String.
|
||||||
StringBuilder result;
|
StringBuilder result;
|
||||||
|
|
||||||
// 7. For each Record { [[Type]], [[Value]] } part in parts, do
|
// 6. For each Record { [[Type]], [[Value]] } part in parts, do
|
||||||
for (auto const& part : parts) {
|
for (auto const& part : parts) {
|
||||||
// a. Set result to the string-concatenation of result and part.[[Value]].
|
// a. Set result to the string-concatenation of result and part.[[Value]].
|
||||||
result.append(part.value);
|
result.append(part.value);
|
||||||
}
|
}
|
||||||
|
|
||||||
// 8. Return result.
|
// 7. Return result.
|
||||||
return PrimitiveString::create(vm, result.build());
|
return PrimitiveString::create(vm, result.build());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -74,18 +70,14 @@ JS_DEFINE_NATIVE_FUNCTION(DurationFormatPrototype::format_to_parts)
|
||||||
// 3. Let record be ? ToDurationRecord(duration).
|
// 3. Let record be ? ToDurationRecord(duration).
|
||||||
auto record = TRY(to_duration_record(vm, vm.argument(0)));
|
auto record = TRY(to_duration_record(vm, vm.argument(0)));
|
||||||
|
|
||||||
// 4. If IsValidDurationRecord(record) is false, throw a RangeError exception.
|
// 4. Let parts be PartitionDurationFormatPattern(df, record).
|
||||||
if (!is_valid_duration_record(record))
|
|
||||||
return vm.throw_completion<RangeError>(ErrorType::TemporalInvalidDurationLikeObject);
|
|
||||||
|
|
||||||
// 5. Let parts be PartitionDurationFormatPattern(df, record).
|
|
||||||
auto parts = partition_duration_format_pattern(vm, *duration_format, record);
|
auto parts = partition_duration_format_pattern(vm, *duration_format, record);
|
||||||
|
|
||||||
// 6. Let result be ! ArrayCreate(0).
|
// 5. Let result be ! ArrayCreate(0).
|
||||||
auto result = MUST(Array::create(realm, 0));
|
auto result = MUST(Array::create(realm, 0));
|
||||||
|
|
||||||
// 7. Let n be 0.
|
// 6. Let n be 0.
|
||||||
// 8. For each { [[Type]], [[Value]] } part in parts, do
|
// 7. For each { [[Type]], [[Value]] } part in parts, do
|
||||||
for (size_t n = 0; n < parts.size(); ++n) {
|
for (size_t n = 0; n < parts.size(); ++n) {
|
||||||
auto const& part = parts[n];
|
auto const& part = parts[n];
|
||||||
|
|
||||||
|
@ -104,7 +96,7 @@ JS_DEFINE_NATIVE_FUNCTION(DurationFormatPrototype::format_to_parts)
|
||||||
// e. Increment n by 1.
|
// e. Increment n by 1.
|
||||||
}
|
}
|
||||||
|
|
||||||
// 9. Return result.
|
// 8. Return result.
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue