11cb0ef41Sopenharmony_ci// Copyright 2021 the V8 project authors. All rights reserved. 21cb0ef41Sopenharmony_ci// Use of this source code is governed by a BSD-style license that can be 31cb0ef41Sopenharmony_ci// found in the LICENSE file. 41cb0ef41Sopenharmony_ci 51cb0ef41Sopenharmony_ci#ifndef V8_OBJECTS_JS_TEMPORAL_OBJECTS_INL_H_ 61cb0ef41Sopenharmony_ci#define V8_OBJECTS_JS_TEMPORAL_OBJECTS_INL_H_ 71cb0ef41Sopenharmony_ci 81cb0ef41Sopenharmony_ci#include "src/api/api-inl.h" 91cb0ef41Sopenharmony_ci#include "src/objects/js-temporal-objects.h" 101cb0ef41Sopenharmony_ci#include "src/objects/objects-inl.h" 111cb0ef41Sopenharmony_ci 121cb0ef41Sopenharmony_ci// Has to be the last include (doesn't have include guards): 131cb0ef41Sopenharmony_ci#include "src/objects/object-macros.h" 141cb0ef41Sopenharmony_ci 151cb0ef41Sopenharmony_cinamespace v8 { 161cb0ef41Sopenharmony_cinamespace internal { 171cb0ef41Sopenharmony_ci 181cb0ef41Sopenharmony_ci#include "torque-generated/src/objects/js-temporal-objects-tq-inl.inc" 191cb0ef41Sopenharmony_ci 201cb0ef41Sopenharmony_ci#define TEMPORAL_INLINE_GETTER_SETTER(T, data, field, lower, upper, B) \ 211cb0ef41Sopenharmony_ci inline void T::set_##field(int32_t field) { \ 221cb0ef41Sopenharmony_ci DCHECK_GE(upper, field); \ 231cb0ef41Sopenharmony_ci DCHECK_LE(lower, field); \ 241cb0ef41Sopenharmony_ci int hints = data(); \ 251cb0ef41Sopenharmony_ci hints = B##Bits::update(hints, field); \ 261cb0ef41Sopenharmony_ci set_##data(hints); \ 271cb0ef41Sopenharmony_ci } \ 281cb0ef41Sopenharmony_ci inline int32_t T::field() const { \ 291cb0ef41Sopenharmony_ci int32_t v = B##Bits::decode(data()); \ 301cb0ef41Sopenharmony_ci DCHECK_GE(upper, v); \ 311cb0ef41Sopenharmony_ci DCHECK_LE(lower, v); \ 321cb0ef41Sopenharmony_ci return v; \ 331cb0ef41Sopenharmony_ci } 341cb0ef41Sopenharmony_ci 351cb0ef41Sopenharmony_ci#define TEMPORAL_INLINE_SIGNED_GETTER_SETTER(T, data, field, lower, upper, B) \ 361cb0ef41Sopenharmony_ci inline void T::set_##field(int32_t field) { \ 371cb0ef41Sopenharmony_ci DCHECK_GE(upper, field); \ 381cb0ef41Sopenharmony_ci DCHECK_LE(lower, field); \ 391cb0ef41Sopenharmony_ci int hints = data(); \ 401cb0ef41Sopenharmony_ci /* Mask out unrelated bits */ \ 411cb0ef41Sopenharmony_ci field &= (static_cast<uint32_t>(int32_t{-1})) ^ \ 421cb0ef41Sopenharmony_ci (static_cast<uint32_t>(int32_t{-1}) << B##Bits::kSize); \ 431cb0ef41Sopenharmony_ci hints = B##Bits::update(hints, field); \ 441cb0ef41Sopenharmony_ci set_##data(hints); \ 451cb0ef41Sopenharmony_ci } \ 461cb0ef41Sopenharmony_ci inline int32_t T::field() const { \ 471cb0ef41Sopenharmony_ci int32_t v = B##Bits::decode(data()); \ 481cb0ef41Sopenharmony_ci /* Restore bits for negative values based on the MSB in that field */ \ 491cb0ef41Sopenharmony_ci v |= ((int32_t{1} << (B##Bits::kSize - 1) & v) \ 501cb0ef41Sopenharmony_ci ? (static_cast<uint32_t>(int32_t{-1}) << B##Bits::kSize) \ 511cb0ef41Sopenharmony_ci : 0); \ 521cb0ef41Sopenharmony_ci DCHECK_GE(upper, v); \ 531cb0ef41Sopenharmony_ci DCHECK_LE(lower, v); \ 541cb0ef41Sopenharmony_ci return v; \ 551cb0ef41Sopenharmony_ci } 561cb0ef41Sopenharmony_ci 571cb0ef41Sopenharmony_ci#define TEMPORAL_DATE_INLINE_GETTER_SETTER(T, data) \ 581cb0ef41Sopenharmony_ci TEMPORAL_INLINE_SIGNED_GETTER_SETTER(T, data, iso_year, -271821, 275760, \ 591cb0ef41Sopenharmony_ci IsoYear) \ 601cb0ef41Sopenharmony_ci TEMPORAL_INLINE_GETTER_SETTER(T, data, iso_month, 1, 12, IsoMonth) \ 611cb0ef41Sopenharmony_ci TEMPORAL_INLINE_GETTER_SETTER(T, data, iso_day, 1, 31, IsoDay) 621cb0ef41Sopenharmony_ci 631cb0ef41Sopenharmony_ci#define TEMPORAL_TIME_INLINE_GETTER_SETTER(T, data1, data2) \ 641cb0ef41Sopenharmony_ci TEMPORAL_INLINE_GETTER_SETTER(T, data1, iso_hour, 0, 23, IsoHour) \ 651cb0ef41Sopenharmony_ci TEMPORAL_INLINE_GETTER_SETTER(T, data1, iso_minute, 0, 59, IsoMinute) \ 661cb0ef41Sopenharmony_ci TEMPORAL_INLINE_GETTER_SETTER(T, data1, iso_second, 0, 59, IsoSecond) \ 671cb0ef41Sopenharmony_ci TEMPORAL_INLINE_GETTER_SETTER(T, data2, iso_millisecond, 0, 999, \ 681cb0ef41Sopenharmony_ci IsoMillisecond) \ 691cb0ef41Sopenharmony_ci TEMPORAL_INLINE_GETTER_SETTER(T, data2, iso_microsecond, 0, 999, \ 701cb0ef41Sopenharmony_ci IsoMicrosecond) \ 711cb0ef41Sopenharmony_ci TEMPORAL_INLINE_GETTER_SETTER(T, data2, iso_nanosecond, 0, 999, IsoNanosecond) 721cb0ef41Sopenharmony_ci 731cb0ef41Sopenharmony_ciTEMPORAL_DATE_INLINE_GETTER_SETTER(JSTemporalPlainDate, year_month_day) 741cb0ef41Sopenharmony_ciTEMPORAL_DATE_INLINE_GETTER_SETTER(JSTemporalPlainDateTime, year_month_day) 751cb0ef41Sopenharmony_ciTEMPORAL_TIME_INLINE_GETTER_SETTER(JSTemporalPlainDateTime, hour_minute_second, 761cb0ef41Sopenharmony_ci second_parts) 771cb0ef41Sopenharmony_ciTEMPORAL_DATE_INLINE_GETTER_SETTER(JSTemporalPlainMonthDay, year_month_day) 781cb0ef41Sopenharmony_ciTEMPORAL_TIME_INLINE_GETTER_SETTER(JSTemporalPlainTime, hour_minute_second, 791cb0ef41Sopenharmony_ci second_parts) 801cb0ef41Sopenharmony_ciTEMPORAL_DATE_INLINE_GETTER_SETTER(JSTemporalPlainYearMonth, year_month_day) 811cb0ef41Sopenharmony_ci 821cb0ef41Sopenharmony_ciTQ_OBJECT_CONSTRUCTORS_IMPL(JSTemporalCalendar) 831cb0ef41Sopenharmony_ciTQ_OBJECT_CONSTRUCTORS_IMPL(JSTemporalDuration) 841cb0ef41Sopenharmony_ciTQ_OBJECT_CONSTRUCTORS_IMPL(JSTemporalInstant) 851cb0ef41Sopenharmony_ciTQ_OBJECT_CONSTRUCTORS_IMPL(JSTemporalPlainDate) 861cb0ef41Sopenharmony_ciTQ_OBJECT_CONSTRUCTORS_IMPL(JSTemporalPlainDateTime) 871cb0ef41Sopenharmony_ciTQ_OBJECT_CONSTRUCTORS_IMPL(JSTemporalPlainMonthDay) 881cb0ef41Sopenharmony_ciTQ_OBJECT_CONSTRUCTORS_IMPL(JSTemporalPlainTime) 891cb0ef41Sopenharmony_ciTQ_OBJECT_CONSTRUCTORS_IMPL(JSTemporalPlainYearMonth) 901cb0ef41Sopenharmony_ciTQ_OBJECT_CONSTRUCTORS_IMPL(JSTemporalTimeZone) 911cb0ef41Sopenharmony_ciTQ_OBJECT_CONSTRUCTORS_IMPL(JSTemporalZonedDateTime) 921cb0ef41Sopenharmony_ci 931cb0ef41Sopenharmony_ciBIT_FIELD_ACCESSORS(JSTemporalCalendar, flags, calendar_index, 941cb0ef41Sopenharmony_ci JSTemporalCalendar::CalendarIndexBits) 951cb0ef41Sopenharmony_ci 961cb0ef41Sopenharmony_ciBOOL_ACCESSORS(JSTemporalTimeZone, flags, is_offset, IsOffsetBit::kShift) 971cb0ef41Sopenharmony_ci 981cb0ef41Sopenharmony_ci// Special handling of sign 991cb0ef41Sopenharmony_ciTEMPORAL_INLINE_SIGNED_GETTER_SETTER(JSTemporalTimeZone, flags, 1001cb0ef41Sopenharmony_ci offset_milliseconds, -24 * 60 * 60 * 1000, 1011cb0ef41Sopenharmony_ci 24 * 60 * 60 * 1000, 1021cb0ef41Sopenharmony_ci OffsetMillisecondsOrTimeZoneIndex) 1031cb0ef41Sopenharmony_ci 1041cb0ef41Sopenharmony_ciTEMPORAL_INLINE_SIGNED_GETTER_SETTER(JSTemporalTimeZone, details, 1051cb0ef41Sopenharmony_ci offset_sub_milliseconds, -1000000, 1000000, 1061cb0ef41Sopenharmony_ci OffsetSubMilliseconds) 1071cb0ef41Sopenharmony_ci 1081cb0ef41Sopenharmony_ciBIT_FIELD_ACCESSORS(JSTemporalTimeZone, flags, 1091cb0ef41Sopenharmony_ci offset_milliseconds_or_time_zone_index, 1101cb0ef41Sopenharmony_ci JSTemporalTimeZone::OffsetMillisecondsOrTimeZoneIndexBits) 1111cb0ef41Sopenharmony_ci 1121cb0ef41Sopenharmony_ci} // namespace internal 1131cb0ef41Sopenharmony_ci} // namespace v8 1141cb0ef41Sopenharmony_ci 1151cb0ef41Sopenharmony_ci#include "src/objects/object-macros-undef.h" 1161cb0ef41Sopenharmony_ci 1171cb0ef41Sopenharmony_ci#endif // V8_OBJECTS_JS_TEMPORAL_OBJECTS_INL_H_ 118