mirror of
https://github.com/tc39/test262.git
synced 2025-11-20 13:49:50 +01:00
I used a script to "unroll" some of the calls to TemporalHelpers.checkToTemporalCalendarFastPath(), and rewrite it slightly not to use a specific Calendar instance. This is in preparation for a future refactor, but also allows testing the PlainTime path which was not previously covered. (I didn't unroll all the calls and remove the helper yet, because the remaining calls have custom assertions that I haven't gotten the script to work with yet. For the same reason, I didn't yet convert these to use the test generation facility. These will follow in a future PR.)
40 lines
1.7 KiB
JavaScript
40 lines
1.7 KiB
JavaScript
// 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.plaindatetime
|
|
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]], [[InitializedTemporalTime]], [[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 plainTime = new Temporal.PlainTime(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, plainTime, 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 result = new Temporal.PlainDateTime(2000, 5, 2, 15, 23, 30, 987, 654, 321, arg);
|
|
assert.sameValue(result.calendar, calendar, "Temporal object coerced to calendar");
|
|
|
|
assert.compareArray(actual, expected, "calendar getter not called");
|
|
});
|