mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 17:37:34 +00:00
LibJS: Store Instant's and ZonedDateTime's m_nanoseconds as a const&
There's no need for these to be non-const. Suggested by @IdanHo in https://github.com/SerenityOS/serenity/pull/9904#discussion_r704960184. Perhaps we can make more internal slots of these and other objects const references as well, but that's a bit more involved as they are used by various functions expecting non-const references.
This commit is contained in:
parent
e4c07c5b8f
commit
5ae6ad8557
4 changed files with 12 additions and 14 deletions
|
@ -20,7 +20,7 @@
|
|||
namespace JS::Temporal {
|
||||
|
||||
// 8 Temporal.Instant Objects, https://tc39.es/proposal-temporal/#sec-temporal-instant-objects
|
||||
Instant::Instant(BigInt& nanoseconds, Object& prototype)
|
||||
Instant::Instant(BigInt const& nanoseconds, Object& prototype)
|
||||
: Object(prototype)
|
||||
, m_nanoseconds(nanoseconds)
|
||||
{
|
||||
|
@ -49,7 +49,7 @@ bool is_valid_epoch_nanoseconds(BigInt const& epoch_nanoseconds)
|
|||
}
|
||||
|
||||
// 8.5.2 CreateTemporalInstant ( epochNanoseconds [ , newTarget ] ), https://tc39.es/proposal-temporal/#sec-temporal-createtemporalinstant
|
||||
Instant* create_temporal_instant(GlobalObject& global_object, BigInt& epoch_nanoseconds, FunctionObject const* new_target)
|
||||
Instant* create_temporal_instant(GlobalObject& global_object, BigInt const& epoch_nanoseconds, FunctionObject const* new_target)
|
||||
{
|
||||
auto& vm = global_object.vm();
|
||||
|
||||
|
|
|
@ -18,17 +18,16 @@ class Instant final : public Object {
|
|||
JS_OBJECT(Instant, Object);
|
||||
|
||||
public:
|
||||
Instant(BigInt& nanoseconds, Object& prototype);
|
||||
Instant(BigInt const& nanoseconds, Object& prototype);
|
||||
virtual ~Instant() override = default;
|
||||
|
||||
[[nodiscard]] BigInt const& nanoseconds() const { return m_nanoseconds; }
|
||||
[[nodiscard]] BigInt& nanoseconds() { return m_nanoseconds; }
|
||||
|
||||
private:
|
||||
virtual void visit_edges(Visitor&) override;
|
||||
|
||||
// 8.4 Properties of Temporal.Instant Instances, https://tc39.es/proposal-temporal/#sec-properties-of-temporal-instant-instances
|
||||
BigInt& m_nanoseconds; // [[Nanoseconds]]
|
||||
BigInt const& m_nanoseconds; // [[Nanoseconds]]
|
||||
};
|
||||
|
||||
// -86400 * 10^17
|
||||
|
@ -37,7 +36,7 @@ const auto INSTANT_NANOSECONDS_MIN = "-8640000000000000000000"_sbigint;
|
|||
const auto INSTANT_NANOSECONDS_MAX = "8640000000000000000000"_sbigint;
|
||||
|
||||
bool is_valid_epoch_nanoseconds(BigInt const& epoch_nanoseconds);
|
||||
Instant* create_temporal_instant(GlobalObject&, BigInt& nanoseconds, FunctionObject const* new_target = nullptr);
|
||||
Instant* create_temporal_instant(GlobalObject&, BigInt const& nanoseconds, FunctionObject const* new_target = nullptr);
|
||||
Instant* to_temporal_instant(GlobalObject&, Value item);
|
||||
BigInt* parse_temporal_instant(GlobalObject&, String const& iso_string);
|
||||
i32 compare_epoch_nanoseconds(BigInt const&, BigInt const&);
|
||||
|
|
|
@ -13,7 +13,7 @@
|
|||
namespace JS::Temporal {
|
||||
|
||||
// 6 Temporal.ZonedDateTime Objects, https://tc39.es/proposal-temporal/#sec-temporal-zoneddatetime-objects
|
||||
ZonedDateTime::ZonedDateTime(BigInt& nanoseconds, Object& time_zone, Object& calendar, Object& prototype)
|
||||
ZonedDateTime::ZonedDateTime(BigInt const& nanoseconds, Object& time_zone, Object& calendar, Object& prototype)
|
||||
: Object(prototype)
|
||||
, m_nanoseconds(nanoseconds)
|
||||
, m_time_zone(time_zone)
|
||||
|
@ -31,7 +31,7 @@ void ZonedDateTime::visit_edges(Cell::Visitor& visitor)
|
|||
}
|
||||
|
||||
// 6.5.3 CreateTemporalZonedDateTime ( epochNanoseconds, timeZone, calendar [ , newTarget ] ), https://tc39.es/proposal-temporal/#sec-temporal-createtemporalzoneddatetime
|
||||
ZonedDateTime* create_temporal_zoned_date_time(GlobalObject& global_object, BigInt& epoch_nanoseconds, Object& time_zone, Object& calendar, FunctionObject const* new_target)
|
||||
ZonedDateTime* create_temporal_zoned_date_time(GlobalObject& global_object, BigInt const& epoch_nanoseconds, Object& time_zone, Object& calendar, FunctionObject const* new_target)
|
||||
{
|
||||
auto& vm = global_object.vm();
|
||||
|
||||
|
|
|
@ -15,11 +15,10 @@ class ZonedDateTime final : public Object {
|
|||
JS_OBJECT(ZonedDateTime, Object);
|
||||
|
||||
public:
|
||||
ZonedDateTime(BigInt& nanoseconds, Object& time_zone, Object& calendar, Object& prototype);
|
||||
ZonedDateTime(BigInt const& nanoseconds, Object& time_zone, Object& calendar, Object& prototype);
|
||||
virtual ~ZonedDateTime() override = default;
|
||||
|
||||
[[nodiscard]] BigInt const& nanoseconds() const { return m_nanoseconds; }
|
||||
[[nodiscard]] BigInt& nanoseconds() { return m_nanoseconds; }
|
||||
[[nodiscard]] Object const& time_zone() const { return m_time_zone; }
|
||||
[[nodiscard]] Object& time_zone() { return m_time_zone; }
|
||||
[[nodiscard]] Object const& calendar() const { return m_calendar; }
|
||||
|
@ -29,11 +28,11 @@ private:
|
|||
virtual void visit_edges(Visitor&) override;
|
||||
|
||||
// 6.4 Properties of Temporal.ZonedDateTime Instances, https://tc39.es/proposal-temporal/#sec-properties-of-temporal-zoneddatetime-instances
|
||||
BigInt& m_nanoseconds; // [[Nanoseconds]]
|
||||
Object& m_time_zone; // [[TimeZone]]
|
||||
Object& m_calendar; // [[Calendar]]
|
||||
BigInt const& m_nanoseconds; // [[Nanoseconds]]
|
||||
Object& m_time_zone; // [[TimeZone]]
|
||||
Object& m_calendar; // [[Calendar]]
|
||||
};
|
||||
|
||||
ZonedDateTime* create_temporal_zoned_date_time(GlobalObject&, BigInt& epoch_nanoseconds, Object& time_zone, Object& calendar, FunctionObject const* new_target = nullptr);
|
||||
ZonedDateTime* create_temporal_zoned_date_time(GlobalObject&, BigInt const& epoch_nanoseconds, Object& time_zone, Object& calendar, FunctionObject const* new_target = nullptr);
|
||||
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue