| 1 |
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- |
| 2 |
* vim: set ts=8 sts=2 et sw=2 tw=80: |
| 3 |
* This Source Code Form is subject to the terms of the Mozilla Public |
| 4 |
* License, v. 2.0. If a copy of the MPL was not distributed with this |
| 5 |
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
| 6 |
|
| 7 |
#include "builtin/temporal/PlainDateTime.h" |
| 8 |
|
| 9 |
#include "mozilla/Assertions.h" |
| 10 |
#include "mozilla/Casting.h" |
| 11 |
#include "mozilla/EnumSet.h" |
| 12 |
|
| 13 |
#include <algorithm> |
| 14 |
#include <utility> |
| 15 |
|
| 16 |
#include "jspubtd.h" |
| 17 |
#include "NamespaceImports.h" |
| 18 |
|
| 19 |
#include "builtin/intl/DateTimeFormat.h" |
| 20 |
#include "builtin/temporal/Calendar.h" |
| 21 |
#include "builtin/temporal/CalendarFields.h" |
| 22 |
#include "builtin/temporal/Duration.h" |
| 23 |
#include "builtin/temporal/Instant.h" |
| 24 |
#include "builtin/temporal/PlainDate.h" |
| 25 |
#include "builtin/temporal/PlainMonthDay.h" |
| 26 |
#include "builtin/temporal/PlainTime.h" |
| 27 |
#include "builtin/temporal/PlainYearMonth.h" |
| 28 |
#include "builtin/temporal/Temporal.h" |
| 29 |
#include "builtin/temporal/TemporalParser.h" |
| 30 |
#include "builtin/temporal/TemporalRoundingMode.h" |
| 31 |
#include "builtin/temporal/TemporalTypes.h" |
| 32 |
#include "builtin/temporal/TemporalUnit.h" |
| 33 |
#include "builtin/temporal/TimeZone.h" |
| 34 |
#include "builtin/temporal/ToString.h" |
| 35 |
#include "builtin/temporal/ZonedDateTime.h" |
| 36 |
#include "gc/AllocKind.h" |
| 37 |
#include "gc/Barrier.h" |
| 38 |
#include "gc/GCEnum.h" |
| 39 |
#include "js/CallArgs.h" |
| 40 |
#include "js/CallNonGenericMethod.h" |
| 41 |
#include "js/Class.h" |
| 42 |
#include "js/ErrorReport.h" |
| 43 |
#include "js/friend/ErrorMessages.h" |
| 44 |
#include "js/PropertyDescriptor.h" |
| 45 |
#include "js/PropertySpec.h" |
| 46 |
#include "js/RootingAPI.h" |
| 47 |
#include "js/TypeDecls.h" |
| 48 |
#include "js/Value.h" |
| 49 |
#include "vm/BytecodeUtil.h" |
| 50 |
#include "vm/GlobalObject.h" |
| 51 |
#include "vm/JSAtomState.h" |
| 52 |
#include "vm/JSContext.h" |
| 53 |
#include "vm/JSObject.h" |
| 54 |
#include "vm/PlainObject.h" |
| 55 |
#include "vm/StringType.h" |
| 56 |
|
| 57 |
#include "vm/JSObject-inl.h" |
| 58 |
#include "vm/NativeObject-inl.h" |
| 59 |
|
| 60 |
using namespace js; |
| 61 |
using namespace js::temporal; |
| 62 |
|
| 63 |
static inline bool IsPlainDateTime(Handle<Value> v) { |
| 64 |
return v.isObject() && v.toObject().is<PlainDateTimeObject>(); |
| 65 |
} |
| 66 |
|
| 67 |
#ifdef DEBUG |
| 68 |
/** |
| 69 |
* IsValidISODate ( year, month, day ) |
| 70 |
* IsValidTime ( hour, minute, second, millisecond, microsecond, nanosecond ) |
| 71 |
*/ |
| 72 |
bool js::temporal::IsValidISODateTime(const ISODateTime& isoDateTime) { |
| 73 |
return IsValidISODate(isoDateTime.date) && IsValidTime(isoDateTime.time); |
| 74 |
} |
| 75 |
#endif |
| 76 |
|
| 77 |
/** |
| 78 |
* ISODateTimeWithinLimits ( isoDateTime ) |
| 79 |
*/ |
| 80 |
bool js::temporal::ISODateTimeWithinLimits(const ISODateTime& isoDateTime) { |
| 81 |
MOZ_ASSERT(IsValidISODateTime(isoDateTime)); |
| 82 |
|
| 83 |
constexpr auto min = ISODate::min(); |
| 84 |
constexpr auto max = ISODate::max(); |
| 85 |
|
| 86 |
const auto& year = isoDateTime.date.year; |
| 87 |
|
| 88 |
// Fast-path when the input is definitely in range. |
| 89 |
if (min.year < year && year < max.year) { |
| 90 |
return true; |
| 91 |
} |
| 92 |
|
| 93 |
// Check |isoDateTime| is within the valid limits. |
| 94 |
if (year < 0) { |
| 95 |
if (isoDateTime.date != min) { |
| 96 |
return isoDateTime.date > min; |
| 97 |
} |
| 98 |
|
| 99 |
// Needs to be past midnight. |
| 100 |
return isoDateTime.time != Time{}; |
| 101 |
} |
| 102 |
return isoDateTime.date <= max; |
| 103 |
} |
| 104 |
|
| 105 |
/** |
| 106 |
* CreateTemporalDateTime ( isoDateTime, calendar [ , newTarget ] ) |
| 107 |
*/ |
| 108 |
static PlainDateTimeObject* CreateTemporalDateTime( |
| 109 |
JSContext* cx, const CallArgs& args, const ISODateTime& isoDateTime, |
| 110 |
Handle<CalendarValue> calendar) { |
| 111 |
MOZ_ASSERT(IsValidISODateTime(isoDateTime)); |
| 112 |
|
| 113 |
// Step 1. |
| 114 |
if (!ISODateTimeWithinLimits(isoDateTime)) { |
| 115 |
JS_ReportErrorNumberASCII(cx, GetErrorMessage, nullptr, |
| 116 |
JSMSG_TEMPORAL_PLAIN_DATE_TIME_INVALID); |
| 117 |
return nullptr; |
| 118 |
} |
| 119 |
|
| 120 |
// Steps 2-3. |
| 121 |
Rooted<JSObject*> proto(cx); |
| 122 |
if (!GetPrototypeFromBuiltinConstructor(cx, args, JSProto_PlainDateTime, |
| 123 |
&proto)) { |
| 124 |
return nullptr; |
| 125 |
} |
| 126 |
|
| 127 |
auto* object = NewObjectWithClassProto<PlainDateTimeObject>(cx, proto); |
| 128 |
if (!object) { |
| 129 |
return nullptr; |
| 130 |
} |
| 131 |
|
| 132 |
// Step 4. |
| 133 |
auto packedDate = PackedDate::pack(isoDateTime.date); |
| 134 |
auto packedTime = PackedTime::pack(isoDateTime.time); |
| 135 |
object->setFixedSlot(PlainDateTimeObject::PACKED_DATE_SLOT, |
| 136 |
PrivateUint32Value(packedDate.value)); |
| 137 |
object->setFixedSlot( |
| 138 |
PlainDateTimeObject::PACKED_TIME_SLOT, |
| 139 |
DoubleValue(mozilla::BitwiseCast<double>(packedTime.value))); |
| 140 |
|
| 141 |
// Step 5. |
| 142 |
object->setFixedSlot(PlainDateTimeObject::CALENDAR_SLOT, |
| 143 |
calendar.toSlotValue()); |
| 144 |
|
| 145 |
// Step 6. |
| 146 |
return object; |
| 147 |
} |
| 148 |
|
| 149 |
/** |
| 150 |
* CreateTemporalDateTime ( isoDateTime, calendar [ , newTarget ] ) |
| 151 |
*/ |
| 152 |
PlainDateTimeObject* js::temporal::CreateTemporalDateTime( |
| 153 |
JSContext* cx, const ISODateTime& isoDateTime, |
| 154 |
Handle<CalendarValue> calendar) { |
| 155 |
MOZ_ASSERT(IsValidISODateTime(isoDateTime)); |
| 156 |
|
| 157 |
// Step 1. |
| 158 |
if (!ISODateTimeWithinLimits(isoDateTime)) { |
| 159 |
JS_ReportErrorNumberASCII(cx, GetErrorMessage, nullptr, |
| 160 |
JSMSG_TEMPORAL_PLAIN_DATE_TIME_INVALID); |
| 161 |
return nullptr; |
| 162 |
} |
| 163 |
|
| 164 |
// Steps 2-3. |
| 165 |
auto* object = NewBuiltinClassInstance<PlainDateTimeObject>(cx); |
| 166 |
if (!object) { |
| 167 |
return nullptr; |
| 168 |
} |
| 169 |
|
| 170 |
// Step 4. |
| 171 |
auto packedDate = PackedDate::pack(isoDateTime.date); |
| 172 |
auto packedTime = PackedTime::pack(isoDateTime.time); |
| 173 |
object->setFixedSlot(PlainDateTimeObject::PACKED_DATE_SLOT, |
| 174 |
PrivateUint32Value(packedDate.value)); |
| 175 |
object->setFixedSlot( |
| 176 |
PlainDateTimeObject::PACKED_TIME_SLOT, |
| 177 |
DoubleValue(mozilla::BitwiseCast<double>(packedTime.value))); |
| 178 |
|
| 179 |
// Step 5. |
| 180 |
object->setFixedSlot(PlainDateTimeObject::CALENDAR_SLOT, |
| 181 |
calendar.toSlotValue()); |
| 182 |
|
| 183 |
// Step 6. |
| 184 |
return object; |
| 185 |
} |
| 186 |
|
| 187 |
/** |
| 188 |
* CreateTemporalDateTime ( isoDateTime, calendar [ , newTarget ] ) |
| 189 |
*/ |
| 190 |
static PlainDateTimeObject* CreateTemporalDateTime( |
| 191 |
JSContext* cx, Handle<PlainDateTime> dateTime) { |
| 192 |
MOZ_ASSERT(ISODateTimeWithinLimits(dateTime)); |
| 193 |
return CreateTemporalDateTime(cx, dateTime, dateTime.calendar()); |
| 194 |
} |
| 195 |
|
| 196 |
/** |
| 197 |
* CreateTemporalDateTime ( isoDateTime, calendar [ , newTarget ] ) |
| 198 |
*/ |
| 199 |
static bool CreateTemporalDateTime(JSContext* cx, const ISODateTime& dateTime, |
| 200 |
Handle<CalendarValue> calendar, |
| 201 |
MutableHandle<PlainDateTime> result) { |
| 202 |
MOZ_ASSERT(IsValidISODateTime(dateTime)); |
| 203 |
|
| 204 |
// Step 1. |
| 205 |
if (!ISODateTimeWithinLimits(dateTime)) { |
| 206 |
JS_ReportErrorNumberASCII(cx, GetErrorMessage, nullptr, |
| 207 |
JSMSG_TEMPORAL_PLAIN_DATE_TIME_INVALID); |
| 208 |
return false; |
| 209 |
} |
| 210 |
|
| 211 |
// Step 2-6. |
| 212 |
result.set(PlainDateTime{dateTime, calendar}); |
| 213 |
return true; |
| 214 |
} |
| 215 |
|
| 216 |
/** |
| 217 |
* InterpretTemporalDateTimeFields ( calendar, fields, overflow ) |
| 218 |
*/ |
| 219 |
bool js::temporal::InterpretTemporalDateTimeFields( |
| 220 |
JSContext* cx, Handle<CalendarValue> calendar, |
| 221 |
Handle<CalendarFields> fields, TemporalOverflow overflow, |
| 222 |
ISODateTime* result) { |
| 223 |
// Step 1. |
| 224 |
Rooted<PlainDate> temporalDate(cx); |
| 225 |
if (!CalendarDateFromFields(cx, calendar, fields, overflow, &temporalDate)) { |
| 226 |
return false; |
| 227 |
} |
| 228 |
|
| 229 |
// Step 2. |
| 230 |
auto timeLike = TemporalTimeLike{ |
| 231 |
fields.hour(), fields.minute(), fields.second(), |
| 232 |
fields.millisecond(), fields.microsecond(), fields.nanosecond(), |
| 233 |
}; |
| 234 |
Time time; |
| 235 |
if (!RegulateTime(cx, timeLike, overflow, &time)) { |
| 236 |
return false; |
| 237 |
} |
| 238 |
|
| 239 |
// Step 3. |
| 240 |
*result = {temporalDate.date(), time}; |
| 241 |
return true; |
| 242 |
} |
| 243 |
|
| 244 |
struct DateTimeOptions { |
| 245 |
TemporalOverflow overflow = TemporalOverflow::Constrain; |
| 246 |
}; |
| 247 |
|
| 248 |
/** |
| 249 |
* ToTemporalDateTime ( item [ , options ] ) |
| 250 |
*/ |
| 251 |
static bool ToTemporalDateTimeOptions(JSContext* cx, Handle<Value> options, |
| 252 |
DateTimeOptions* result) { |
| 253 |
if (options.isUndefined()) { |
| 254 |
*result = {}; |
| 255 |
return true; |
| 256 |
} |
| 257 |
|
| 258 |
// NOTE: |options| are only passed from `Temporal.PlainDateTime.from`. |
| 259 |
|
| 260 |
Rooted<JSObject*> resolvedOptions( |
| 261 |
cx, RequireObjectArg(cx, "options", "from", options)); |
| 262 |
if (!resolvedOptions) { |
| 263 |
return false; |
| 264 |
} |
| 265 |
|
| 266 |
auto overflow = TemporalOverflow::Constrain; |
| 267 |
if (!GetTemporalOverflowOption(cx, resolvedOptions, &overflow)) { |
| 268 |
return false; |
| 269 |
} |
| 270 |
|
| 271 |
*result = {overflow}; |
| 272 |
return true; |
| 273 |
} |
| 274 |
|
| 275 |
/** |
| 276 |
* ToTemporalDateTime ( item [ , options ] ) |
| 277 |
*/ |
| 278 |
static bool ToTemporalDateTime(JSContext* cx, Handle<JSObject*> item, |
| 279 |
Handle<Value> options, |
| 280 |
MutableHandle<PlainDateTime> result) { |
| 281 |
// Step 1. (Not applicable in our implementation.) |
| 282 |
|
| 283 |
// Step 2.a. |
| 284 |
if (auto* plainDateTime = item->maybeUnwrapIf<PlainDateTimeObject>()) { |
| 285 |
auto dateTime = plainDateTime->dateTime(); |
| 286 |
Rooted<CalendarValue> calendar(cx, plainDateTime->calendar()); |
| 287 |
if (!calendar.wrap(cx)) { |
| 288 |
return false; |
| 289 |
} |
| 290 |
|
| 291 |
// Steps 2.a.i-ii. |
| 292 |
DateTimeOptions ignoredOptions; |
| 293 |
if (!ToTemporalDateTimeOptions(cx, options, &ignoredOptions)) { |
| 294 |
return false; |
| 295 |
} |
| 296 |
|
| 297 |
// Step 2.a.iii. |
| 298 |
result.set(PlainDateTime{dateTime, calendar}); |
| 299 |
return true; |
| 300 |
} |
| 301 |
|
| 302 |
// Step 2.b. |
| 303 |
if (auto* zonedDateTime = item->maybeUnwrapIf<ZonedDateTimeObject>()) { |
| 304 |
auto epochNs = zonedDateTime->epochNanoseconds(); |
| 305 |
Rooted<TimeZoneValue> timeZone(cx, zonedDateTime->timeZone()); |
| 306 |
Rooted<CalendarValue> calendar(cx, zonedDateTime->calendar()); |
| 307 |
|
| 308 |
if (!timeZone.wrap(cx)) { |
| 309 |
return false; |
| 310 |
} |
| 311 |
if (!calendar.wrap(cx)) { |
| 312 |
return false; |
| 313 |
} |
| 314 |
|
| 315 |
// Step 2.b.i. |
| 316 |
ISODateTime dateTime; |
| 317 |
if (!GetISODateTimeFor(cx, timeZone, epochNs, &dateTime)) { |
| 318 |
return false; |
| 319 |
} |
| 320 |
|
| 321 |
// Steps 2.b.ii-iii. |
| 322 |
DateTimeOptions ignoredOptions; |
| 323 |
if (!ToTemporalDateTimeOptions(cx, options, &ignoredOptions)) { |
| 324 |
return false; |
| 325 |
} |
| 326 |
|
| 327 |
// Step 2.b.iv. |
| 328 |
result.set(PlainDateTime{dateTime, calendar}); |
| 329 |
return true; |
| 330 |
} |
| 331 |
|
| 332 |
// Step 2.c. |
| 333 |
if (auto* plainDate = item->maybeUnwrapIf<PlainDateObject>()) { |
| 334 |
auto date = plainDate->date(); |
| 335 |
Rooted<CalendarValue> calendar(cx, plainDate->calendar()); |
| 336 |
if (!calendar.wrap(cx)) { |
| 337 |
return false; |
| 338 |
} |
| 339 |
|
| 340 |
// Steps 2.c.i-ii. |
| 341 |
DateTimeOptions ignoredOptions; |
| 342 |
if (!ToTemporalDateTimeOptions(cx, options, &ignoredOptions)) { |
| 343 |
return false; |
| 344 |
} |
| 345 |
|
| 346 |
// Steps 2.c.iii-iv. |
| 347 |
return CreateTemporalDateTime(cx, ISODateTime{date}, calendar, result); |
| 348 |
} |
| 349 |
|
| 350 |
// Step 2.d. |
| 351 |
Rooted<CalendarValue> calendar(cx); |
| 352 |
if (!GetTemporalCalendarWithISODefault(cx, item, &calendar)) { |
| 353 |
return false; |
| 354 |
} |
| 355 |
|
| 356 |
// Step 2.e. |
| 357 |
Rooted<CalendarFields> fields(cx); |
| 358 |
if (!PrepareCalendarFields(cx, calendar, item, |
| 359 |
{ |
| 360 |
CalendarField::Year, |
| 361 |
CalendarField::Month, |
| 362 |
CalendarField::MonthCode, |
| 363 |
CalendarField::Day, |
| 364 |
CalendarField::Hour, |
| 365 |
CalendarField::Minute, |
| 366 |
CalendarField::Second, |
| 367 |
CalendarField::Millisecond, |
| 368 |
CalendarField::Microsecond, |
| 369 |
CalendarField::Nanosecond, |
| 370 |
}, |
| 371 |
&fields)) { |
| 372 |
return false; |
| 373 |
} |
| 374 |
|
| 375 |
// Steps 2.f-g. |
| 376 |
DateTimeOptions resolvedOptions; |
| 377 |
if (!ToTemporalDateTimeOptions(cx, options, &resolvedOptions)) { |
| 378 |
return false; |
| 379 |
} |
| 380 |
auto [overflow] = resolvedOptions; |
| 381 |
|
| 382 |
// Step 2.h. |
| 383 |
ISODateTime dateTime; |
| 384 |
if (!InterpretTemporalDateTimeFields(cx, calendar, fields, overflow, |
| 385 |
&dateTime)) { |
| 386 |
return false; |
| 387 |
} |
| 388 |
|
| 389 |
// Step 2.i. |
| 390 |
return CreateTemporalDateTime(cx, dateTime, calendar, result); |
| 391 |
} |
| 392 |
|
| 393 |
/** |
| 394 |
* ToTemporalDateTime ( item [ , options ] ) |
| 395 |
*/ |
| 396 |
static bool ToTemporalDateTime(JSContext* cx, Handle<Value> item, |
| 397 |
Handle<Value> options, |
| 398 |
MutableHandle<PlainDateTime> result) { |
| 399 |
// Step 1. (Not applicable) |
| 400 |
|
| 401 |
// Step 2. |
| 402 |
if (item.isObject()) { |
| 403 |
Rooted<JSObject*> itemObj(cx, &item.toObject()); |
| 404 |
return ToTemporalDateTime(cx, itemObj, options, result); |
| 405 |
} |
| 406 |
|
| 407 |
// Step 3. |
| 408 |
if (!item.isString()) { |
| 409 |
ReportValueError(cx, JSMSG_UNEXPECTED_TYPE, JSDVG_IGNORE_STACK, item, |
| 410 |
nullptr, "not a string"); |
| 411 |
return false; |
| 412 |
} |
| 413 |
Rooted<JSString*> string(cx, item.toString()); |
| 414 |
|
| 415 |
// Steps 4-5. |
| 416 |
ISODateTime dateTime; |
| 417 |
Rooted<JSString*> calendarString(cx); |
| 418 |
if (!ParseTemporalDateTimeString(cx, string, &dateTime, &calendarString)) { |
| 419 |
return false; |
| 420 |
} |
| 421 |
MOZ_ASSERT(IsValidISODateTime(dateTime)); |
| 422 |
|
| 423 |
// Steps 6-8. |
| 424 |
Rooted<CalendarValue> calendar(cx, CalendarValue(CalendarId::ISO8601)); |
| 425 |
if (calendarString) { |
| 426 |
if (!CanonicalizeCalendar(cx, calendarString, &calendar)) { |
| 427 |
return false; |
| 428 |
} |
| 429 |
} |
| 430 |
|
| 431 |
// Steps 9-10. |
| 432 |
DateTimeOptions ignoredOptions; |
| 433 |
if (!ToTemporalDateTimeOptions(cx, options, &ignoredOptions)) { |
| 434 |
return false; |
| 435 |
} |
| 436 |
|
| 437 |
// Steps 11-13. |
| 438 |
return CreateTemporalDateTime(cx, dateTime, calendar, result); |
| 439 |
} |
| 440 |
|
| 441 |
/** |
| 442 |
* ToTemporalDateTime ( item [ , options ] ) |
| 443 |
*/ |
| 444 |
static bool ToTemporalDateTime(JSContext* cx, Handle<Value> item, |
| 445 |
MutableHandle<PlainDateTime> result) { |
| 446 |
return ToTemporalDateTime(cx, item, UndefinedHandleValue, result); |
| 447 |
} |
| 448 |
|
| 449 |
/** |
| 450 |
* CompareISODateTime ( isoDateTime1, isoDateTime2 ) |
| 451 |
*/ |
| 452 |
static int32_t CompareISODateTime(const ISODateTime& isoDateTime1, |
| 453 |
const ISODateTime& isoDateTime2) { |
| 454 |
// Steps 1-2. |
| 455 |
if (int32_t dateResult = |
| 456 |
CompareISODate(isoDateTime1.date, isoDateTime2.date)) { |
| 457 |
return dateResult; |
| 458 |
} |
| 459 |
|
| 460 |
// Steps 3. |
| 461 |
return CompareTimeRecord(isoDateTime1.time, isoDateTime2.time); |
| 462 |
} |
| 463 |
|
| 464 |
/** |
| 465 |
* Add24HourDaysToTimeDuration ( d, days ) |
| 466 |
*/ |
| 467 |
static TimeDuration Add24HourDaysToTimeDuration(const TimeDuration& d, |
| 468 |
int32_t days) { |
| 469 |
// Step 1. |
| 470 |
auto result = d + TimeDuration::fromDays(days); |
| 471 |
|
| 472 |
// Step 2. |
| 473 |
MOZ_ASSERT(result.abs() <= TimeDuration::max()); |
| 474 |
|
| 475 |
// Step 3. |
| 476 |
return result; |
| 477 |
} |
| 478 |
|
| 479 |
/** |
| 480 |
* DifferenceISODateTime ( isoDateTime1, isoDateTime2, calendar, largestUnit ) |
| 481 |
*/ |
| 482 |
static bool DifferenceISODateTime(JSContext* cx, |
| 483 |
const ISODateTime& isoDateTime1, |
| 484 |
const ISODateTime& isoDateTime2, |
| 485 |
Handle<CalendarValue> calendar, |
| 486 |
TemporalUnit largestUnit, |
| 487 |
InternalDuration* result) { |
| 488 |
MOZ_ASSERT(isoDateTime1 != isoDateTime2, |
| 489 |
"fast-path for same date-time case handled in caller"); |
| 490 |
|
| 491 |
// Steps 1-2. |
| 492 |
MOZ_ASSERT(IsValidISODateTime(isoDateTime1)); |
| 493 |
MOZ_ASSERT(IsValidISODateTime(isoDateTime2)); |
| 494 |
MOZ_ASSERT(ISODateTimeWithinLimits(isoDateTime1)); |
| 495 |
MOZ_ASSERT(ISODateTimeWithinLimits(isoDateTime2)); |
| 496 |
|
| 497 |
// Step 3. |
| 498 |
auto timeDuration = DifferenceTime(isoDateTime1.time, isoDateTime2.time); |
| 499 |
|
| 500 |
// Step 4. |
| 501 |
int32_t timeSign = TimeDurationSign(timeDuration); |
| 502 |
|
| 503 |
// Step 5. |
| 504 |
int32_t dateSign = CompareISODate(isoDateTime1.date, isoDateTime2.date); |
| 505 |
|
| 506 |
// Step 6. |
| 507 |
auto adjustedDate = isoDateTime2.date; |
| 508 |
|
| 509 |
// Step 7. |
| 510 |
if (timeSign == dateSign) { |
| 511 |
// Step 7.a. |
| 512 |
adjustedDate = BalanceISODate(adjustedDate, timeSign); |
| 513 |
|
| 514 |
// Step 7.b. |
| 515 |
timeDuration = Add24HourDaysToTimeDuration(timeDuration, -timeSign); |
| 516 |
} |
| 517 |
|
| 518 |
MOZ_ASSERT(IsValidISODate(adjustedDate)); |
| 519 |
MOZ_ASSERT(ISODateWithinLimits(adjustedDate)); |
| 520 |
|
| 521 |
// Step 8. |
| 522 |
auto dateLargestUnit = std::min(TemporalUnit::Day, largestUnit); |
| 523 |
|
| 524 |
// Step 9. |
| 525 |
DateDuration dateDifference; |
| 526 |
if (!CalendarDateUntil(cx, calendar, isoDateTime1.date, adjustedDate, |
| 527 |
dateLargestUnit, &dateDifference)) { |
| 528 |
return false; |
| 529 |
} |
| 530 |
|
| 531 |
// Steps 10. |
| 532 |
if (largestUnit > TemporalUnit::Day) { |
| 533 |
// Step 10.a. |
| 534 |
auto days = mozilla::AssertedCast<int32_t>(dateDifference.days); |
| 535 |
timeDuration = Add24HourDaysToTimeDuration(timeDuration, days); |
| 536 |
|
| 537 |
// Step 10.b. |
| 538 |
dateDifference.days = 0; |
| 539 |
} |
| 540 |
|
| 541 |
// Step 11. |
| 542 |
MOZ_ASSERT( |
| 543 |
DateDurationSign(dateDifference) * TimeDurationSign(timeDuration) >= 0); |
| 544 |
*result = {dateDifference, timeDuration}; |
| 545 |
return true; |
| 546 |
} |
| 547 |
|
| 548 |
/** |
| 549 |
* RoundISODateTime ( isoDateTime, increment, unit, roundingMode ) |
| 550 |
*/ |
| 551 |
ISODateTime js::temporal::RoundISODateTime(const ISODateTime& isoDateTime, |
| 552 |
Increment increment, |
| 553 |
TemporalUnit unit, |
| 554 |
TemporalRoundingMode roundingMode) { |
| 555 |
MOZ_ASSERT(IsValidISODateTime(isoDateTime)); |
| 556 |
|
| 557 |
// Step 1. |
| 558 |
MOZ_ASSERT(ISODateTimeWithinLimits(isoDateTime)); |
| 559 |
|
| 560 |
// Step 2. |
| 561 |
auto roundedTime = RoundTime(isoDateTime.time, increment, unit, roundingMode); |
| 562 |
MOZ_ASSERT(0 <= roundedTime.days && roundedTime.days <= 1); |
| 563 |
|
| 564 |
// Step 3. |
| 565 |
auto balanceResult = BalanceISODate(isoDateTime.date, roundedTime.days); |
| 566 |
|
| 567 |
// Step 4. |
| 568 |
return {balanceResult, roundedTime.time}; |
| 569 |
} |
| 570 |
|
| 571 |
/** |
| 572 |
* DifferencePlainDateTimeWithRounding ( isoDateTime1, isoDateTime2, calendar, |
| 573 |
* largestUnit, roundingIncrement, smallestUnit, roundingMode ) |
| 574 |
*/ |
| 575 |
bool js::temporal::DifferencePlainDateTimeWithRounding( |
| 576 |
JSContext* cx, const ISODateTime& isoDateTime1, |
| 577 |
const ISODateTime& isoDateTime2, Handle<CalendarValue> calendar, |
| 578 |
const DifferenceSettings& settings, InternalDuration* result) { |
| 579 |
MOZ_ASSERT(ISODateTimeWithinLimits(isoDateTime1)); |
| 580 |
MOZ_ASSERT(ISODateTimeWithinLimits(isoDateTime2)); |
| 581 |
|
| 582 |
// Step 1. |
| 583 |
if (isoDateTime1 == isoDateTime2) { |
| 584 |
// Step 1.a. |
| 585 |
*result = {}; |
| 586 |
return true; |
| 587 |
} |
| 588 |
|
| 589 |
// Step 2. (Not applicable in our implementation.) |
| 590 |
|
| 591 |
// Step 3. |
| 592 |
InternalDuration diff; |
| 593 |
if (!DifferenceISODateTime(cx, isoDateTime1, isoDateTime2, calendar, |
| 594 |
settings.largestUnit, &diff)) { |
| 595 |
return false; |
| 596 |
} |
| 597 |
|
| 598 |
// Step 4. |
| 599 |
if (settings.smallestUnit == TemporalUnit::Nanosecond && |
| 600 |
settings.roundingIncrement == Increment{1}) { |
| 601 |
*result = diff; |
| 602 |
return true; |
| 603 |
} |
| 604 |
|
| 605 |
// Step 5. |
| 606 |
auto destEpochNs = GetUTCEpochNanoseconds(isoDateTime2); |
| 607 |
|
| 608 |
// Step 6. |
| 609 |
Rooted<TimeZoneValue> timeZone(cx, TimeZoneValue{}); |
| 610 |
return RoundRelativeDuration( |
| 611 |
cx, diff, destEpochNs, isoDateTime1, timeZone, calendar, |
| 612 |
settings.largestUnit, settings.roundingIncrement, settings.smallestUnit, |
| 613 |
settings.roundingMode, result); |
| 614 |
} |
| 615 |
|
| 616 |
/** |
| 617 |
* DifferencePlainDateTimeWithTotal ( isoDateTime1, isoDateTime2, calendar, unit |
| 618 |
* ) |
| 619 |
*/ |
| 620 |
bool js::temporal::DifferencePlainDateTimeWithTotal( |
| 621 |
JSContext* cx, const ISODateTime& isoDateTime1, |
| 622 |
const ISODateTime& isoDateTime2, Handle<CalendarValue> calendar, |
| 623 |
TemporalUnit unit, double* result) { |
| 624 |
MOZ_ASSERT(ISODateTimeWithinLimits(isoDateTime1)); |
| 625 |
MOZ_ASSERT(ISODateTimeWithinLimits(isoDateTime2)); |
| 626 |
|
| 627 |
// Step 1. |
| 628 |
if (isoDateTime1 == isoDateTime2) { |
| 629 |
// Step 1.a. |
| 630 |
*result = 0; |
| 631 |
return true; |
| 632 |
} |
| 633 |
|
| 634 |
// Step 2. (Not applicable in our implementation.) |
| 635 |
|
| 636 |
// Step 3. |
| 637 |
InternalDuration diff; |
| 638 |
if (!DifferenceISODateTime(cx, isoDateTime1, isoDateTime2, calendar, unit, |
| 639 |
&diff)) { |
| 640 |
return false; |
| 641 |
} |
| 642 |
|
| 643 |
// Step 4. (Optimized to avoid GetUTCEpochNanoseconds for non-calendar units.) |
| 644 |
if (unit > TemporalUnit::Day) { |
| 645 |
MOZ_ASSERT(diff.date == DateDuration{}); |
| 646 |
|
| 647 |
// TotalRelativeDuration, steps 1-2. (Not applicable) |
| 648 |
|
| 649 |
// TotalRelativeDuration, step 3. |
| 650 |
*result = TotalTimeDuration(diff.time, unit); |
| 651 |
return true; |
| 652 |
} else if (unit == TemporalUnit::Day) { |
| 653 |
// TotalRelativeDuration, step 1. (Not applicable) |
| 654 |
|
| 655 |
// TotalRelativeDuration, step 2. |
| 656 |
auto days = mozilla::AssertedCast<int32_t>(diff.date.days); |
| 657 |
auto timeDuration = Add24HourDaysToTimeDuration(diff.time, days); |
| 658 |
|
| 659 |
// TotalRelativeDuration, step 3. |
| 660 |
*result = TotalTimeDuration(timeDuration, unit); |
| 661 |
return true; |
| 662 |
} |
| 663 |
|
| 664 |
// Step 5. |
| 665 |
auto destEpochNs = GetUTCEpochNanoseconds(isoDateTime2); |
| 666 |
|
| 667 |
// Step 6. |
| 668 |
Rooted<TimeZoneValue> timeZone(cx, TimeZoneValue{}); |
| 669 |
return TotalRelativeDuration(cx, diff, destEpochNs, isoDateTime1, timeZone, |
| 670 |
calendar, unit, result); |
| 671 |
} |
| 672 |
|
| 673 |
/** |
| 674 |
* DifferenceTemporalPlainDateTime ( operation, dateTime, other, options ) |
| 675 |
*/ |
| 676 |
static bool DifferenceTemporalPlainDateTime(JSContext* cx, |
| 677 |
TemporalDifference operation, |
| 678 |
const CallArgs& args) { |
| 679 |
Rooted<PlainDateTime> dateTime( |
| 680 |
cx, &args.thisv().toObject().as<PlainDateTimeObject>()); |
| 681 |
|
| 682 |
// Step 1. |
| 683 |
Rooted<PlainDateTime> other(cx); |
| 684 |
if (!ToTemporalDateTime(cx, args.get(0), &other)) { |
| 685 |
return false; |
| 686 |
} |
| 687 |
|
| 688 |
// Step 2. |
| 689 |
if (!CalendarEquals(dateTime.calendar(), other.calendar())) { |
| 690 |
JS_ReportErrorNumberASCII(cx, GetErrorMessage, nullptr, |
| 691 |
JSMSG_TEMPORAL_CALENDAR_INCOMPATIBLE, |
| 692 |
CalendarIdentifier(dateTime.calendar()).data(), |
| 693 |
CalendarIdentifier(other.calendar()).data()); |
| 694 |
return false; |
| 695 |
} |
| 696 |
|
| 697 |
// Steps 3-4. |
| 698 |
DifferenceSettings settings; |
| 699 |
if (args.hasDefined(1)) { |
| 700 |
// Step 3. |
| 701 |
Rooted<JSObject*> options( |
| 702 |
cx, RequireObjectArg(cx, "options", ToName(operation), args[1])); |
| 703 |
if (!options) { |
| 704 |
return false; |
| 705 |
} |
| 706 |
|
| 707 |
// Step 4. |
| 708 |
if (!GetDifferenceSettings( |
| 709 |
cx, operation, options, TemporalUnitGroup::DateTime, |
| 710 |
TemporalUnit::Nanosecond, TemporalUnit::Day, &settings)) { |
| 711 |
return false; |
| 712 |
} |
| 713 |
} else { |
| 714 |
// Steps 3-4. |
| 715 |
settings = { |
| 716 |
TemporalUnit::Nanosecond, |
| 717 |
TemporalUnit::Day, |
| 718 |
TemporalRoundingMode::Trunc, |
| 719 |
Increment{1}, |
| 720 |
}; |
| 721 |
} |
| 722 |
|
| 723 |
// Step 5. |
| 724 |
if (dateTime.dateTime() == other.dateTime()) { |
| 725 |
auto* obj = CreateTemporalDuration(cx, {}); |
| 726 |
if (!obj) { |
| 727 |
return false; |
| 728 |
} |
| 729 |
|
| 730 |
args.rval().setObject(*obj); |
| 731 |
return true; |
| 732 |
} |
| 733 |
|
| 734 |
// Step 6. |
| 735 |
InternalDuration internalDuration; |
| 736 |
if (!DifferencePlainDateTimeWithRounding(cx, dateTime, other, |
| 737 |
dateTime.calendar(), settings, |
| 738 |
&internalDuration)) { |
| 739 |
return false; |
| 740 |
} |
| 741 |
MOZ_ASSERT(IsValidDuration(internalDuration)); |
| 742 |
|
| 743 |
// Step 7. |
| 744 |
Duration result; |
| 745 |
if (!TemporalDurationFromInternal(cx, internalDuration, settings.largestUnit, |
| 746 |
&result)) { |
| 747 |
return false; |
| 748 |
} |
| 749 |
MOZ_ASSERT(IsValidDuration(result)); |
| 750 |
|
| 751 |
// Step 8. |
| 752 |
if (operation == TemporalDifference::Since) { |
| 753 |
result = result.negate(); |
| 754 |
} |
| 755 |
|
| 756 |
// Step 9. |
| 757 |
auto* obj = CreateTemporalDuration(cx, result); |
| 758 |
if (!obj) { |
| 759 |
return false; |
| 760 |
} |
| 761 |
|
| 762 |
args.rval().setObject(*obj); |
| 763 |
return true; |
| 764 |
} |
| 765 |
|
| 766 |
/** |
| 767 |
* AddDurationToDateTime ( operation, dateTime, temporalDurationLike, options ) |
| 768 |
*/ |
| 769 |
static bool AddDurationToDateTime(JSContext* cx, TemporalAddDuration operation, |
| 770 |
const CallArgs& args) { |
| 771 |
Rooted<PlainDateTime> dateTime( |
| 772 |
cx, &args.thisv().toObject().as<PlainDateTimeObject>()); |
| 773 |
|
| 774 |
// Step 1. |
| 775 |
Duration duration; |
| 776 |
if (!ToTemporalDuration(cx, args.get(0), &duration)) { |
| 777 |
return false; |
| 778 |
} |
| 779 |
|
| 780 |
// Step 2. |
| 781 |
if (operation == TemporalAddDuration::Subtract) { |
| 782 |
duration = duration.negate(); |
| 783 |
} |
| 784 |
|
| 785 |
// Steps 3-4. |
| 786 |
auto overflow = TemporalOverflow::Constrain; |
| 787 |
if (args.hasDefined(1)) { |
| 788 |
// Step 3. |
| 789 |
Rooted<JSObject*> options( |
| 790 |
cx, RequireObjectArg(cx, "options", ToName(operation), args[1])); |
| 791 |
if (!options) { |
| 792 |
return false; |
| 793 |
} |
| 794 |
|
| 795 |
// Step 4. |
| 796 |
if (!GetTemporalOverflowOption(cx, options, &overflow)) { |
| 797 |
return false; |
| 798 |
} |
| 799 |
} |
| 800 |
|
| 801 |
// Step 5. |
| 802 |
auto internalDuration = ToInternalDurationRecordWith24HourDays(duration); |
| 803 |
MOZ_ASSERT(IsValidDuration(internalDuration)); |
| 804 |
|
| 805 |
// Step 6. |
| 806 |
auto timeResult = AddTime(dateTime.time(), internalDuration.time); |
| 807 |
|
| 808 |
// Step 7. (Inlined AdjustDateDurationRecord) |
| 809 |
if (std::abs(timeResult.days) > TimeDuration::max().toDays()) { |
| 810 |
JS_ReportErrorNumberASCII(cx, GetErrorMessage, nullptr, |
| 811 |
JSMSG_TEMPORAL_DURATION_INVALID_NORMALIZED_TIME); |
| 812 |
return false; |
| 813 |
} |
| 814 |
auto dateDuration = DateDuration{ |
| 815 |
internalDuration.date.years, |
| 816 |
internalDuration.date.months, |
| 817 |
internalDuration.date.weeks, |
| 818 |
timeResult.days, |
| 819 |
}; |
| 820 |
MOZ_ASSERT(IsValidDuration(dateDuration)); |
| 821 |
|
| 822 |
// Step 8. |
| 823 |
ISODate addedDate; |
| 824 |
if (!CalendarDateAdd(cx, dateTime.calendar(), dateTime.date(), dateDuration, |
| 825 |
overflow, &addedDate)) { |
| 826 |
return false; |
| 827 |
} |
| 828 |
|
| 829 |
// Step 9. |
| 830 |
auto result = ISODateTime{addedDate, timeResult.time}; |
| 831 |
MOZ_ASSERT(IsValidISODateTime(result)); |
| 832 |
|
| 833 |
// Step 10. |
| 834 |
auto* obj = CreateTemporalDateTime(cx, result, dateTime.calendar()); |
| 835 |
if (!obj) { |
| 836 |
return false; |
| 837 |
} |
| 838 |
|
| 839 |
args.rval().setObject(*obj); |
| 840 |
return true; |
| 841 |
} |
| 842 |
|
| 843 |
/** |
| 844 |
* Temporal.PlainDateTime ( isoYear, isoMonth, isoDay [ , hour [ , minute [ , |
| 845 |
* second [ , millisecond [ , microsecond [ , nanosecond [ , calendar ] ] ] ] ] |
| 846 |
* ] ] ) |
| 847 |
*/ |
| 848 |
static bool PlainDateTimeConstructor(JSContext* cx, unsigned argc, Value* vp) { |
| 849 |
CallArgs args = CallArgsFromVp(argc, vp); |
| 850 |
|
| 851 |
// Step 1. |
| 852 |
if (!ThrowIfNotConstructing(cx, args, "Temporal.PlainDateTime")) { |
| 853 |
return false; |
| 854 |
} |
| 855 |
|
| 856 |
// Step 2. |
| 857 |
double isoYear; |
| 858 |
if (!ToIntegerWithTruncation(cx, args.get(0), "year", &isoYear)) { |
| 859 |
return false; |
| 860 |
} |
| 861 |
|
| 862 |
// Step 3. |
| 863 |
double isoMonth; |
| 864 |
if (!ToIntegerWithTruncation(cx, args.get(1), "month", &isoMonth)) { |
| 865 |
return false; |
| 866 |
} |
| 867 |
|
| 868 |
// Step 4. |
| 869 |
double isoDay; |
| 870 |
if (!ToIntegerWithTruncation(cx, args.get(2), "day", &isoDay)) { |
| 871 |
return false; |
| 872 |
} |
| 873 |
|
| 874 |
// Step 5. |
| 875 |
double hour = 0; |
| 876 |
if (args.hasDefined(3)) { |
| 877 |
if (!ToIntegerWithTruncation(cx, args[3], "hour", &hour)) { |
| 878 |
return false; |
| 879 |
} |
| 880 |
} |
| 881 |
|
| 882 |
// Step 6. |
| 883 |
double minute = 0; |
| 884 |
if (args.hasDefined(4)) { |
| 885 |
if (!ToIntegerWithTruncation(cx, args[4], "minute", &minute)) { |
| 886 |
return false; |
| 887 |
} |
| 888 |
} |
| 889 |
|
| 890 |
// Step 7. |
| 891 |
double second = 0; |
| 892 |
if (args.hasDefined(5)) { |
| 893 |
if (!ToIntegerWithTruncation(cx, args[5], "second", &second)) { |
| 894 |
return false; |
| 895 |
} |
| 896 |
} |
| 897 |
|
| 898 |
// Step 8. |
| 899 |
double millisecond = 0; |
| 900 |
if (args.hasDefined(6)) { |
| 901 |
if (!ToIntegerWithTruncation(cx, args[6], "millisecond", &millisecond)) { |
| 902 |
return false; |
| 903 |
} |
| 904 |
} |
| 905 |
|
| 906 |
// Step 9. |
| 907 |
double microsecond = 0; |
| 908 |
if (args.hasDefined(7)) { |
| 909 |
if (!ToIntegerWithTruncation(cx, args[7], "microsecond", µsecond)) { |
| 910 |
return false; |
| 911 |
} |
| 912 |
} |
| 913 |
|
| 914 |
// Step 10. |
| 915 |
double nanosecond = 0; |
| 916 |
if (args.hasDefined(8)) { |
| 917 |
if (!ToIntegerWithTruncation(cx, args[8], "nanosecond", &nanosecond)) { |
| 918 |
return false; |
| 919 |
} |
| 920 |
} |
| 921 |
|
| 922 |
// Steps 11-13. |
| 923 |
Rooted<CalendarValue> calendar(cx, CalendarValue(CalendarId::ISO8601)); |
| 924 |
if (args.hasDefined(9)) { |
| 925 |
// Step 12. |
| 926 |
if (!args[9].isString()) { |
| 927 |
ReportValueError(cx, JSMSG_UNEXPECTED_TYPE, JSDVG_IGNORE_STACK, args[9], |
| 928 |
nullptr, "not a string"); |
| 929 |
return false; |
| 930 |
} |
| 931 |
|
| 932 |
// Step 13. |
| 933 |
Rooted<JSString*> calendarString(cx, args[9].toString()); |
| 934 |
if (!CanonicalizeCalendar(cx, calendarString, &calendar)) { |
| 935 |
return false; |
| 936 |
} |
| 937 |
} |
| 938 |
|
| 939 |
// Step 14. |
| 940 |
if (!ThrowIfInvalidISODate(cx, isoYear, isoMonth, isoDay)) { |
| 941 |
return false; |
| 942 |
} |
| 943 |
|
| 944 |
// Step 15. |
| 945 |
auto isoDate = ISODate{int32_t(isoYear), int32_t(isoMonth), int32_t(isoDay)}; |
| 946 |
|
| 947 |
// Step 16. |
| 948 |
if (!ThrowIfInvalidTime(cx, hour, minute, second, millisecond, microsecond, |
| 949 |
nanosecond)) { |
| 950 |
return false; |
| 951 |
} |
| 952 |
|
| 953 |
// Step 17. |
| 954 |
auto time = |
| 955 |
Time{int32_t(hour), int32_t(minute), int32_t(second), |
| 956 |
int32_t(millisecond), int32_t(microsecond), int32_t(nanosecond)}; |
| 957 |
|
| 958 |
// Step 18. |
| 959 |
auto isoDateTime = ISODateTime{isoDate, time}; |
| 960 |
|
| 961 |
// Step 19. |
| 962 |
auto* temporalDateTime = |
| 963 |
CreateTemporalDateTime(cx, args, isoDateTime, calendar); |
| 964 |
if (!temporalDateTime) { |
| 965 |
return false; |
| 966 |
} |
| 967 |
|
| 968 |
args.rval().setObject(*temporalDateTime); |
| 969 |
return true; |
| 970 |
} |
| 971 |
|
| 972 |
/** |
| 973 |
* Temporal.PlainDateTime.from ( item [ , options ] ) |
| 974 |
*/ |
| 975 |
static bool PlainDateTime_from(JSContext* cx, unsigned argc, Value* vp) { |
| 976 |
CallArgs args = CallArgsFromVp(argc, vp); |
| 977 |
|
| 978 |
// Step 1. |
| 979 |
Rooted<PlainDateTime> dateTime(cx); |
| 980 |
if (!ToTemporalDateTime(cx, args.get(0), args.get(1), &dateTime)) { |
| 981 |
return false; |
| 982 |
} |
| 983 |
|
| 984 |
auto* result = CreateTemporalDateTime(cx, dateTime); |
| 985 |
if (!result) { |
| 986 |
return false; |
| 987 |
} |
| 988 |
|
| 989 |
args.rval().setObject(*result); |
| 990 |
return true; |
| 991 |
} |
| 992 |
|
| 993 |
/** |
| 994 |
* Temporal.PlainDateTime.compare ( one, two ) |
| 995 |
*/ |
| 996 |
static bool PlainDateTime_compare(JSContext* cx, unsigned argc, Value* vp) { |
| 997 |
CallArgs args = CallArgsFromVp(argc, vp); |
| 998 |
|
| 999 |
// Step 1. |
| 1000 |
Rooted<PlainDateTime> one(cx); |
| 1001 |
if (!ToTemporalDateTime(cx, args.get(0), &one)) { |
| 1002 |
return false; |
| 1003 |
} |
| 1004 |
|
| 1005 |
// Step 2. |
| 1006 |
Rooted<PlainDateTime> two(cx); |
| 1007 |
if (!ToTemporalDateTime(cx, args.get(1), &two)) { |
| 1008 |
return false; |
| 1009 |
} |
| 1010 |
|
| 1011 |
// Step 3. |
| 1012 |
args.rval().setInt32(CompareISODateTime(one, two)); |
| 1013 |
return true; |
| 1014 |
} |
| 1015 |
|
| 1016 |
/** |
| 1017 |
* get Temporal.PlainDateTime.prototype.calendarId |
| 1018 |
*/ |
| 1019 |
static bool PlainDateTime_calendarId(JSContext* cx, const CallArgs& args) { |
| 1020 |
auto* dateTime = &args.thisv().toObject().as<PlainDateTimeObject>(); |
| 1021 |
|
| 1022 |
// Step 3. |
| 1023 |
auto* str = |
| 1024 |
NewStringCopy<CanGC>(cx, CalendarIdentifier(dateTime->calendar())); |
| 1025 |
if (!str) { |
| 1026 |
return false; |
| 1027 |
} |
| 1028 |
|
| 1029 |
args.rval().setString(str); |
| 1030 |
return true; |
| 1031 |
} |
| 1032 |
|
| 1033 |
/** |
| 1034 |
* get Temporal.PlainDateTime.prototype.calendarId |
| 1035 |
*/ |
| 1036 |
static bool PlainDateTime_calendarId(JSContext* cx, unsigned argc, Value* vp) { |
| 1037 |
// Steps 1-2. |
| 1038 |
CallArgs args = CallArgsFromVp(argc, vp); |
| 1039 |
return CallNonGenericMethod<IsPlainDateTime, PlainDateTime_calendarId>(cx, |
| 1040 |
args); |
| 1041 |
} |
| 1042 |
|
| 1043 |
/** |
| 1044 |
* get Temporal.PlainDateTime.prototype.era |
| 1045 |
*/ |
| 1046 |
static bool PlainDateTime_era(JSContext* cx, const CallArgs& args) { |
| 1047 |
auto* dateTime = &args.thisv().toObject().as<PlainDateTimeObject>(); |
| 1048 |
Rooted<CalendarValue> calendar(cx, dateTime->calendar()); |
| 1049 |
|
| 1050 |
// Step 3. |
| 1051 |
return CalendarEra(cx, calendar, dateTime->date(), args.rval()); |
| 1052 |
} |
| 1053 |
|
| 1054 |
/** |
| 1055 |
* get Temporal.PlainDateTime.prototype.era |
| 1056 |
*/ |
| 1057 |
static bool PlainDateTime_era(JSContext* cx, unsigned argc, Value* vp) { |
| 1058 |
// Steps 1-2. |
| 1059 |
CallArgs args = CallArgsFromVp(argc, vp); |
| 1060 |
return CallNonGenericMethod<IsPlainDateTime, PlainDateTime_era>(cx, args); |
| 1061 |
} |
| 1062 |
|
| 1063 |
/** |
| 1064 |
* get Temporal.PlainDateTime.prototype.eraYear |
| 1065 |
*/ |
| 1066 |
static bool PlainDateTime_eraYear(JSContext* cx, const CallArgs& args) { |
| 1067 |
auto* dateTime = &args.thisv().toObject().as<PlainDateTimeObject>(); |
| 1068 |
Rooted<CalendarValue> calendar(cx, dateTime->calendar()); |
| 1069 |
|
| 1070 |
// Steps 3-5. |
| 1071 |
return CalendarEraYear(cx, calendar, dateTime->date(), args.rval()); |
| 1072 |
} |
| 1073 |
|
| 1074 |
/** |
| 1075 |
* get Temporal.PlainDateTime.prototype.eraYear |
| 1076 |
*/ |
| 1077 |
static bool PlainDateTime_eraYear(JSContext* cx, unsigned argc, Value* vp) { |
| 1078 |
// Steps 1-2. |
| 1079 |
CallArgs args = CallArgsFromVp(argc, vp); |
| 1080 |
return CallNonGenericMethod<IsPlainDateTime, PlainDateTime_eraYear>(cx, args); |
| 1081 |
} |
| 1082 |
|
| 1083 |
/** |
| 1084 |
* get Temporal.PlainDateTime.prototype.year |
| 1085 |
*/ |
| 1086 |
static bool PlainDateTime_year(JSContext* cx, const CallArgs& args) { |
| 1087 |
auto* dateTime = &args.thisv().toObject().as<PlainDateTimeObject>(); |
| 1088 |
Rooted<CalendarValue> calendar(cx, dateTime->calendar()); |
| 1089 |
|
| 1090 |
// Step 3. |
| 1091 |
return CalendarYear(cx, calendar, dateTime->date(), args.rval()); |
| 1092 |
} |
| 1093 |
|
| 1094 |
/** |
| 1095 |
* get Temporal.PlainDateTime.prototype.year |
| 1096 |
*/ |
| 1097 |
static bool PlainDateTime_year(JSContext* cx, unsigned argc, Value* vp) { |
| 1098 |
// Steps 1-2. |
| 1099 |
CallArgs args = CallArgsFromVp(argc, vp); |
| 1100 |
return CallNonGenericMethod<IsPlainDateTime, PlainDateTime_year>(cx, args); |
| 1101 |
} |
| 1102 |
|
| 1103 |
/** |
| 1104 |
* get Temporal.PlainDateTime.prototype.month |
| 1105 |
*/ |
| 1106 |
static bool PlainDateTime_month(JSContext* cx, const CallArgs& args) { |
| 1107 |
auto* dateTime = &args.thisv().toObject().as<PlainDateTimeObject>(); |
| 1108 |
Rooted<CalendarValue> calendar(cx, dateTime->calendar()); |
| 1109 |
|
| 1110 |
// Step 3. |
| 1111 |
return CalendarMonth(cx, calendar, dateTime->date(), args.rval()); |
| 1112 |
} |
| 1113 |
|
| 1114 |
/** |
| 1115 |
* get Temporal.PlainDateTime.prototype.month |
| 1116 |
*/ |
| 1117 |
static bool PlainDateTime_month(JSContext* cx, unsigned argc, Value* vp) { |
| 1118 |
// Steps 1-2. |
| 1119 |
CallArgs args = CallArgsFromVp(argc, vp); |
| 1120 |
return CallNonGenericMethod<IsPlainDateTime, PlainDateTime_month>(cx, args); |
| 1121 |
} |
| 1122 |
|
| 1123 |
/** |
| 1124 |
* get Temporal.PlainDateTime.prototype.monthCode |
| 1125 |
*/ |
| 1126 |
static bool PlainDateTime_monthCode(JSContext* cx, const CallArgs& args) { |
| 1127 |
auto* dateTime = &args.thisv().toObject().as<PlainDateTimeObject>(); |
| 1128 |
Rooted<CalendarValue> calendar(cx, dateTime->calendar()); |
| 1129 |
|
| 1130 |
// Step 3. |
| 1131 |
return CalendarMonthCode(cx, calendar, dateTime->date(), args.rval()); |
| 1132 |
} |
| 1133 |
|
| 1134 |
/** |
| 1135 |
* get Temporal.PlainDateTime.prototype.monthCode |
| 1136 |
*/ |
| 1137 |
static bool PlainDateTime_monthCode(JSContext* cx, unsigned argc, Value* vp) { |
| 1138 |
// Steps 1-2. |
| 1139 |
CallArgs args = CallArgsFromVp(argc, vp); |
| 1140 |
return CallNonGenericMethod<IsPlainDateTime, PlainDateTime_monthCode>(cx, |
| 1141 |
args); |
| 1142 |
} |
| 1143 |
|
| 1144 |
/** |
| 1145 |
* get Temporal.PlainDateTime.prototype.day |
| 1146 |
*/ |
| 1147 |
static bool PlainDateTime_day(JSContext* cx, const CallArgs& args) { |
| 1148 |
auto* dateTime = &args.thisv().toObject().as<PlainDateTimeObject>(); |
| 1149 |
Rooted<CalendarValue> calendar(cx, dateTime->calendar()); |
| 1150 |
|
| 1151 |
// Step 3. |
| 1152 |
return CalendarDay(cx, calendar, dateTime->date(), args.rval()); |
| 1153 |
} |
| 1154 |
|
| 1155 |
/** |
| 1156 |
* get Temporal.PlainDateTime.prototype.day |
| 1157 |
*/ |
| 1158 |
static bool PlainDateTime_day(JSContext* cx, unsigned argc, Value* vp) { |
| 1159 |
// Steps 1-2. |
| 1160 |
CallArgs args = CallArgsFromVp(argc, vp); |
| 1161 |
return CallNonGenericMethod<IsPlainDateTime, PlainDateTime_day>(cx, args); |
| 1162 |
} |
| 1163 |
|
| 1164 |
/** |
| 1165 |
* get Temporal.PlainDateTime.prototype.hour |
| 1166 |
*/ |
| 1167 |
static bool PlainDateTime_hour(JSContext* cx, const CallArgs& args) { |
| 1168 |
// Step 3. |
| 1169 |
auto* dateTime = &args.thisv().toObject().as<PlainDateTimeObject>(); |
| 1170 |
args.rval().setInt32(dateTime->time().hour); |
| 1171 |
return true; |
| 1172 |
} |
| 1173 |
|
| 1174 |
/** |
| 1175 |
* get Temporal.PlainDateTime.prototype.hour |
| 1176 |
*/ |
| 1177 |
static bool PlainDateTime_hour(JSContext* cx, unsigned argc, Value* vp) { |
| 1178 |
// Steps 1-2. |
| 1179 |
CallArgs args = CallArgsFromVp(argc, vp); |
| 1180 |
return CallNonGenericMethod<IsPlainDateTime, PlainDateTime_hour>(cx, args); |
| 1181 |
} |
| 1182 |
|
| 1183 |
/** |
| 1184 |
* get Temporal.PlainDateTime.prototype.minute |
| 1185 |
*/ |
| 1186 |
static bool PlainDateTime_minute(JSContext* cx, const CallArgs& args) { |
| 1187 |
// Step 3. |
| 1188 |
auto* dateTime = &args.thisv().toObject().as<PlainDateTimeObject>(); |
| 1189 |
args.rval().setInt32(dateTime->time().minute); |
| 1190 |
return true; |
| 1191 |
} |
| 1192 |
|
| 1193 |
/** |
| 1194 |
* get Temporal.PlainDateTime.prototype.minute |
| 1195 |
*/ |
| 1196 |
static bool PlainDateTime_minute(JSContext* cx, unsigned argc, Value* vp) { |
| 1197 |
// Steps 1-2. |
| 1198 |
CallArgs args = CallArgsFromVp(argc, vp); |
| 1199 |
return CallNonGenericMethod<IsPlainDateTime, PlainDateTime_minute>(cx, args); |
| 1200 |
} |
| 1201 |
|
| 1202 |
/** |
| 1203 |
* get Temporal.PlainDateTime.prototype.second |
| 1204 |
*/ |
| 1205 |
static bool PlainDateTime_second(JSContext* cx, const CallArgs& args) { |
| 1206 |
// Step 3. |
| 1207 |
auto* dateTime = &args.thisv().toObject().as<PlainDateTimeObject>(); |
| 1208 |
args.rval().setInt32(dateTime->time().second); |
| 1209 |
return true; |
| 1210 |
} |
| 1211 |
|
| 1212 |
/** |
| 1213 |
* get Temporal.PlainDateTime.prototype.second |
| 1214 |
*/ |
| 1215 |
static bool PlainDateTime_second(JSContext* cx, unsigned argc, Value* vp) { |
| 1216 |
// Steps 1-2. |
| 1217 |
CallArgs args = CallArgsFromVp(argc, vp); |
| 1218 |
return CallNonGenericMethod<IsPlainDateTime, PlainDateTime_second>(cx, args); |
| 1219 |
} |
| 1220 |
|
| 1221 |
/** |
| 1222 |
* get Temporal.PlainDateTime.prototype.millisecond |
| 1223 |
*/ |
| 1224 |
static bool PlainDateTime_millisecond(JSContext* cx, const CallArgs& args) { |
| 1225 |
// Step 3. |
| 1226 |
auto* dateTime = &args.thisv().toObject().as<PlainDateTimeObject>(); |
| 1227 |
args.rval().setInt32(dateTime->time().millisecond); |
| 1228 |
return true; |
| 1229 |
} |
| 1230 |
|
| 1231 |
/** |
| 1232 |
* get Temporal.PlainDateTime.prototype.millisecond |
| 1233 |
*/ |
| 1234 |
static bool PlainDateTime_millisecond(JSContext* cx, unsigned argc, Value* vp) { |
| 1235 |
// Steps 1-2. |
| 1236 |
CallArgs args = CallArgsFromVp(argc, vp); |
| 1237 |
return CallNonGenericMethod<IsPlainDateTime, PlainDateTime_millisecond>(cx, |
| 1238 |
args); |
| 1239 |
} |
| 1240 |
|
| 1241 |
/** |
| 1242 |
* get Temporal.PlainDateTime.prototype.microsecond |
| 1243 |
*/ |
| 1244 |
static bool PlainDateTime_microsecond(JSContext* cx, const CallArgs& args) { |
| 1245 |
// Step 3. |
| 1246 |
auto* dateTime = &args.thisv().toObject().as<PlainDateTimeObject>(); |
| 1247 |
args.rval().setInt32(dateTime->time().microsecond); |
| 1248 |
return true; |
| 1249 |
} |
| 1250 |
|
| 1251 |
/** |
| 1252 |
* get Temporal.PlainDateTime.prototype.microsecond |
| 1253 |
*/ |
| 1254 |
static bool PlainDateTime_microsecond(JSContext* cx, unsigned argc, Value* vp) { |
| 1255 |
// Steps 1-2. |
| 1256 |
CallArgs args = CallArgsFromVp(argc, vp); |
| 1257 |
return CallNonGenericMethod<IsPlainDateTime, PlainDateTime_microsecond>(cx, |
| 1258 |
args); |
| 1259 |
} |
| 1260 |
|
| 1261 |
/** |
| 1262 |
* get Temporal.PlainDateTime.prototype.nanosecond |
| 1263 |
*/ |
| 1264 |
static bool PlainDateTime_nanosecond(JSContext* cx, const CallArgs& args) { |
| 1265 |
// Step 3. |
| 1266 |
auto* dateTime = &args.thisv().toObject().as<PlainDateTimeObject>(); |
| 1267 |
args.rval().setInt32(dateTime->time().nanosecond); |
| 1268 |
return true; |
| 1269 |
} |
| 1270 |
|
| 1271 |
/** |
| 1272 |
* get Temporal.PlainDateTime.prototype.nanosecond |
| 1273 |
*/ |
| 1274 |
static bool PlainDateTime_nanosecond(JSContext* cx, unsigned argc, Value* vp) { |
| 1275 |
// Steps 1-2. |
| 1276 |
CallArgs args = CallArgsFromVp(argc, vp); |
| 1277 |
return CallNonGenericMethod<IsPlainDateTime, PlainDateTime_nanosecond>(cx, |
| 1278 |
args); |
| 1279 |
} |
| 1280 |
|
| 1281 |
/** |
| 1282 |
* get Temporal.PlainDateTime.prototype.dayOfWeek |
| 1283 |
*/ |
| 1284 |
static bool PlainDateTime_dayOfWeek(JSContext* cx, const CallArgs& args) { |
| 1285 |
auto* dateTime = &args.thisv().toObject().as<PlainDateTimeObject>(); |
| 1286 |
Rooted<CalendarValue> calendar(cx, dateTime->calendar()); |
| 1287 |
|
| 1288 |
// Step 3. |
| 1289 |
return CalendarDayOfWeek(cx, calendar, dateTime->date(), args.rval()); |
| 1290 |
} |
| 1291 |
|
| 1292 |
/** |
| 1293 |
* get Temporal.PlainDateTime.prototype.dayOfWeek |
| 1294 |
*/ |
| 1295 |
static bool PlainDateTime_dayOfWeek(JSContext* cx, unsigned argc, Value* vp) { |
| 1296 |
// Steps 1-2. |
| 1297 |
CallArgs args = CallArgsFromVp(argc, vp); |
| 1298 |
return CallNonGenericMethod<IsPlainDateTime, PlainDateTime_dayOfWeek>(cx, |
| 1299 |
args); |
| 1300 |
} |
| 1301 |
|
| 1302 |
/** |
| 1303 |
* get Temporal.PlainDateTime.prototype.dayOfYear |
| 1304 |
*/ |
| 1305 |
static bool PlainDateTime_dayOfYear(JSContext* cx, const CallArgs& args) { |
| 1306 |
auto* dateTime = &args.thisv().toObject().as<PlainDateTimeObject>(); |
| 1307 |
Rooted<CalendarValue> calendar(cx, dateTime->calendar()); |
| 1308 |
|
| 1309 |
// Step 3. |
| 1310 |
return CalendarDayOfYear(cx, calendar, dateTime->date(), args.rval()); |
| 1311 |
} |
| 1312 |
|
| 1313 |
/** |
| 1314 |
* get Temporal.PlainDateTime.prototype.dayOfYear |
| 1315 |
*/ |
| 1316 |
static bool PlainDateTime_dayOfYear(JSContext* cx, unsigned argc, Value* vp) { |
| 1317 |
// Steps 1-2. |
| 1318 |
CallArgs args = CallArgsFromVp(argc, vp); |
| 1319 |
return CallNonGenericMethod<IsPlainDateTime, PlainDateTime_dayOfYear>(cx, |
| 1320 |
args); |
| 1321 |
} |
| 1322 |
|
| 1323 |
/** |
| 1324 |
* get Temporal.PlainDateTime.prototype.weekOfYear |
| 1325 |
*/ |
| 1326 |
static bool PlainDateTime_weekOfYear(JSContext* cx, const CallArgs& args) { |
| 1327 |
auto* dateTime = &args.thisv().toObject().as<PlainDateTimeObject>(); |
| 1328 |
Rooted<CalendarValue> calendar(cx, dateTime->calendar()); |
| 1329 |
|
| 1330 |
// Steps 3-5. |
| 1331 |
return CalendarWeekOfYear(cx, calendar, dateTime->date(), args.rval()); |
| 1332 |
} |
| 1333 |
|
| 1334 |
/** |
| 1335 |
* get Temporal.PlainDateTime.prototype.weekOfYear |
| 1336 |
*/ |
| 1337 |
static bool PlainDateTime_weekOfYear(JSContext* cx, unsigned argc, Value* vp) { |
| 1338 |
// Steps 1-2. |
| 1339 |
CallArgs args = CallArgsFromVp(argc, vp); |
| 1340 |
return CallNonGenericMethod<IsPlainDateTime, PlainDateTime_weekOfYear>(cx, |
| 1341 |
args); |
| 1342 |
} |
| 1343 |
|
| 1344 |
/** |
| 1345 |
* get Temporal.PlainDateTime.prototype.yearOfWeek |
| 1346 |
*/ |
| 1347 |
static bool PlainDateTime_yearOfWeek(JSContext* cx, const CallArgs& args) { |
| 1348 |
auto* dateTime = &args.thisv().toObject().as<PlainDateTimeObject>(); |
| 1349 |
Rooted<CalendarValue> calendar(cx, dateTime->calendar()); |
| 1350 |
|
| 1351 |
// Steps 3-5. |
| 1352 |
return CalendarYearOfWeek(cx, calendar, dateTime->date(), args.rval()); |
| 1353 |
} |
| 1354 |
|
| 1355 |
/** |
| 1356 |
* get Temporal.PlainDateTime.prototype.yearOfWeek |
| 1357 |
*/ |
| 1358 |
static bool PlainDateTime_yearOfWeek(JSContext* cx, unsigned argc, Value* vp) { |
| 1359 |
// Steps 1-2. |
| 1360 |
CallArgs args = CallArgsFromVp(argc, vp); |
| 1361 |
return CallNonGenericMethod<IsPlainDateTime, PlainDateTime_yearOfWeek>(cx, |
| 1362 |
args); |
| 1363 |
} |
| 1364 |
|
| 1365 |
/** |
| 1366 |
* get Temporal.PlainDateTime.prototype.daysInWeek |
| 1367 |
*/ |
| 1368 |
static bool PlainDateTime_daysInWeek(JSContext* cx, const CallArgs& args) { |
| 1369 |
auto* dateTime = &args.thisv().toObject().as<PlainDateTimeObject>(); |
| 1370 |
Rooted<CalendarValue> calendar(cx, dateTime->calendar()); |
| 1371 |
|
| 1372 |
// Step 3. |
| 1373 |
return CalendarDaysInWeek(cx, calendar, dateTime->date(), args.rval()); |
| 1374 |
} |
| 1375 |
|
| 1376 |
/** |
| 1377 |
* get Temporal.PlainDateTime.prototype.daysInWeek |
| 1378 |
*/ |
| 1379 |
static bool PlainDateTime_daysInWeek(JSContext* cx, unsigned argc, Value* vp) { |
| 1380 |
// Steps 1-2. |
| 1381 |
CallArgs args = CallArgsFromVp(argc, vp); |
| 1382 |
return CallNonGenericMethod<IsPlainDateTime, PlainDateTime_daysInWeek>(cx, |
| 1383 |
args); |
| 1384 |
} |
| 1385 |
|
| 1386 |
/** |
| 1387 |
* get Temporal.PlainDateTime.prototype.daysInMonth |
| 1388 |
*/ |
| 1389 |
static bool PlainDateTime_daysInMonth(JSContext* cx, const CallArgs& args) { |
| 1390 |
auto* dateTime = &args.thisv().toObject().as<PlainDateTimeObject>(); |
| 1391 |
Rooted<CalendarValue> calendar(cx, dateTime->calendar()); |
| 1392 |
|
| 1393 |
// Step 3. |
| 1394 |
return CalendarDaysInMonth(cx, calendar, dateTime->date(), args.rval()); |
| 1395 |
} |
| 1396 |
|
| 1397 |
/** |
| 1398 |
* get Temporal.PlainDateTime.prototype.daysInMonth |
| 1399 |
*/ |
| 1400 |
static bool PlainDateTime_daysInMonth(JSContext* cx, unsigned argc, Value* vp) { |
| 1401 |
// Steps 1-2. |
| 1402 |
CallArgs args = CallArgsFromVp(argc, vp); |
| 1403 |
return CallNonGenericMethod<IsPlainDateTime, PlainDateTime_daysInMonth>(cx, |
| 1404 |
args); |
| 1405 |
} |
| 1406 |
|
| 1407 |
/** |
| 1408 |
* get Temporal.PlainDateTime.prototype.daysInYear |
| 1409 |
*/ |
| 1410 |
static bool PlainDateTime_daysInYear(JSContext* cx, const CallArgs& args) { |
| 1411 |
auto* dateTime = &args.thisv().toObject().as<PlainDateTimeObject>(); |
| 1412 |
Rooted<CalendarValue> calendar(cx, dateTime->calendar()); |
| 1413 |
|
| 1414 |
// Step 3. |
| 1415 |
return CalendarDaysInYear(cx, calendar, dateTime->date(), args.rval()); |
| 1416 |
} |
| 1417 |
|
| 1418 |
/** |
| 1419 |
* get Temporal.PlainDateTime.prototype.daysInYear |
| 1420 |
*/ |
| 1421 |
static bool PlainDateTime_daysInYear(JSContext* cx, unsigned argc, Value* vp) { |
| 1422 |
// Steps 1-2. |
| 1423 |
CallArgs args = CallArgsFromVp(argc, vp); |
| 1424 |
return CallNonGenericMethod<IsPlainDateTime, PlainDateTime_daysInYear>(cx, |
| 1425 |
args); |
| 1426 |
} |
| 1427 |
|
| 1428 |
/** |
| 1429 |
* get Temporal.PlainDateTime.prototype.monthsInYear |
| 1430 |
*/ |
| 1431 |
static bool PlainDateTime_monthsInYear(JSContext* cx, const CallArgs& args) { |
| 1432 |
auto* dateTime = &args.thisv().toObject().as<PlainDateTimeObject>(); |
| 1433 |
Rooted<CalendarValue> calendar(cx, dateTime->calendar()); |
| 1434 |
|
| 1435 |
// Step 3. |
| 1436 |
return CalendarMonthsInYear(cx, calendar, dateTime->date(), args.rval()); |
| 1437 |
} |
| 1438 |
|
| 1439 |
/** |
| 1440 |
* get Temporal.PlainDateTime.prototype.monthsInYear |
| 1441 |
*/ |
| 1442 |
static bool PlainDateTime_monthsInYear(JSContext* cx, unsigned argc, |
| 1443 |
Value* vp) { |
| 1444 |
// Steps 1-2. |
| 1445 |
CallArgs args = CallArgsFromVp(argc, vp); |
| 1446 |
return CallNonGenericMethod<IsPlainDateTime, PlainDateTime_monthsInYear>( |
| 1447 |
cx, args); |
| 1448 |
} |
| 1449 |
|
| 1450 |
/** |
| 1451 |
* get Temporal.PlainDateTime.prototype.inLeapYear |
| 1452 |
*/ |
| 1453 |
static bool PlainDateTime_inLeapYear(JSContext* cx, const CallArgs& args) { |
| 1454 |
auto* dateTime = &args.thisv().toObject().as<PlainDateTimeObject>(); |
| 1455 |
Rooted<CalendarValue> calendar(cx, dateTime->calendar()); |
| 1456 |
|
| 1457 |
// Step 3. |
| 1458 |
return CalendarInLeapYear(cx, calendar, dateTime->date(), args.rval()); |
| 1459 |
} |
| 1460 |
|
| 1461 |
/** |
| 1462 |
* get Temporal.PlainDateTime.prototype.inLeapYear |
| 1463 |
*/ |
| 1464 |
static bool PlainDateTime_inLeapYear(JSContext* cx, unsigned argc, Value* vp) { |
| 1465 |
// Steps 1-2. |
| 1466 |
CallArgs args = CallArgsFromVp(argc, vp); |
| 1467 |
return CallNonGenericMethod<IsPlainDateTime, PlainDateTime_inLeapYear>(cx, |
| 1468 |
args); |
| 1469 |
} |
| 1470 |
|
| 1471 |
/** |
| 1472 |
* Temporal.PlainDateTime.prototype.with ( temporalDateTimeLike [ , options ] ) |
| 1473 |
*/ |
| 1474 |
static bool PlainDateTime_with(JSContext* cx, const CallArgs& args) { |
| 1475 |
Rooted<PlainDateTime> dateTime( |
| 1476 |
cx, &args.thisv().toObject().as<PlainDateTimeObject>()); |
| 1477 |
|
| 1478 |
// Step 3. |
| 1479 |
Rooted<JSObject*> temporalDateTimeLike( |
| 1480 |
cx, RequireObjectArg(cx, "temporalDateTimeLike", "with", args.get(0))); |
| 1481 |
if (!temporalDateTimeLike) { |
| 1482 |
return false; |
| 1483 |
} |
| 1484 |
if (!ThrowIfTemporalLikeObject(cx, temporalDateTimeLike)) { |
| 1485 |
return false; |
| 1486 |
} |
| 1487 |
|
| 1488 |
// Step 4. |
| 1489 |
auto calendar = dateTime.calendar(); |
| 1490 |
|
| 1491 |
// Step 5. |
| 1492 |
Rooted<CalendarFields> fields(cx); |
| 1493 |
if (!ISODateToFields(cx, dateTime, &fields)) { |
| 1494 |
return false; |
| 1495 |
} |
| 1496 |
|
| 1497 |
// Steps 6-11. |
| 1498 |
fields.setHour(dateTime.time().hour); |
| 1499 |
fields.setMinute(dateTime.time().minute); |
| 1500 |
fields.setSecond(dateTime.time().second); |
| 1501 |
fields.setMillisecond(dateTime.time().millisecond); |
| 1502 |
fields.setMicrosecond(dateTime.time().microsecond); |
| 1503 |
fields.setNanosecond(dateTime.time().nanosecond); |
| 1504 |
|
| 1505 |
// Step 12. |
| 1506 |
Rooted<CalendarFields> partialDateTime(cx); |
| 1507 |
if (!PreparePartialCalendarFields(cx, calendar, temporalDateTimeLike, |
| 1508 |
{ |
| 1509 |
CalendarField::Year, |
| 1510 |
CalendarField::Month, |
| 1511 |
CalendarField::MonthCode, |
| 1512 |
CalendarField::Day, |
| 1513 |
CalendarField::Hour, |
| 1514 |
CalendarField::Minute, |
| 1515 |
CalendarField::Second, |
| 1516 |
CalendarField::Millisecond, |
| 1517 |
CalendarField::Microsecond, |
| 1518 |
CalendarField::Nanosecond, |
| 1519 |
}, |
| 1520 |
&partialDateTime)) { |
| 1521 |
return false; |
| 1522 |
} |
| 1523 |
MOZ_ASSERT(!partialDateTime.keys().isEmpty()); |
| 1524 |
|
| 1525 |
// Step 13. |
| 1526 |
fields = CalendarMergeFields(calendar, fields, partialDateTime); |
| 1527 |
|
| 1528 |
// Steps 14-15. |
| 1529 |
auto overflow = TemporalOverflow::Constrain; |
| 1530 |
if (args.hasDefined(1)) { |
| 1531 |
// Step 14. |
| 1532 |
Rooted<JSObject*> options(cx, |
| 1533 |
RequireObjectArg(cx, "options", "with", args[1])); |
| 1534 |
if (!options) { |
| 1535 |
return false; |
| 1536 |
} |
| 1537 |
|
| 1538 |
// Step 15. |
| 1539 |
if (!GetTemporalOverflowOption(cx, options, &overflow)) { |
| 1540 |
return false; |
| 1541 |
} |
| 1542 |
} |
| 1543 |
|
| 1544 |
// Step 16. |
| 1545 |
ISODateTime result; |
| 1546 |
if (!InterpretTemporalDateTimeFields(cx, calendar, fields, overflow, |
| 1547 |
&result)) { |
| 1548 |
return false; |
| 1549 |
} |
| 1550 |
MOZ_ASSERT(IsValidISODateTime(result)); |
| 1551 |
|
| 1552 |
// Step 21. |
| 1553 |
auto* obj = CreateTemporalDateTime(cx, result, calendar); |
| 1554 |
if (!obj) { |
| 1555 |
return false; |
| 1556 |
} |
| 1557 |
|
| 1558 |
args.rval().setObject(*obj); |
| 1559 |
return true; |
| 1560 |
} |
| 1561 |
|
| 1562 |
/** |
| 1563 |
* Temporal.PlainDateTime.prototype.with ( temporalDateTimeLike [ , options ] ) |
| 1564 |
*/ |
| 1565 |
static bool PlainDateTime_with(JSContext* cx, unsigned argc, Value* vp) { |
| 1566 |
// Steps 1-2. |
| 1567 |
CallArgs args = CallArgsFromVp(argc, vp); |
| 1568 |
return CallNonGenericMethod<IsPlainDateTime, PlainDateTime_with>(cx, args); |
| 1569 |
} |
| 1570 |
|
| 1571 |
/** |
| 1572 |
* Temporal.PlainDateTime.prototype.withPlainTime ( [ plainTimeLike ] ) |
| 1573 |
*/ |
| 1574 |
static bool PlainDateTime_withPlainTime(JSContext* cx, const CallArgs& args) { |
| 1575 |
auto* temporalDateTime = &args.thisv().toObject().as<PlainDateTimeObject>(); |
| 1576 |
auto date = temporalDateTime->date(); |
| 1577 |
Rooted<CalendarValue> calendar(cx, temporalDateTime->calendar()); |
| 1578 |
|
| 1579 |
// Step 3. (Inlined ToTemporalTimeOrMidnight) |
| 1580 |
Time time = {}; |
| 1581 |
if (args.hasDefined(0)) { |
| 1582 |
if (!ToTemporalTime(cx, args[0], &time)) { |
| 1583 |
return false; |
| 1584 |
} |
| 1585 |
} |
| 1586 |
|
| 1587 |
// Step 4. |
| 1588 |
auto isoDateTime = ISODateTime{date, time}; |
| 1589 |
|
| 1590 |
// Step 5. |
| 1591 |
auto* obj = CreateTemporalDateTime(cx, isoDateTime, calendar); |
| 1592 |
if (!obj) { |
| 1593 |
return false; |
| 1594 |
} |
| 1595 |
|
| 1596 |
args.rval().setObject(*obj); |
| 1597 |
return true; |
| 1598 |
} |
| 1599 |
|
| 1600 |
/** |
| 1601 |
* Temporal.PlainDateTime.prototype.withPlainTime ( [ plainTimeLike ] ) |
| 1602 |
*/ |
| 1603 |
static bool PlainDateTime_withPlainTime(JSContext* cx, unsigned argc, |
| 1604 |
Value* vp) { |
| 1605 |
// Steps 1-2. |
| 1606 |
CallArgs args = CallArgsFromVp(argc, vp); |
| 1607 |
return CallNonGenericMethod<IsPlainDateTime, PlainDateTime_withPlainTime>( |
| 1608 |
cx, args); |
| 1609 |
} |
| 1610 |
|
| 1611 |
/** |
| 1612 |
* Temporal.PlainDateTime.prototype.withCalendar ( calendar ) |
| 1613 |
*/ |
| 1614 |
static bool PlainDateTime_withCalendar(JSContext* cx, const CallArgs& args) { |
| 1615 |
auto* temporalDateTime = &args.thisv().toObject().as<PlainDateTimeObject>(); |
| 1616 |
auto dateTime = temporalDateTime->dateTime(); |
| 1617 |
|
| 1618 |
// Step 3. |
| 1619 |
Rooted<CalendarValue> calendar(cx); |
| 1620 |
if (!ToTemporalCalendar(cx, args.get(0), &calendar)) { |
| 1621 |
return false; |
| 1622 |
} |
| 1623 |
|
| 1624 |
// Step 4. |
| 1625 |
auto* result = CreateTemporalDateTime(cx, dateTime, calendar); |
| 1626 |
if (!result) { |
| 1627 |
return false; |
| 1628 |
} |
| 1629 |
|
| 1630 |
args.rval().setObject(*result); |
| 1631 |
return true; |
| 1632 |
} |
| 1633 |
|
| 1634 |
/** |
| 1635 |
* Temporal.PlainDateTime.prototype.withCalendar ( calendar ) |
| 1636 |
*/ |
| 1637 |
static bool PlainDateTime_withCalendar(JSContext* cx, unsigned argc, |
| 1638 |
Value* vp) { |
| 1639 |
// Steps 1-2. |
| 1640 |
CallArgs args = CallArgsFromVp(argc, vp); |
| 1641 |
return CallNonGenericMethod<IsPlainDateTime, PlainDateTime_withCalendar>( |
| 1642 |
cx, args); |
| 1643 |
} |
| 1644 |
|
| 1645 |
/** |
| 1646 |
* Temporal.PlainDateTime.prototype.add ( temporalDurationLike [ , options ] ) |
| 1647 |
*/ |
| 1648 |
static bool PlainDateTime_add(JSContext* cx, const CallArgs& args) { |
| 1649 |
// Step 3. |
| 1650 |
return AddDurationToDateTime(cx, TemporalAddDuration::Add, args); |
| 1651 |
} |
| 1652 |
|
| 1653 |
/** |
| 1654 |
* Temporal.PlainDateTime.prototype.add ( temporalDurationLike [ , options ] ) |
| 1655 |
*/ |
| 1656 |
static bool PlainDateTime_add(JSContext* cx, unsigned argc, Value* vp) { |
| 1657 |
// Steps 1-2. |
| 1658 |
CallArgs args = CallArgsFromVp(argc, vp); |
| 1659 |
return CallNonGenericMethod<IsPlainDateTime, PlainDateTime_add>(cx, args); |
| 1660 |
} |
| 1661 |
|
| 1662 |
/** |
| 1663 |
* Temporal.PlainDateTime.prototype.subtract ( temporalDurationLike [ , options |
| 1664 |
* ] ) |
| 1665 |
*/ |
| 1666 |
static bool PlainDateTime_subtract(JSContext* cx, const CallArgs& args) { |
| 1667 |
// Step 3. |
| 1668 |
return AddDurationToDateTime(cx, TemporalAddDuration::Subtract, args); |
| 1669 |
} |
| 1670 |
|
| 1671 |
/** |
| 1672 |
* Temporal.PlainDateTime.prototype.subtract ( temporalDurationLike [ , options |
| 1673 |
* ] ) |
| 1674 |
*/ |
| 1675 |
static bool PlainDateTime_subtract(JSContext* cx, unsigned argc, Value* vp) { |
| 1676 |
// Steps 1-2. |
| 1677 |
CallArgs args = CallArgsFromVp(argc, vp); |
| 1678 |
return CallNonGenericMethod<IsPlainDateTime, PlainDateTime_subtract>(cx, |
| 1679 |
args); |
| 1680 |
} |
| 1681 |
|
| 1682 |
/** |
| 1683 |
* Temporal.PlainDateTime.prototype.until ( other [ , options ] ) |
| 1684 |
*/ |
| 1685 |
static bool PlainDateTime_until(JSContext* cx, const CallArgs& args) { |
| 1686 |
// Step 3. |
| 1687 |
return DifferenceTemporalPlainDateTime(cx, TemporalDifference::Until, args); |
| 1688 |
} |
| 1689 |
|
| 1690 |
/** |
| 1691 |
* Temporal.PlainDateTime.prototype.until ( other [ , options ] ) |
| 1692 |
*/ |
| 1693 |
static bool PlainDateTime_until(JSContext* cx, unsigned argc, Value* vp) { |
| 1694 |
// Steps 1-2. |
| 1695 |
CallArgs args = CallArgsFromVp(argc, vp); |
| 1696 |
return CallNonGenericMethod<IsPlainDateTime, PlainDateTime_until>(cx, args); |
| 1697 |
} |
| 1698 |
|
| 1699 |
/** |
| 1700 |
* Temporal.PlainDateTime.prototype.since ( other [ , options ] ) |
| 1701 |
*/ |
| 1702 |
static bool PlainDateTime_since(JSContext* cx, const CallArgs& args) { |
| 1703 |
// Step 3. |
| 1704 |
return DifferenceTemporalPlainDateTime(cx, TemporalDifference::Since, args); |
| 1705 |
} |
| 1706 |
|
| 1707 |
/** |
| 1708 |
* Temporal.PlainDateTime.prototype.since ( other [ , options ] ) |
| 1709 |
*/ |
| 1710 |
static bool PlainDateTime_since(JSContext* cx, unsigned argc, Value* vp) { |
| 1711 |
// Steps 1-2. |
| 1712 |
CallArgs args = CallArgsFromVp(argc, vp); |
| 1713 |
return CallNonGenericMethod<IsPlainDateTime, PlainDateTime_since>(cx, args); |
| 1714 |
} |
| 1715 |
|
| 1716 |
/** |
| 1717 |
* Temporal.PlainDateTime.prototype.round ( roundTo ) |
| 1718 |
*/ |
| 1719 |
static bool PlainDateTime_round(JSContext* cx, const CallArgs& args) { |
| 1720 |
auto* temporalDateTime = &args.thisv().toObject().as<PlainDateTimeObject>(); |
| 1721 |
auto dateTime = temporalDateTime->dateTime(); |
| 1722 |
Rooted<CalendarValue> calendar(cx, temporalDateTime->calendar()); |
| 1723 |
|
| 1724 |
// Steps 3-12. |
| 1725 |
auto smallestUnit = TemporalUnit::Auto; |
| 1726 |
auto roundingMode = TemporalRoundingMode::HalfExpand; |
| 1727 |
auto roundingIncrement = Increment{1}; |
| 1728 |
if (args.get(0).isString()) { |
| 1729 |
// Step 4. (Not applicable in our implementation.) |
| 1730 |
|
| 1731 |
// Step 9. |
| 1732 |
Rooted<JSString*> paramString(cx, args[0].toString()); |
| 1733 |
if (!GetTemporalUnitValuedOption( |
| 1734 |
cx, paramString, TemporalUnitKey::SmallestUnit, |
| 1735 |
TemporalUnitGroup::DayTime, &smallestUnit)) { |
| 1736 |
return false; |
| 1737 |
} |
| 1738 |
|
| 1739 |
MOZ_ASSERT(TemporalUnit::Day <= smallestUnit && |
| 1740 |
smallestUnit <= TemporalUnit::Nanosecond); |
| 1741 |
|
| 1742 |
// Steps 6-8 and 10-12. (Implicit) |
| 1743 |
} else { |
| 1744 |
// Steps 3 and 5. |
| 1745 |
Rooted<JSObject*> roundTo( |
| 1746 |
cx, RequireObjectArg(cx, "roundTo", "round", args.get(0))); |
| 1747 |
if (!roundTo) { |
| 1748 |
return false; |
| 1749 |
} |
| 1750 |
|
| 1751 |
// Steps 6-7. |
| 1752 |
if (!GetRoundingIncrementOption(cx, roundTo, &roundingIncrement)) { |
| 1753 |
return false; |
| 1754 |
} |
| 1755 |
|
| 1756 |
// Step 8. |
| 1757 |
if (!GetRoundingModeOption(cx, roundTo, &roundingMode)) { |
| 1758 |
return false; |
| 1759 |
} |
| 1760 |
|
| 1761 |
// Step 9. |
| 1762 |
if (!GetTemporalUnitValuedOption(cx, roundTo, TemporalUnitKey::SmallestUnit, |
| 1763 |
TemporalUnitGroup::DayTime, |
| 1764 |
&smallestUnit)) { |
| 1765 |
return false; |
| 1766 |
} |
| 1767 |
|
| 1768 |
if (smallestUnit == TemporalUnit::Auto) { |
| 1769 |
JS_ReportErrorNumberASCII(cx, GetErrorMessage, nullptr, |
| 1770 |
JSMSG_TEMPORAL_MISSING_OPTION, "smallestUnit"); |
| 1771 |
return false; |
| 1772 |
} |
| 1773 |
|
| 1774 |
MOZ_ASSERT(TemporalUnit::Day <= smallestUnit && |
| 1775 |
smallestUnit <= TemporalUnit::Nanosecond); |
| 1776 |
|
| 1777 |
// Steps 10-11. |
| 1778 |
auto maximum = Increment{1}; |
| 1779 |
bool inclusive = true; |
| 1780 |
if (smallestUnit > TemporalUnit::Day) { |
| 1781 |
maximum = MaximumTemporalDurationRoundingIncrement(smallestUnit); |
| 1782 |
inclusive = false; |
| 1783 |
} |
| 1784 |
|
| 1785 |
// Step 12. |
| 1786 |
if (!ValidateTemporalRoundingIncrement(cx, roundingIncrement, maximum, |
| 1787 |
inclusive)) { |
| 1788 |
return false; |
| 1789 |
} |
| 1790 |
} |
| 1791 |
|
| 1792 |
// Step 13. |
| 1793 |
if (smallestUnit == TemporalUnit::Nanosecond && |
| 1794 |
roundingIncrement == Increment{1}) { |
| 1795 |
auto* obj = CreateTemporalDateTime(cx, dateTime, calendar); |
| 1796 |
if (!obj) { |
| 1797 |
return false; |
| 1798 |
} |
| 1799 |
|
| 1800 |
args.rval().setObject(*obj); |
| 1801 |
return true; |
| 1802 |
} |
| 1803 |
|
| 1804 |
// Step 14. |
| 1805 |
auto result = |
| 1806 |
RoundISODateTime(dateTime, roundingIncrement, smallestUnit, roundingMode); |
| 1807 |
|
| 1808 |
// Step 15. |
| 1809 |
auto* obj = CreateTemporalDateTime(cx, result, calendar); |
| 1810 |
if (!obj) { |
| 1811 |
return false; |
| 1812 |
} |
| 1813 |
|
| 1814 |
args.rval().setObject(*obj); |
| 1815 |
return true; |
| 1816 |
} |
| 1817 |
|
| 1818 |
/** |
| 1819 |
* Temporal.PlainDateTime.prototype.round ( roundTo ) |
| 1820 |
*/ |
| 1821 |
static bool PlainDateTime_round(JSContext* cx, unsigned argc, Value* vp) { |
| 1822 |
// Steps 1-2. |
| 1823 |
CallArgs args = CallArgsFromVp(argc, vp); |
| 1824 |
return CallNonGenericMethod<IsPlainDateTime, PlainDateTime_round>(cx, args); |
| 1825 |
} |
| 1826 |
|
| 1827 |
/** |
| 1828 |
* Temporal.PlainDateTime.prototype.equals ( other ) |
| 1829 |
*/ |
| 1830 |
static bool PlainDateTime_equals(JSContext* cx, const CallArgs& args) { |
| 1831 |
auto* temporalDateTime = &args.thisv().toObject().as<PlainDateTimeObject>(); |
| 1832 |
auto dateTime = temporalDateTime->dateTime(); |
| 1833 |
Rooted<CalendarValue> calendar(cx, temporalDateTime->calendar()); |
| 1834 |
|
| 1835 |
// Step 3. |
| 1836 |
Rooted<PlainDateTime> other(cx); |
| 1837 |
if (!ToTemporalDateTime(cx, args.get(0), &other)) { |
| 1838 |
return false; |
| 1839 |
} |
| 1840 |
|
| 1841 |
// Steps 4-5. |
| 1842 |
bool equals = dateTime == other.dateTime() && |
| 1843 |
CalendarEquals(calendar, other.calendar()); |
| 1844 |
|
| 1845 |
args.rval().setBoolean(equals); |
| 1846 |
return true; |
| 1847 |
} |
| 1848 |
|
| 1849 |
/** |
| 1850 |
* Temporal.PlainDateTime.prototype.equals ( other ) |
| 1851 |
*/ |
| 1852 |
static bool PlainDateTime_equals(JSContext* cx, unsigned argc, Value* vp) { |
| 1853 |
// Steps 1-2. |
| 1854 |
CallArgs args = CallArgsFromVp(argc, vp); |
| 1855 |
return CallNonGenericMethod<IsPlainDateTime, PlainDateTime_equals>(cx, args); |
| 1856 |
} |
| 1857 |
|
| 1858 |
/** |
| 1859 |
* Temporal.PlainDateTime.prototype.toString ( [ options ] ) |
| 1860 |
*/ |
| 1861 |
static bool PlainDateTime_toString(JSContext* cx, const CallArgs& args) { |
| 1862 |
auto* dateTime = &args.thisv().toObject().as<PlainDateTimeObject>(); |
| 1863 |
auto dt = dateTime->dateTime(); |
| 1864 |
Rooted<CalendarValue> calendar(cx, dateTime->calendar()); |
| 1865 |
|
| 1866 |
SecondsStringPrecision precision = {Precision::Auto(), |
| 1867 |
TemporalUnit::Nanosecond, Increment{1}}; |
| 1868 |
auto roundingMode = TemporalRoundingMode::Trunc; |
| 1869 |
auto showCalendar = ShowCalendar::Auto; |
| 1870 |
if (args.hasDefined(0)) { |
| 1871 |
// Step 3. |
| 1872 |
Rooted<JSObject*> options( |
| 1873 |
cx, RequireObjectArg(cx, "options", "toString", args[0])); |
| 1874 |
if (!options) { |
| 1875 |
return false; |
| 1876 |
} |
| 1877 |
|
| 1878 |
// Steps 4-5. |
| 1879 |
if (!GetTemporalShowCalendarNameOption(cx, options, &showCalendar)) { |
| 1880 |
return false; |
| 1881 |
} |
| 1882 |
|
| 1883 |
// Step 6. |
| 1884 |
auto digits = Precision::Auto(); |
| 1885 |
if (!GetTemporalFractionalSecondDigitsOption(cx, options, &digits)) { |
| 1886 |
return false; |
| 1887 |
} |
| 1888 |
|
| 1889 |
// Step 7. |
| 1890 |
if (!GetRoundingModeOption(cx, options, &roundingMode)) { |
| 1891 |
return false; |
| 1892 |
} |
| 1893 |
|
| 1894 |
// Step 8. |
| 1895 |
auto smallestUnit = TemporalUnit::Auto; |
| 1896 |
if (!GetTemporalUnitValuedOption(cx, options, TemporalUnitKey::SmallestUnit, |
| 1897 |
TemporalUnitGroup::Time, &smallestUnit)) { |
| 1898 |
return false; |
| 1899 |
} |
| 1900 |
|
| 1901 |
// Step 9. |
| 1902 |
if (smallestUnit == TemporalUnit::Hour) { |
| 1903 |
JS_ReportErrorNumberASCII(cx, GetErrorMessage, nullptr, |
| 1904 |
JSMSG_TEMPORAL_INVALID_UNIT_OPTION, "hour", |
| 1905 |
"smallestUnit"); |
| 1906 |
return false; |
| 1907 |
} |
| 1908 |
|
| 1909 |
// Step 10. |
| 1910 |
precision = ToSecondsStringPrecision(smallestUnit, digits); |
| 1911 |
} |
| 1912 |
|
| 1913 |
// Step 11. |
| 1914 |
auto result = |
| 1915 |
RoundISODateTime(dt, precision.increment, precision.unit, roundingMode); |
| 1916 |
|
| 1917 |
// Step 12. |
| 1918 |
if (!ISODateTimeWithinLimits(result)) { |
| 1919 |
JS_ReportErrorNumberASCII(cx, GetErrorMessage, nullptr, |
| 1920 |
JSMSG_TEMPORAL_PLAIN_DATE_TIME_INVALID); |
| 1921 |
return false; |
| 1922 |
} |
| 1923 |
|
| 1924 |
// Step 13. |
| 1925 |
JSString* str = ISODateTimeToString(cx, result, calendar, precision.precision, |
| 1926 |
showCalendar); |
| 1927 |
if (!str) { |
| 1928 |
return false; |
| 1929 |
} |
| 1930 |
|
| 1931 |
args.rval().setString(str); |
| 1932 |
return true; |
| 1933 |
} |
| 1934 |
|
| 1935 |
/** |
| 1936 |
* Temporal.PlainDateTime.prototype.toString ( [ options ] ) |
| 1937 |
*/ |
| 1938 |
static bool PlainDateTime_toString(JSContext* cx, unsigned argc, Value* vp) { |
| 1939 |
// Steps 1-2. |
| 1940 |
CallArgs args = CallArgsFromVp(argc, vp); |
| 1941 |
return CallNonGenericMethod<IsPlainDateTime, PlainDateTime_toString>(cx, |
| 1942 |
args); |
| 1943 |
} |
| 1944 |
|
| 1945 |
/** |
| 1946 |
* Temporal.PlainDateTime.prototype.toLocaleString ( [ locales [ , options ] ] ) |
| 1947 |
*/ |
| 1948 |
static bool PlainDateTime_toLocaleString(JSContext* cx, const CallArgs& args) { |
| 1949 |
// Steps 3-4. |
| 1950 |
Handle<PropertyName*> required = cx->names().any; |
| 1951 |
Handle<PropertyName*> defaults = cx->names().all; |
| 1952 |
return TemporalObjectToLocaleString(cx, args, required, defaults); |
| 1953 |
} |
| 1954 |
|
| 1955 |
/** |
| 1956 |
* Temporal.PlainDateTime.prototype.toLocaleString ( [ locales [ , options ] ] ) |
| 1957 |
*/ |
| 1958 |
static bool PlainDateTime_toLocaleString(JSContext* cx, unsigned argc, |
| 1959 |
Value* vp) { |
| 1960 |
// Steps 1-2. |
| 1961 |
CallArgs args = CallArgsFromVp(argc, vp); |
| 1962 |
return CallNonGenericMethod<IsPlainDateTime, PlainDateTime_toLocaleString>( |
| 1963 |
cx, args); |
| 1964 |
} |
| 1965 |
|
| 1966 |
/** |
| 1967 |
* Temporal.PlainDateTime.prototype.toJSON ( ) |
| 1968 |
*/ |
| 1969 |
static bool PlainDateTime_toJSON(JSContext* cx, const CallArgs& args) { |
| 1970 |
auto* dateTime = &args.thisv().toObject().as<PlainDateTimeObject>(); |
| 1971 |
auto dt = dateTime->dateTime(); |
| 1972 |
Rooted<CalendarValue> calendar(cx, dateTime->calendar()); |
| 1973 |
|
| 1974 |
// Step 3. |
| 1975 |
JSString* str = ISODateTimeToString(cx, dt, calendar, Precision::Auto(), |
| 1976 |
ShowCalendar::Auto); |
| 1977 |
if (!str) { |
| 1978 |
return false; |
| 1979 |
} |
| 1980 |
|
| 1981 |
args.rval().setString(str); |
| 1982 |
return true; |
| 1983 |
} |
| 1984 |
|
| 1985 |
/** |
| 1986 |
* Temporal.PlainDateTime.prototype.toJSON ( ) |
| 1987 |
*/ |
| 1988 |
static bool PlainDateTime_toJSON(JSContext* cx, unsigned argc, Value* vp) { |
| 1989 |
// Steps 1-2. |
| 1990 |
CallArgs args = CallArgsFromVp(argc, vp); |
| 1991 |
return CallNonGenericMethod<IsPlainDateTime, PlainDateTime_toJSON>(cx, args); |
| 1992 |
} |
| 1993 |
|
| 1994 |
/** |
| 1995 |
* Temporal.PlainDateTime.prototype.valueOf ( ) |
| 1996 |
*/ |
| 1997 |
static bool PlainDateTime_valueOf(JSContext* cx, unsigned argc, Value* vp) { |
| 1998 |
JS_ReportErrorNumberASCII(cx, GetErrorMessage, nullptr, JSMSG_CANT_CONVERT_TO, |
| 1999 |
"PlainDateTime", "primitive type"); |
| 2000 |
return false; |
| 2001 |
} |
| 2002 |
|
| 2003 |
/** |
| 2004 |
* Temporal.PlainDateTime.prototype.toZonedDateTime ( temporalTimeZoneLike [ , |
| 2005 |
* options ] ) |
| 2006 |
*/ |
| 2007 |
static bool PlainDateTime_toZonedDateTime(JSContext* cx, const CallArgs& args) { |
| 2008 |
auto* temporalDateTime = &args.thisv().toObject().as<PlainDateTimeObject>(); |
| 2009 |
auto isoDateTime = temporalDateTime->dateTime(); |
| 2010 |
Rooted<CalendarValue> calendar(cx, temporalDateTime->calendar()); |
| 2011 |
|
| 2012 |
// Step 3. |
| 2013 |
Rooted<TimeZoneValue> timeZone(cx); |
| 2014 |
if (!ToTemporalTimeZone(cx, args.get(0), &timeZone)) { |
| 2015 |
return false; |
| 2016 |
} |
| 2017 |
|
| 2018 |
auto disambiguation = TemporalDisambiguation::Compatible; |
| 2019 |
if (args.hasDefined(1)) { |
| 2020 |
// Step 4. |
| 2021 |
Rooted<JSObject*> options( |
| 2022 |
cx, RequireObjectArg(cx, "options", "toZonedDateTime", args[1])); |
| 2023 |
if (!options) { |
| 2024 |
return false; |
| 2025 |
} |
| 2026 |
|
| 2027 |
// Step 5. |
| 2028 |
if (!GetTemporalDisambiguationOption(cx, options, &disambiguation)) { |
| 2029 |
return false; |
| 2030 |
} |
| 2031 |
} |
| 2032 |
|
| 2033 |
// Step 6. |
| 2034 |
EpochNanoseconds epochNs; |
| 2035 |
if (!GetEpochNanosecondsFor(cx, timeZone, isoDateTime, disambiguation, |
| 2036 |
&epochNs)) { |
| 2037 |
return false; |
| 2038 |
} |
| 2039 |
|
| 2040 |
// Step 7. |
| 2041 |
auto* result = CreateTemporalZonedDateTime(cx, epochNs, timeZone, calendar); |
| 2042 |
if (!result) { |
| 2043 |
return false; |
| 2044 |
} |
| 2045 |
|
| 2046 |
args.rval().setObject(*result); |
| 2047 |
return true; |
| 2048 |
} |
| 2049 |
|
| 2050 |
/** |
| 2051 |
* Temporal.PlainDateTime.prototype.toZonedDateTime ( temporalTimeZoneLike [ , |
| 2052 |
* options ] ) |
| 2053 |
*/ |
| 2054 |
static bool PlainDateTime_toZonedDateTime(JSContext* cx, unsigned argc, |
| 2055 |
Value* vp) { |
| 2056 |
// Steps 1-2. |
| 2057 |
CallArgs args = CallArgsFromVp(argc, vp); |
| 2058 |
return CallNonGenericMethod<IsPlainDateTime, PlainDateTime_toZonedDateTime>( |
| 2059 |
cx, args); |
| 2060 |
} |
| 2061 |
|
| 2062 |
/** |
| 2063 |
* Temporal.PlainDateTime.prototype.toPlainDate ( ) |
| 2064 |
*/ |
| 2065 |
static bool PlainDateTime_toPlainDate(JSContext* cx, const CallArgs& args) { |
| 2066 |
auto* dateTime = &args.thisv().toObject().as<PlainDateTimeObject>(); |
| 2067 |
Rooted<CalendarValue> calendar(cx, dateTime->calendar()); |
| 2068 |
|
| 2069 |
// Step 3. |
| 2070 |
auto* obj = CreateTemporalDate(cx, dateTime->date(), calendar); |
| 2071 |
if (!obj) { |
| 2072 |
return false; |
| 2073 |
} |
| 2074 |
|
| 2075 |
args.rval().setObject(*obj); |
| 2076 |
return true; |
| 2077 |
} |
| 2078 |
|
| 2079 |
/** |
| 2080 |
* Temporal.PlainDateTime.prototype.toPlainDate ( ) |
| 2081 |
*/ |
| 2082 |
static bool PlainDateTime_toPlainDate(JSContext* cx, unsigned argc, Value* vp) { |
| 2083 |
// Steps 1-2. |
| 2084 |
CallArgs args = CallArgsFromVp(argc, vp); |
| 2085 |
return CallNonGenericMethod<IsPlainDateTime, PlainDateTime_toPlainDate>(cx, |
| 2086 |
args); |
| 2087 |
} |
| 2088 |
|
| 2089 |
/** |
| 2090 |
* Temporal.PlainDateTime.prototype.toPlainTime ( ) |
| 2091 |
*/ |
| 2092 |
static bool PlainDateTime_toPlainTime(JSContext* cx, const CallArgs& args) { |
| 2093 |
auto* dateTime = &args.thisv().toObject().as<PlainDateTimeObject>(); |
| 2094 |
|
| 2095 |
// Step 3. |
| 2096 |
auto* obj = CreateTemporalTime(cx, dateTime->time()); |
| 2097 |
if (!obj) { |
| 2098 |
return false; |
| 2099 |
} |
| 2100 |
|
| 2101 |
args.rval().setObject(*obj); |
| 2102 |
return true; |
| 2103 |
} |
| 2104 |
|
| 2105 |
/** |
| 2106 |
* Temporal.PlainDateTime.prototype.toPlainTime ( ) |
| 2107 |
*/ |
| 2108 |
static bool PlainDateTime_toPlainTime(JSContext* cx, unsigned argc, Value* vp) { |
| 2109 |
// Steps 1-2. |
| 2110 |
CallArgs args = CallArgsFromVp(argc, vp); |
| 2111 |
return CallNonGenericMethod<IsPlainDateTime, PlainDateTime_toPlainTime>(cx, |
| 2112 |
args); |
| 2113 |
} |
| 2114 |
|
| 2115 |
const JSClass PlainDateTimeObject::class_ = { |
| 2116 |
"Temporal.PlainDateTime", |
| 2117 |
JSCLASS_HAS_RESERVED_SLOTS(PlainDateTimeObject::SLOT_COUNT) | |
| 2118 |
JSCLASS_HAS_CACHED_PROTO(JSProto_PlainDateTime), |
| 2119 |
JS_NULL_CLASS_OPS, |
| 2120 |
&PlainDateTimeObject::classSpec_, |
| 2121 |
}; |
| 2122 |
|
| 2123 |
const JSClass& PlainDateTimeObject::protoClass_ = PlainObject::class_; |
| 2124 |
|
| 2125 |
static const JSFunctionSpec PlainDateTime_methods[] = { |
| 2126 |
JS_FN("from", PlainDateTime_from, 1, 0), |
| 2127 |
JS_FN("compare", PlainDateTime_compare, 2, 0), |
| 2128 |
JS_FS_END, |
| 2129 |
}; |
| 2130 |
|
| 2131 |
static const JSFunctionSpec PlainDateTime_prototype_methods[] = { |
| 2132 |
JS_FN("with", PlainDateTime_with, 1, 0), |
| 2133 |
JS_FN("withPlainTime", PlainDateTime_withPlainTime, 0, 0), |
| 2134 |
JS_FN("withCalendar", PlainDateTime_withCalendar, 1, 0), |
| 2135 |
JS_FN("add", PlainDateTime_add, 1, 0), |
| 2136 |
JS_FN("subtract", PlainDateTime_subtract, 1, 0), |
| 2137 |
JS_FN("until", PlainDateTime_until, 1, 0), |
| 2138 |
JS_FN("since", PlainDateTime_since, 1, 0), |
| 2139 |
JS_FN("round", PlainDateTime_round, 1, 0), |
| 2140 |
JS_FN("equals", PlainDateTime_equals, 1, 0), |
| 2141 |
JS_FN("toString", PlainDateTime_toString, 0, 0), |
| 2142 |
JS_FN("toLocaleString", PlainDateTime_toLocaleString, 0, 0), |
| 2143 |
JS_FN("toJSON", PlainDateTime_toJSON, 0, 0), |
| 2144 |
JS_FN("valueOf", PlainDateTime_valueOf, 0, 0), |
| 2145 |
JS_FN("toZonedDateTime", PlainDateTime_toZonedDateTime, 1, 0), |
| 2146 |
JS_FN("toPlainDate", PlainDateTime_toPlainDate, 0, 0), |
| 2147 |
JS_FN("toPlainTime", PlainDateTime_toPlainTime, 0, 0), |
| 2148 |
JS_FS_END, |
| 2149 |
}; |
| 2150 |
|
| 2151 |
static const JSPropertySpec PlainDateTime_prototype_properties[] = { |
| 2152 |
JS_PSG("calendarId", PlainDateTime_calendarId, 0), |
| 2153 |
JS_PSG("era", PlainDateTime_era, 0), |
| 2154 |
JS_PSG("eraYear", PlainDateTime_eraYear, 0), |
| 2155 |
JS_PSG("year", PlainDateTime_year, 0), |
| 2156 |
JS_PSG("month", PlainDateTime_month, 0), |
| 2157 |
JS_PSG("monthCode", PlainDateTime_monthCode, 0), |
| 2158 |
JS_PSG("day", PlainDateTime_day, 0), |
| 2159 |
JS_PSG("hour", PlainDateTime_hour, 0), |
| 2160 |
JS_PSG("minute", PlainDateTime_minute, 0), |
| 2161 |
JS_PSG("second", PlainDateTime_second, 0), |
| 2162 |
JS_PSG("millisecond", PlainDateTime_millisecond, 0), |
| 2163 |
JS_PSG("microsecond", PlainDateTime_microsecond, 0), |
| 2164 |
JS_PSG("nanosecond", PlainDateTime_nanosecond, 0), |
| 2165 |
JS_PSG("dayOfWeek", PlainDateTime_dayOfWeek, 0), |
| 2166 |
JS_PSG("dayOfYear", PlainDateTime_dayOfYear, 0), |
| 2167 |
JS_PSG("weekOfYear", PlainDateTime_weekOfYear, 0), |
| 2168 |
JS_PSG("yearOfWeek", PlainDateTime_yearOfWeek, 0), |
| 2169 |
JS_PSG("daysInWeek", PlainDateTime_daysInWeek, 0), |
| 2170 |
JS_PSG("daysInMonth", PlainDateTime_daysInMonth, 0), |
| 2171 |
JS_PSG("daysInYear", PlainDateTime_daysInYear, 0), |
| 2172 |
JS_PSG("monthsInYear", PlainDateTime_monthsInYear, 0), |
| 2173 |
JS_PSG("inLeapYear", PlainDateTime_inLeapYear, 0), |
| 2174 |
JS_STRING_SYM_PS(toStringTag, "Temporal.PlainDateTime", JSPROP_READONLY), |
| 2175 |
JS_PS_END, |
| 2176 |
}; |
| 2177 |
|
| 2178 |
const ClassSpec PlainDateTimeObject::classSpec_ = { |
| 2179 |
GenericCreateConstructor<PlainDateTimeConstructor, 3, |
| 2180 |
gc::AllocKind::FUNCTION>, |
| 2181 |
GenericCreatePrototype<PlainDateTimeObject>, |
| 2182 |
PlainDateTime_methods, |
| 2183 |
nullptr, |
| 2184 |
PlainDateTime_prototype_methods, |
| 2185 |
PlainDateTime_prototype_properties, |
| 2186 |
nullptr, |
| 2187 |
ClassSpec::DontDefineConstructor, |
| 2188 |
}; |