1// Copyright 2021 the V8 project authors. All rights reserved. 2// Use of this source code is governed by a BSD-style license that can be 3// found in the LICENSE file. 4 5#ifndef V8_OBJECTS_JS_TEMPORAL_OBJECTS_INL_H_ 6#define V8_OBJECTS_JS_TEMPORAL_OBJECTS_INL_H_ 7 8#include "src/api/api-inl.h" 9#include "src/objects/js-temporal-objects.h" 10#include "src/objects/objects-inl.h" 11 12// Has to be the last include (doesn't have include guards): 13#include "src/objects/object-macros.h" 14 15namespace v8 { 16namespace internal { 17 18#include "torque-generated/src/objects/js-temporal-objects-tq-inl.inc" 19 20#define TEMPORAL_INLINE_GETTER_SETTER(T, data, field, lower, upper, B) \ 21 inline void T::set_##field(int32_t field) { \ 22 DCHECK_GE(upper, field); \ 23 DCHECK_LE(lower, field); \ 24 int hints = data(); \ 25 hints = B##Bits::update(hints, field); \ 26 set_##data(hints); \ 27 } \ 28 inline int32_t T::field() const { \ 29 int32_t v = B##Bits::decode(data()); \ 30 DCHECK_GE(upper, v); \ 31 DCHECK_LE(lower, v); \ 32 return v; \ 33 } 34 35#define TEMPORAL_INLINE_SIGNED_GETTER_SETTER(T, data, field, lower, upper, B) \ 36 inline void T::set_##field(int32_t field) { \ 37 DCHECK_GE(upper, field); \ 38 DCHECK_LE(lower, field); \ 39 int hints = data(); \ 40 /* Mask out unrelated bits */ \ 41 field &= (static_cast<uint32_t>(int32_t{-1})) ^ \ 42 (static_cast<uint32_t>(int32_t{-1}) << B##Bits::kSize); \ 43 hints = B##Bits::update(hints, field); \ 44 set_##data(hints); \ 45 } \ 46 inline int32_t T::field() const { \ 47 int32_t v = B##Bits::decode(data()); \ 48 /* Restore bits for negative values based on the MSB in that field */ \ 49 v |= ((int32_t{1} << (B##Bits::kSize - 1) & v) \ 50 ? (static_cast<uint32_t>(int32_t{-1}) << B##Bits::kSize) \ 51 : 0); \ 52 DCHECK_GE(upper, v); \ 53 DCHECK_LE(lower, v); \ 54 return v; \ 55 } 56 57#define TEMPORAL_DATE_INLINE_GETTER_SETTER(T, data) \ 58 TEMPORAL_INLINE_SIGNED_GETTER_SETTER(T, data, iso_year, -271821, 275760, \ 59 IsoYear) \ 60 TEMPORAL_INLINE_GETTER_SETTER(T, data, iso_month, 1, 12, IsoMonth) \ 61 TEMPORAL_INLINE_GETTER_SETTER(T, data, iso_day, 1, 31, IsoDay) 62 63#define TEMPORAL_TIME_INLINE_GETTER_SETTER(T, data1, data2) \ 64 TEMPORAL_INLINE_GETTER_SETTER(T, data1, iso_hour, 0, 23, IsoHour) \ 65 TEMPORAL_INLINE_GETTER_SETTER(T, data1, iso_minute, 0, 59, IsoMinute) \ 66 TEMPORAL_INLINE_GETTER_SETTER(T, data1, iso_second, 0, 59, IsoSecond) \ 67 TEMPORAL_INLINE_GETTER_SETTER(T, data2, iso_millisecond, 0, 999, \ 68 IsoMillisecond) \ 69 TEMPORAL_INLINE_GETTER_SETTER(T, data2, iso_microsecond, 0, 999, \ 70 IsoMicrosecond) \ 71 TEMPORAL_INLINE_GETTER_SETTER(T, data2, iso_nanosecond, 0, 999, IsoNanosecond) 72 73TEMPORAL_DATE_INLINE_GETTER_SETTER(JSTemporalPlainDate, year_month_day) 74TEMPORAL_DATE_INLINE_GETTER_SETTER(JSTemporalPlainDateTime, year_month_day) 75TEMPORAL_TIME_INLINE_GETTER_SETTER(JSTemporalPlainDateTime, hour_minute_second, 76 second_parts) 77TEMPORAL_DATE_INLINE_GETTER_SETTER(JSTemporalPlainMonthDay, year_month_day) 78TEMPORAL_TIME_INLINE_GETTER_SETTER(JSTemporalPlainTime, hour_minute_second, 79 second_parts) 80TEMPORAL_DATE_INLINE_GETTER_SETTER(JSTemporalPlainYearMonth, year_month_day) 81 82TQ_OBJECT_CONSTRUCTORS_IMPL(JSTemporalCalendar) 83TQ_OBJECT_CONSTRUCTORS_IMPL(JSTemporalDuration) 84TQ_OBJECT_CONSTRUCTORS_IMPL(JSTemporalInstant) 85TQ_OBJECT_CONSTRUCTORS_IMPL(JSTemporalPlainDate) 86TQ_OBJECT_CONSTRUCTORS_IMPL(JSTemporalPlainDateTime) 87TQ_OBJECT_CONSTRUCTORS_IMPL(JSTemporalPlainMonthDay) 88TQ_OBJECT_CONSTRUCTORS_IMPL(JSTemporalPlainTime) 89TQ_OBJECT_CONSTRUCTORS_IMPL(JSTemporalPlainYearMonth) 90TQ_OBJECT_CONSTRUCTORS_IMPL(JSTemporalTimeZone) 91TQ_OBJECT_CONSTRUCTORS_IMPL(JSTemporalZonedDateTime) 92 93BIT_FIELD_ACCESSORS(JSTemporalCalendar, flags, calendar_index, 94 JSTemporalCalendar::CalendarIndexBits) 95 96BOOL_ACCESSORS(JSTemporalTimeZone, flags, is_offset, IsOffsetBit::kShift) 97 98// Special handling of sign 99TEMPORAL_INLINE_SIGNED_GETTER_SETTER(JSTemporalTimeZone, flags, 100 offset_milliseconds, -24 * 60 * 60 * 1000, 101 24 * 60 * 60 * 1000, 102 OffsetMillisecondsOrTimeZoneIndex) 103 104TEMPORAL_INLINE_SIGNED_GETTER_SETTER(JSTemporalTimeZone, details, 105 offset_sub_milliseconds, -1000000, 1000000, 106 OffsetSubMilliseconds) 107 108BIT_FIELD_ACCESSORS(JSTemporalTimeZone, flags, 109 offset_milliseconds_or_time_zone_index, 110 JSTemporalTimeZone::OffsetMillisecondsOrTimeZoneIndexBits) 111 112} // namespace internal 113} // namespace v8 114 115#include "src/objects/object-macros-undef.h" 116 117#endif // V8_OBJECTS_JS_TEMPORAL_OBJECTS_INL_H_ 118