mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 01:17:35 +00:00
LibJS: Add missing check in ParseTemporalInstant
This is an editorial change in the Temporal spec.
See: baead4d
This commit is contained in:
parent
f75052ff7c
commit
55f9733316
2 changed files with 27 additions and 2 deletions
|
@ -127,8 +127,17 @@ ThrowCompletionOr<BigInt*> parse_temporal_instant(GlobalObject& global_object, S
|
||||||
// 7. Let offsetNanoseconds be ? ParseTimeZoneOffsetString(offsetString).
|
// 7. Let offsetNanoseconds be ? ParseTimeZoneOffsetString(offsetString).
|
||||||
auto offset_nanoseconds = TRY(parse_time_zone_offset_string(global_object, *offset_string));
|
auto offset_nanoseconds = TRY(parse_time_zone_offset_string(global_object, *offset_string));
|
||||||
|
|
||||||
// 8. Return utc − offsetNanoseconds.
|
// 8. Let result be utc − offsetNanoseconds.
|
||||||
return js_bigint(vm, utc->big_integer().minus(Crypto::SignedBigInteger::create_from(offset_nanoseconds)));
|
auto* result_ns = js_bigint(vm, utc->big_integer().minus(Crypto::SignedBigInteger::create_from(offset_nanoseconds)));
|
||||||
|
|
||||||
|
// 9. If ! IsValidEpochNanoseconds(ℤ(result)) is false, then
|
||||||
|
if (!is_valid_epoch_nanoseconds(*result_ns)) {
|
||||||
|
// a. Throw a RangeError exception.
|
||||||
|
return vm.throw_completion<RangeError>(global_object, ErrorType::TemporalInvalidEpochNanoseconds);
|
||||||
|
}
|
||||||
|
|
||||||
|
// 10. Return result.
|
||||||
|
return result_ns;
|
||||||
}
|
}
|
||||||
|
|
||||||
// 8.5.5 CompareEpochNanoseconds ( epochNanosecondsOne, epochNanosecondsTwo ), https://tc39.es/proposal-temporal/#sec-temporal-compareepochnanoseconds
|
// 8.5.5 CompareEpochNanoseconds ( epochNanosecondsOne, epochNanosecondsTwo ), https://tc39.es/proposal-temporal/#sec-temporal-compareepochnanoseconds
|
||||||
|
|
|
@ -32,4 +32,20 @@ describe("errors", () => {
|
||||||
Temporal.Instant.from("foo");
|
Temporal.Instant.from("foo");
|
||||||
}).toThrowWithMessage(RangeError, "Invalid instant string 'foo'");
|
}).toThrowWithMessage(RangeError, "Invalid instant string 'foo'");
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test("invalid epoch nanoseconds", () => {
|
||||||
|
// Test cases from https://github.com/tc39/proposal-temporal/commit/baead4d85bc3e9ecab1e9824c3d3fe4fdd77fc3a
|
||||||
|
expect(() => {
|
||||||
|
Temporal.Instant.from("-271821-04-20T00:00:00+00:01");
|
||||||
|
}).toThrowWithMessage(
|
||||||
|
RangeError,
|
||||||
|
"Invalid epoch nanoseconds value, must be in range -86400 * 10^17 to 86400 * 10^17"
|
||||||
|
);
|
||||||
|
expect(() => {
|
||||||
|
Temporal.Instant.from("+275760-09-13T00:00:00-00:01");
|
||||||
|
}).toThrowWithMessage(
|
||||||
|
RangeError,
|
||||||
|
"Invalid epoch nanoseconds value, must be in range -86400 * 10^17 to 86400 * 10^17"
|
||||||
|
);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue