1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
|
// |reftest| skip-if(!this.hasOwnProperty('Temporal')) -- Temporal is not enabled unconditionally
// Copyright (C) 2021 Igalia, S.L. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-temporal.plaindate.prototype.withcalendar
description: Fast path for converting other Temporal objects to Temporal.Calendar by reading internal slots
info: |
sec-temporal-totemporalcalendar step 1.b:
b. If _temporalCalendarLike_ has an [[InitializedTemporalDate]], [[InitializedTemporalDateTime]], [[InitializedTemporalMonthDay]], [[InitializedTemporalYearMonth]], or [[InitializedTemporalZonedDateTime]] internal slot, then
i. Return _temporalCalendarLike_.[[Calendar]].
includes: [compareArray.js]
features: [Temporal]
---*/
const plainDate = new Temporal.PlainDate(2000, 5, 2);
const plainDateTime = new Temporal.PlainDateTime(2000, 5, 2, 12, 34, 56, 987, 654, 321);
const plainMonthDay = new Temporal.PlainMonthDay(5, 2);
const plainYearMonth = new Temporal.PlainYearMonth(2000, 5);
const zonedDateTime = new Temporal.ZonedDateTime(1_000_000_000_000_000_000n, "UTC");
[plainDate, plainDateTime, plainMonthDay, plainYearMonth, zonedDateTime].forEach((arg) => {
const actual = [];
const expected = [];
const calendar = arg.getISOFields().calendar;
Object.defineProperty(arg, "calendar", {
get() {
actual.push("get calendar");
return calendar;
},
});
const instance = new Temporal.PlainDate(1976, 11, 18, {
dateAdd() {},
dateFromFields() {},
dateUntil() {},
day() {},
dayOfWeek() {},
dayOfYear() {},
daysInMonth() {},
daysInWeek() {},
daysInYear() {},
fields() {},
id: "replace-me",
inLeapYear() {},
mergeFields() {},
month() {},
monthCode() {},
monthDayFromFields() {},
monthsInYear() {},
weekOfYear() {},
year() {},
yearMonthFromFields() {},
yearOfWeek() {},
});
const result = instance.withCalendar(arg);
assert.sameValue(result.getISOFields().calendar, calendar, "Temporal object coerced to calendar");
assert.compareArray(actual, expected, "calendar getter not called");
});
reportCompare(0, 0);
|