|
@@ -42,23 +42,19 @@ JS_DEFINE_NATIVE_FUNCTION(DurationFormatPrototype::format)
|
|
|
// 3. Let record be ? ToDurationRecord(duration).
|
|
|
auto record = TRY(to_duration_record(vm, vm.argument(0)));
|
|
|
|
|
|
- // 4. If IsValidDurationRecord(record) is false, throw a RangeError exception.
|
|
|
- if (!is_valid_duration_record(record))
|
|
|
- return vm.throw_completion<RangeError>(ErrorType::TemporalInvalidDurationLikeObject);
|
|
|
-
|
|
|
- // 5. Let parts be PartitionDurationFormatPattern(df, record).
|
|
|
+ // 4. Let parts be PartitionDurationFormatPattern(df, 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;
|
|
|
|
|
|
- // 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) {
|
|
|
// a. Set result to the string-concatenation of result and part.[[Value]].
|
|
|
result.append(part.value);
|
|
|
}
|
|
|
|
|
|
- // 8. Return result.
|
|
|
+ // 7. Return result.
|
|
|
return PrimitiveString::create(vm, result.build());
|
|
|
}
|
|
|
|
|
@@ -74,18 +70,14 @@ JS_DEFINE_NATIVE_FUNCTION(DurationFormatPrototype::format_to_parts)
|
|
|
// 3. Let record be ? ToDurationRecord(duration).
|
|
|
auto record = TRY(to_duration_record(vm, vm.argument(0)));
|
|
|
|
|
|
- // 4. If IsValidDurationRecord(record) is false, throw a RangeError exception.
|
|
|
- if (!is_valid_duration_record(record))
|
|
|
- return vm.throw_completion<RangeError>(ErrorType::TemporalInvalidDurationLikeObject);
|
|
|
-
|
|
|
- // 5. Let parts be PartitionDurationFormatPattern(df, record).
|
|
|
+ // 4. Let parts be PartitionDurationFormatPattern(df, 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));
|
|
|
|
|
|
- // 7. Let n be 0.
|
|
|
- // 8. For each { [[Type]], [[Value]] } part in parts, do
|
|
|
+ // 6. Let n be 0.
|
|
|
+ // 7. For each { [[Type]], [[Value]] } part in parts, do
|
|
|
for (size_t n = 0; n < parts.size(); ++n) {
|
|
|
auto const& part = parts[n];
|
|
|
|
|
@@ -104,7 +96,7 @@ JS_DEFINE_NATIVE_FUNCTION(DurationFormatPrototype::format_to_parts)
|
|
|
// e. Increment n by 1.
|
|
|
}
|
|
|
|
|
|
- // 9. Return result.
|
|
|
+ // 8. Return result.
|
|
|
return result;
|
|
|
}
|
|
|
|