Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Temporal: Remove conditional lookups #3959

Merged
merged 3 commits into from
Nov 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 11 additions & 35 deletions test/built-ins/Temporal/Duration/compare/order-of-operations.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ Temporal.Duration.compare(
assert.compareArray(actual, expected, "order of operations");
actual.splice(0); // clear

const expectedOpsForPlainRelativeTo = expected.concat([
const baseExpectedOpsWithRelativeTo = expected.concat([
// ToRelativeTemporalObject
"get options.relativeTo.calendar",
"has options.relativeTo.calendar.dateAdd",
Expand All @@ -109,14 +109,17 @@ const expectedOpsForPlainRelativeTo = expected.concat([
"has options.relativeTo.calendar.year",
"has options.relativeTo.calendar.yearMonthFromFields",
"has options.relativeTo.calendar.yearOfWeek",
// lookup
"get options.relativeTo.calendar.dateFromFields",
"get options.relativeTo.calendar.fields",
"call options.relativeTo.calendar.fields",
"get options.relativeTo.day",
"get options.relativeTo.day.valueOf",
"call options.relativeTo.day.valueOf",
"get options.relativeTo.hour",
]);

const expectedOpsForPlainRelativeTo = baseExpectedOpsWithRelativeTo.concat([
// ToRelativeTemporalObject, continued
"get options.relativeTo.microsecond",
"get options.relativeTo.millisecond",
"get options.relativeTo.minute",
Expand All @@ -134,6 +137,8 @@ const expectedOpsForPlainRelativeTo = expected.concat([
"get options.relativeTo.year.valueOf",
"call options.relativeTo.year.valueOf",
"call options.relativeTo.calendar.dateFromFields",
// lookup in Duration.compare
"get options.relativeTo.calendar.dateAdd",
]);

const plainRelativeTo = TemporalHelpers.propertyBagObserver(actual, {
Expand Down Expand Up @@ -176,7 +181,6 @@ actual.splice(0); // clear
// to days:
const expectedOpsForPlainDayBalancing = expectedOpsForPlainRelativeTo.concat(
[
"get options.relativeTo.calendar.dateAdd",
// UnbalanceDurationRelative
"call options.relativeTo.calendar.dateAdd", // 11.a.iii.1 MoveRelativeDate
"call options.relativeTo.calendar.dateAdd", // 11.a.iv.1 MoveRelativeDate
Expand All @@ -195,37 +199,8 @@ Temporal.Duration.compare(
assert.compareArray(actual, expectedOpsForPlainDayBalancing, "order of operations with PlainDate relativeTo and calendar units");
actual.splice(0); // clear

const expectedOpsForZonedRelativeTo = expected.concat([
// ToRelativeTemporalObject
"get options.relativeTo.calendar",
"has options.relativeTo.calendar.dateAdd",
"has options.relativeTo.calendar.dateFromFields",
"has options.relativeTo.calendar.dateUntil",
"has options.relativeTo.calendar.day",
"has options.relativeTo.calendar.dayOfWeek",
"has options.relativeTo.calendar.dayOfYear",
"has options.relativeTo.calendar.daysInMonth",
"has options.relativeTo.calendar.daysInWeek",
"has options.relativeTo.calendar.daysInYear",
"has options.relativeTo.calendar.fields",
"has options.relativeTo.calendar.id",
"has options.relativeTo.calendar.inLeapYear",
"has options.relativeTo.calendar.mergeFields",
"has options.relativeTo.calendar.month",
"has options.relativeTo.calendar.monthCode",
"has options.relativeTo.calendar.monthDayFromFields",
"has options.relativeTo.calendar.monthsInYear",
"has options.relativeTo.calendar.weekOfYear",
"has options.relativeTo.calendar.year",
"has options.relativeTo.calendar.yearMonthFromFields",
"has options.relativeTo.calendar.yearOfWeek",
"get options.relativeTo.calendar.dateFromFields",
"get options.relativeTo.calendar.fields",
"call options.relativeTo.calendar.fields",
"get options.relativeTo.day",
"get options.relativeTo.day.valueOf",
"call options.relativeTo.day.valueOf",
"get options.relativeTo.hour",
const expectedOpsForZonedRelativeTo = baseExpectedOpsWithRelativeTo.concat([
// ToRelativeTemporalObject, continued
"get options.relativeTo.hour.valueOf",
"call options.relativeTo.hour.valueOf",
"get options.relativeTo.microsecond",
Expand Down Expand Up @@ -264,6 +239,8 @@ const expectedOpsForZonedRelativeTo = expected.concat([
"get options.relativeTo.timeZone.getPossibleInstantsFor",
"call options.relativeTo.timeZone.getPossibleInstantsFor",
"call options.relativeTo.timeZone.getOffsetNanosecondsFor",
// lookup in Duration.compare
"get options.relativeTo.calendar.dateAdd",
ptomato marked this conversation as resolved.
Show resolved Hide resolved
]);

const zonedRelativeTo = TemporalHelpers.propertyBagObserver(actual, {
Expand Down Expand Up @@ -323,7 +300,6 @@ Temporal.Duration.compare(
assert.compareArray(
actual,
expectedOpsForZonedRelativeTo.concat([
"get options.relativeTo.calendar.dateAdd",
"call options.relativeTo.timeZone.getOffsetNanosecondsFor",
// AddZonedDateTime on first argument
"call options.relativeTo.calendar.dateAdd",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,6 @@ const expectedOpsForPlainRelativeTo = expected.concat([
"has options.relativeTo.calendar.year",
"has options.relativeTo.calendar.yearMonthFromFields",
"has options.relativeTo.calendar.yearOfWeek",
// lookup
"get options.relativeTo.calendar.dateFromFields",
"get options.relativeTo.calendar.fields",
"call options.relativeTo.calendar.fields",
Expand All @@ -119,7 +118,7 @@ const expectedOpsForPlainRelativeTo = expected.concat([
"call options.relativeTo.year.valueOf",
// InterpretTemporalDateTimeFields
"call options.relativeTo.calendar.dateFromFields",
// lookup 2
// lookup in AddDurationToOrSubtractDurationFromDuration
"get options.relativeTo.calendar.dateAdd",
"get options.relativeTo.calendar.dateUntil",
// AddDuration
Expand Down Expand Up @@ -231,6 +230,9 @@ const expectedOpsForPlainRelativeToNoCalendarOperations = [
"call options.relativeTo.year.valueOf",
// InterpretTemporalDateTimeFields
"call options.relativeTo.calendar.dateFromFields",
// lookup in AddDurationToOrSubtractDurationFromDuration
"get options.relativeTo.calendar.dateAdd",
"get options.relativeTo.calendar.dateUntil",
];

const noCalendarInstance = new Temporal.Duration(0, 0, 0, 4, 5, 6, 7, 987, 654, 321);
Expand Down Expand Up @@ -273,7 +275,6 @@ const expectedOpsForZonedRelativeTo = expected.concat([
"has options.relativeTo.calendar.year",
"has options.relativeTo.calendar.yearMonthFromFields",
"has options.relativeTo.calendar.yearOfWeek",
// lookup
"get options.relativeTo.calendar.dateFromFields",
"get options.relativeTo.calendar.fields",
"call options.relativeTo.calendar.fields",
Expand Down Expand Up @@ -323,7 +324,7 @@ const expectedOpsForZonedRelativeTo = expected.concat([
"get options.relativeTo.timeZone.getPossibleInstantsFor",
"call options.relativeTo.timeZone.getPossibleInstantsFor",
"call options.relativeTo.timeZone.getOffsetNanosecondsFor",
// lookup 2
// lookup in AddDurationToOrSubtractDurationFromDuration
"get options.relativeTo.calendar.dateAdd",
"get options.relativeTo.calendar.dateUntil",
// AddDuration
Expand Down Expand Up @@ -419,7 +420,6 @@ const expectedOpsForZonedRelativeToNoDaysOperations = [
"has options.relativeTo.calendar.year",
"has options.relativeTo.calendar.yearMonthFromFields",
"has options.relativeTo.calendar.yearOfWeek",
// lookup
"get options.relativeTo.calendar.dateFromFields",
"get options.relativeTo.calendar.fields",
"call options.relativeTo.calendar.fields",
Expand Down Expand Up @@ -469,6 +469,9 @@ const expectedOpsForZonedRelativeToNoDaysOperations = [
"get options.relativeTo.timeZone.getPossibleInstantsFor",
"call options.relativeTo.timeZone.getPossibleInstantsFor",
"call options.relativeTo.timeZone.getOffsetNanosecondsFor",
// lookup in AddDurationToOrSubtractDurationFromDuration
"get options.relativeTo.calendar.dateAdd",
"get options.relativeTo.calendar.dateUntil",
];

const noDaysInstance = new Temporal.Duration(0, 0, 0, 0, 5, 6, 7, 987, 654, 321);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,9 @@ const expectedOpsForPlainRelativeTo = [
"get options.smallestUnit",
"get options.smallestUnit.toString",
"call options.smallestUnit.toString",
// lookup in Duration.p.round
"get options.relativeTo.calendar.dateAdd",
"get options.relativeTo.calendar.dateUntil",
];

const plainRelativeTo = TemporalHelpers.propertyBagObserver(actual, {
Expand All @@ -119,8 +122,6 @@ actual.splice(0); // clear

// code path through RoundDuration that rounds to the nearest year, with minimal calendar calls:
const expectedMinimalOpsForYearRounding = expectedOpsForPlainRelativeTo.concat([
"get options.relativeTo.calendar.dateAdd",
"get options.relativeTo.calendar.dateUntil",
// 7.e and 7.g not called because years, months, weeks are 0
"call options.relativeTo.calendar.dateUntil", // 7.o
// 7.s not called because years, months, weeks are 0
Expand All @@ -132,8 +133,6 @@ actual.splice(0); // clear

// code path through RoundDuration that rounds to the nearest year:
const expectedOpsForYearRounding = expectedOpsForPlainRelativeTo.concat([
"get options.relativeTo.calendar.dateAdd",
"get options.relativeTo.calendar.dateUntil",
"call options.relativeTo.calendar.dateAdd", // 7.e
"call options.relativeTo.calendar.dateAdd", // 7.g
"call options.relativeTo.calendar.dateUntil", // 7.o
Expand All @@ -152,8 +151,6 @@ actual.splice(0); // clear

// code path through Duration.prototype.round that rounds to the nearest month:
const expectedOpsForMonthRounding = expectedOpsForPlainRelativeTo.concat([
"get options.relativeTo.calendar.dateAdd",
"get options.relativeTo.calendar.dateUntil",
// UnbalanceDurationRelative
"call options.relativeTo.calendar.dateAdd", // 9.d.i
"call options.relativeTo.calendar.dateUntil", // 9.d.iv
Expand All @@ -172,7 +169,6 @@ actual.splice(0); // clear

// code path through Duration.prototype.round that rounds to the nearest week:
const expectedOpsForWeekRounding = expectedOpsForPlainRelativeTo.concat([
"get options.relativeTo.calendar.dateAdd",
// UnbalanceDurationRelative
"call options.relativeTo.calendar.dateAdd", // 10.c.i MoveRelativeDate
"call options.relativeTo.calendar.dateAdd", // 10.d.i MoveRelativeDate
Expand All @@ -189,7 +185,6 @@ actual.splice(0); // clear

// code path through UnbalanceDurationRelative that rounds to the nearest day:
const expectedOpsForDayRounding = expectedOpsForPlainRelativeTo.concat([
"get options.relativeTo.calendar.dateAdd",
"call options.relativeTo.calendar.dateAdd", // 11.a.iii.1 MoveRelativeDate
"call options.relativeTo.calendar.dateAdd", // 11.a.iv.1 MoveRelativeDate
"call options.relativeTo.calendar.dateAdd", // 11.a.v.1 MoveRelativeDate
Expand All @@ -201,8 +196,6 @@ actual.splice(0); // clear

// code path through BalanceDurationRelative balancing from days up to years:
const expectedOpsForDayToYearBalancing = expectedOpsForPlainRelativeTo.concat([
"get options.relativeTo.calendar.dateAdd",
"get options.relativeTo.calendar.dateUntil",
"call options.relativeTo.calendar.dateAdd", // 10.b MoveRelativeDate
"call options.relativeTo.calendar.dateAdd", // 10.e.iv MoveRelativeDate
"call options.relativeTo.calendar.dateAdd", // 10.f MoveRelativeDate
Expand All @@ -217,8 +210,6 @@ actual.splice(0); // clear

// code path through Duration.prototype.round balancing from months up to years:
const expectedOpsForMonthToYearBalancing = expectedOpsForPlainRelativeTo.concat([
"get options.relativeTo.calendar.dateAdd",
"get options.relativeTo.calendar.dateUntil",
// RoundDuration
"call options.relativeTo.calendar.dateAdd", // 10.c
"call options.relativeTo.calendar.dateAdd", // 10.e
Expand All @@ -237,7 +228,6 @@ assert.compareArray(actual, expectedOpsForMonthToYearBalancing, "order of operat
actual.splice(0); // clear

const expectedOpsForDayToMonthBalancing = expectedOpsForPlainRelativeTo.concat([
"get options.relativeTo.calendar.dateAdd",
// BalanceDurationRelative
"call options.relativeTo.calendar.dateAdd", // 11.b MoveRelativeDate
"call options.relativeTo.calendar.dateAdd", // 11.e.iv MoveRelativeDate
Expand All @@ -248,7 +238,6 @@ assert.compareArray(actual, expectedOpsForDayToMonthBalancing, "order of operati
actual.splice(0); // clear

const expectedOpsForDayToWeekBalancing = expectedOpsForPlainRelativeTo.concat([
"get options.relativeTo.calendar.dateAdd",
// BalanceDurationRelative
"call options.relativeTo.calendar.dateAdd", // 12.c MoveRelativeDate
"call options.relativeTo.calendar.dateAdd", // 12.f.iv MoveRelativeDate
Expand Down Expand Up @@ -360,14 +349,17 @@ const zonedRelativeTo = TemporalHelpers.propertyBagObserver(actual, {

// basic order of operations with ZonedDateTime relativeTo:
instance.round(createOptionsObserver({ relativeTo: zonedRelativeTo }));
assert.compareArray(actual, expectedOpsForZonedRelativeTo, "order of operations for ZonedDateTime relativeTo");
assert.compareArray(actual, expectedOpsForZonedRelativeTo.concat([
"get options.relativeTo.calendar.dateAdd",
"get options.relativeTo.calendar.dateUntil",
]), "order of operations for ZonedDateTime relativeTo");
actual.splice(0); // clear

// code path through RoundDuration that rounds to the nearest year with minimal calendar operations:
const expectedOpsForMinimalYearRoundingZoned = expectedOpsForZonedRelativeTo.concat([
// ToTemporalDate
"call options.relativeTo.timeZone.getOffsetNanosecondsFor",
// lookup
// lookup in Duration.p.round
"get options.relativeTo.calendar.dateAdd",
"get options.relativeTo.calendar.dateUntil",
// NanosecondsToDays
Expand Down Expand Up @@ -395,7 +387,7 @@ actual.splice(0); // clear
const expectedOpsForYearRoundingZoned = expectedOpsForZonedRelativeTo.concat([
// ToTemporalDate
"call options.relativeTo.timeZone.getOffsetNanosecondsFor",
// lookup
// lookup in Duration.p.round
"get options.relativeTo.calendar.dateAdd",
"get options.relativeTo.calendar.dateUntil",
// MoveRelativeZonedDateTime → AddZonedDateTime
Expand Down Expand Up @@ -432,8 +424,9 @@ actual.splice(0); // clear
const expectedOpsForUnbalanceRoundBalance = expectedOpsForZonedRelativeTo.concat([
// ToTemporalDate
"call options.relativeTo.timeZone.getOffsetNanosecondsFor",
// lookup
// lookup in Duration.p.round
"get options.relativeTo.calendar.dateAdd",
"get options.relativeTo.calendar.dateUntil",
// No user code calls in UnbalanceDurationRelative
// RoundDuration → MoveRelativeZonedDateTime → AddZonedDateTime
"call options.relativeTo.calendar.dateAdd",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,6 @@ const expectedOpsForPlainRelativeTo = expected.concat([
"has options.relativeTo.calendar.year",
"has options.relativeTo.calendar.yearMonthFromFields",
"has options.relativeTo.calendar.yearOfWeek",
// lookup
"get options.relativeTo.calendar.dateFromFields",
"get options.relativeTo.calendar.fields",
"call options.relativeTo.calendar.fields",
Expand All @@ -119,7 +118,7 @@ const expectedOpsForPlainRelativeTo = expected.concat([
"call options.relativeTo.year.valueOf",
// InterpretTemporalDateTimeFields
"call options.relativeTo.calendar.dateFromFields",
// lookup 2
// lookup in AddDurationToOrSubtractDurationFromDuration
"get options.relativeTo.calendar.dateAdd",
"get options.relativeTo.calendar.dateUntil",
// AddDuration
Expand Down Expand Up @@ -231,6 +230,9 @@ const expectedOpsForPlainRelativeToNoCalendarOperations = [
"call options.relativeTo.year.valueOf",
// InterpretTemporalDateTimeFields
"call options.relativeTo.calendar.dateFromFields",
// lookup in AddDurationToOrSubtractDurationFromDuration
"get options.relativeTo.calendar.dateAdd",
"get options.relativeTo.calendar.dateUntil",
];

const noCalendarInstance = new Temporal.Duration(0, 0, 0, 4, 5, 6, 7, 987, 654, 321);
Expand Down Expand Up @@ -273,7 +275,6 @@ const expectedOpsForZonedRelativeTo = expected.concat([
"has options.relativeTo.calendar.year",
"has options.relativeTo.calendar.yearMonthFromFields",
"has options.relativeTo.calendar.yearOfWeek",
// lookup
"get options.relativeTo.calendar.dateFromFields",
"get options.relativeTo.calendar.fields",
"call options.relativeTo.calendar.fields",
Expand Down Expand Up @@ -323,7 +324,7 @@ const expectedOpsForZonedRelativeTo = expected.concat([
"get options.relativeTo.timeZone.getPossibleInstantsFor",
"call options.relativeTo.timeZone.getPossibleInstantsFor",
"call options.relativeTo.timeZone.getOffsetNanosecondsFor",
// lookup 2
// lookup in AddDurationToOrSubtractDurationFromDuration
"get options.relativeTo.calendar.dateAdd",
"get options.relativeTo.calendar.dateUntil",
// AddDuration
Expand Down Expand Up @@ -419,7 +420,6 @@ const expectedOpsForZonedRelativeToNoDaysOperations = [
"has options.relativeTo.calendar.year",
"has options.relativeTo.calendar.yearMonthFromFields",
"has options.relativeTo.calendar.yearOfWeek",
// lookup
"get options.relativeTo.calendar.dateFromFields",
"get options.relativeTo.calendar.fields",
"call options.relativeTo.calendar.fields",
Expand Down Expand Up @@ -469,6 +469,9 @@ const expectedOpsForZonedRelativeToNoDaysOperations = [
"get options.relativeTo.timeZone.getPossibleInstantsFor",
"call options.relativeTo.timeZone.getPossibleInstantsFor",
"call options.relativeTo.timeZone.getOffsetNanosecondsFor",
// lookup in AddDurationToOrSubtractDurationFromDuration
"get options.relativeTo.calendar.dateAdd",
"get options.relativeTo.calendar.dateUntil",
];

const noDaysInstance = new Temporal.Duration(0, 0, 0, 0, 5, 6, 7, 987, 654, 321);
Expand Down
Loading