1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-26 21:07:36 +00:00

LibJS: Pass valid offset string directly to CreateTemporalTimeZone

This is an editorial change in the Temporal spec.

See:
- 75490b9
- 8b70e4b
This commit is contained in:
Linus Groh 2022-01-22 21:35:08 +00:00
parent 6d744eb4a7
commit 31283b5e64
3 changed files with 34 additions and 31 deletions

View file

@ -22,9 +22,8 @@
namespace JS::Temporal {
// 11 Temporal.TimeZone Objects, https://tc39.es/proposal-temporal/#sec-temporal-timezone-objects
TimeZone::TimeZone(String identifier, Object& prototype)
TimeZone::TimeZone(Object& prototype)
: Object(prototype)
, m_identifier(move(identifier))
{
}
@ -71,22 +70,33 @@ ThrowCompletionOr<TimeZone*> create_temporal_time_zone(GlobalObject& global_obje
new_target = global_object.temporal_time_zone_constructor();
// 2. Let object be ? OrdinaryCreateFromConstructor(newTarget, "%Temporal.TimeZone.prototype%", « [[InitializedTemporalTimeZone]], [[Identifier]], [[OffsetNanoseconds]] »).
// 3. Set object.[[Identifier]] to identifier.
auto* object = TRY(ordinary_create_from_constructor<TimeZone>(global_object, *new_target, &GlobalObject::temporal_time_zone_prototype, identifier));
auto* object = TRY(ordinary_create_from_constructor<TimeZone>(global_object, *new_target, &GlobalObject::temporal_time_zone_prototype));
// 3. Let offsetNanosecondsResult be ParseTimeZoneOffsetString(identifier).
auto offset_nanoseconds_result = parse_time_zone_offset_string(global_object, identifier);
// 4. If offsetNanosecondsResult is an abrupt completion, then
if (offset_nanoseconds_result.is_throw_completion()) {
global_object.vm().clear_exception();
// 4. If identifier satisfies the syntax of a TimeZoneNumericUTCOffset (see 13.33), then
if (is_valid_time_zone_numeric_utc_offset_syntax(identifier)) {
// a. Set object.[[OffsetNanoseconds]] to ! ParseTimeZoneOffsetString(identifier).
object->set_offset_nanoseconds(TRY(parse_time_zone_offset_string(global_object, identifier)));
}
// 5. Else,
else {
// a. Assert: ! CanonicalizeTimeZoneName(identifier) is identifier.
VERIFY(canonicalize_time_zone_name(identifier) == identifier);
// b. Set object.[[OffsetNanoseconds]] to undefined.
// b. Set object.[[Identifier]] to identifier.
object->set_identifier(identifier);
// c. Set object.[[OffsetNanoseconds]] to undefined.
// NOTE: No-op.
}
// 5. Else,
else {
// a. Set object.[[Identifier]] to ! FormatTimeZoneOffsetString(identifier).
// TODO: `identifier` is wrong here. See: https://github.com/tc39/proposal-temporal/pull/2010
object->set_identifier(format_time_zone_offset_string(offset_nanoseconds_result.value()));
// b. Set object.[[OffsetNanoseconds]] to offsetNanosecondsResult.[[Value]].
object->set_offset_nanoseconds(offset_nanoseconds_result.value());
}
// 6. Return object.
return object;