diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-19 00:47:55 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-19 00:47:55 +0000 |
commit | 26a029d407be480d791972afb5975cf62c9360a6 (patch) | |
tree | f435a8308119effd964b339f76abb83a57c29483 /js/src/tests/test262/built-ins/Temporal/Duration/prototype/subtract/order-of-operations.js | |
parent | Initial commit. (diff) | |
download | firefox-26a029d407be480d791972afb5975cf62c9360a6.tar.xz firefox-26a029d407be480d791972afb5975cf62c9360a6.zip |
Adding upstream version 124.0.1.upstream/124.0.1
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'js/src/tests/test262/built-ins/Temporal/Duration/prototype/subtract/order-of-operations.js')
-rw-r--r-- | js/src/tests/test262/built-ins/Temporal/Duration/prototype/subtract/order-of-operations.js | 493 |
1 files changed, 493 insertions, 0 deletions
diff --git a/js/src/tests/test262/built-ins/Temporal/Duration/prototype/subtract/order-of-operations.js b/js/src/tests/test262/built-ins/Temporal/Duration/prototype/subtract/order-of-operations.js new file mode 100644 index 0000000000..988835838f --- /dev/null +++ b/js/src/tests/test262/built-ins/Temporal/Duration/prototype/subtract/order-of-operations.js @@ -0,0 +1,493 @@ +// |reftest| skip-if(!this.hasOwnProperty('Temporal')) -- Temporal is not enabled unconditionally +// Copyright (C) 2020 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-temporal.duration.prototype.subtract +description: Properties on an object passed to subtract() are accessed in the correct order +includes: [compareArray.js, temporalHelpers.js] +features: [Temporal] +---*/ + +const expected = [ + // ToTemporalDurationRecord + "get fields.days", + "get fields.days.valueOf", + "call fields.days.valueOf", + "get fields.hours", + "get fields.hours.valueOf", + "call fields.hours.valueOf", + "get fields.microseconds", + "get fields.microseconds.valueOf", + "call fields.microseconds.valueOf", + "get fields.milliseconds", + "get fields.milliseconds.valueOf", + "call fields.milliseconds.valueOf", + "get fields.minutes", + "get fields.minutes.valueOf", + "call fields.minutes.valueOf", + "get fields.months", + "get fields.months.valueOf", + "call fields.months.valueOf", + "get fields.nanoseconds", + "get fields.nanoseconds.valueOf", + "call fields.nanoseconds.valueOf", + "get fields.seconds", + "get fields.seconds.valueOf", + "call fields.seconds.valueOf", + "get fields.weeks", + "get fields.weeks.valueOf", + "call fields.weeks.valueOf", + "get fields.years", + "get fields.years.valueOf", + "call fields.years.valueOf", + // ToRelativeTemporalObject + "get options.relativeTo", +]; +const actual = []; + +const simpleFields = TemporalHelpers.propertyBagObserver(actual, { + years: 0, + months: 0, + weeks: 0, + days: 1, + hours: 1, + minutes: 1, + seconds: 1, + milliseconds: 1, + microseconds: 1, + nanoseconds: 1, +}, "fields"); + +function createOptionsObserver(relativeTo = undefined) { + return TemporalHelpers.propertyBagObserver(actual, { relativeTo }, "options"); +} + +// basic order of observable operations, without any calendar units: +const simpleInstance = new Temporal.Duration(0, 0, 0, 1, 1, 1, 1, 1, 1, 1); +simpleInstance.subtract(simpleFields, createOptionsObserver()); +assert.compareArray(actual, expected, "order of operations"); +actual.splice(0); // clear + +const expectedOpsForPlainRelativeTo = 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", + // PrepareTemporalFields + "get options.relativeTo.day", + "get options.relativeTo.day.valueOf", + "call options.relativeTo.day.valueOf", + "get options.relativeTo.hour", + "get options.relativeTo.microsecond", + "get options.relativeTo.millisecond", + "get options.relativeTo.minute", + "get options.relativeTo.month", + "get options.relativeTo.month.valueOf", + "call options.relativeTo.month.valueOf", + "get options.relativeTo.monthCode", + "get options.relativeTo.monthCode.toString", + "call options.relativeTo.monthCode.toString", + "get options.relativeTo.nanosecond", + "get options.relativeTo.offset", + "get options.relativeTo.second", + "get options.relativeTo.timeZone", + "get options.relativeTo.year", + "get options.relativeTo.year.valueOf", + "call options.relativeTo.year.valueOf", + // InterpretTemporalDateTimeFields + "call options.relativeTo.calendar.dateFromFields", + // lookup in AddDurationToOrSubtractDurationFromDuration + "get options.relativeTo.calendar.dateAdd", + "get options.relativeTo.calendar.dateUntil", + // AddDuration + "call options.relativeTo.calendar.dateAdd", + "call options.relativeTo.calendar.dateAdd", + "call options.relativeTo.calendar.dateUntil", +]); + +const instance = new Temporal.Duration(1, 2, 1, 4, 5, 6, 7, 987, 654, 321); + +const fields = TemporalHelpers.propertyBagObserver(actual, { + years: 1, + months: 1, + weeks: 1, + days: 1, + hours: 1, + minutes: 1, + seconds: 1, + milliseconds: 1, + microseconds: 1, + nanoseconds: 1, +}, "fields"); + +const plainRelativeTo = TemporalHelpers.propertyBagObserver(actual, { + year: 2000, + month: 1, + monthCode: "M01", + day: 1, + calendar: TemporalHelpers.calendarObserver(actual, "options.relativeTo.calendar"), +}, "options.relativeTo"); + +instance.subtract(fields, createOptionsObserver(plainRelativeTo)); +assert.compareArray(actual, expectedOpsForPlainRelativeTo, "order of operations with PlainDate relativeTo"); +actual.splice(0); // clear + +const expectedOpsForPlainRelativeToNoCalendarOperations = [ + // ToTemporalDurationRecord + "get fields.days", + "get fields.days.valueOf", + "call fields.days.valueOf", + "get fields.hours", + "get fields.hours.valueOf", + "call fields.hours.valueOf", + "get fields.microseconds", + "get fields.microseconds.valueOf", + "call fields.microseconds.valueOf", + "get fields.milliseconds", + "get fields.milliseconds.valueOf", + "call fields.milliseconds.valueOf", + "get fields.minutes", + "get fields.minutes.valueOf", + "call fields.minutes.valueOf", + "get fields.months", + "get fields.nanoseconds", + "get fields.nanoseconds.valueOf", + "call fields.nanoseconds.valueOf", + "get fields.seconds", + "get fields.seconds.valueOf", + "call fields.seconds.valueOf", + "get fields.weeks", + "get fields.years", + // ToRelativeTemporalObject + "get options.relativeTo", + "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", + // PrepareTemporalFields + "get options.relativeTo.day", + "get options.relativeTo.day.valueOf", + "call options.relativeTo.day.valueOf", + "get options.relativeTo.hour", + "get options.relativeTo.microsecond", + "get options.relativeTo.millisecond", + "get options.relativeTo.minute", + "get options.relativeTo.month", + "get options.relativeTo.month.valueOf", + "call options.relativeTo.month.valueOf", + "get options.relativeTo.monthCode", + "get options.relativeTo.monthCode.toString", + "call options.relativeTo.monthCode.toString", + "get options.relativeTo.nanosecond", + "get options.relativeTo.offset", + "get options.relativeTo.second", + "get options.relativeTo.timeZone", + "get options.relativeTo.year", + "get options.relativeTo.year.valueOf", + "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); + +const noCalendarFields = TemporalHelpers.propertyBagObserver(actual, { + days: 1, + hours: 1, + minutes: 1, + seconds: 1, + milliseconds: 1, + microseconds: 1, + nanoseconds: 1, +}, "fields"); + +noCalendarInstance.subtract(noCalendarFields, createOptionsObserver(plainRelativeTo)); +assert.compareArray(actual, expectedOpsForPlainRelativeToNoCalendarOperations, "order of operations with PlainDate relativeTo and no 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", + // PrepareTemporalFields + "get options.relativeTo.day", + "get options.relativeTo.day.valueOf", + "call options.relativeTo.day.valueOf", + "get options.relativeTo.hour", + "get options.relativeTo.hour.valueOf", + "call options.relativeTo.hour.valueOf", + "get options.relativeTo.microsecond", + "get options.relativeTo.microsecond.valueOf", + "call options.relativeTo.microsecond.valueOf", + "get options.relativeTo.millisecond", + "get options.relativeTo.millisecond.valueOf", + "call options.relativeTo.millisecond.valueOf", + "get options.relativeTo.minute", + "get options.relativeTo.minute.valueOf", + "call options.relativeTo.minute.valueOf", + "get options.relativeTo.month", + "get options.relativeTo.month.valueOf", + "call options.relativeTo.month.valueOf", + "get options.relativeTo.monthCode", + "get options.relativeTo.monthCode.toString", + "call options.relativeTo.monthCode.toString", + "get options.relativeTo.nanosecond", + "get options.relativeTo.nanosecond.valueOf", + "call options.relativeTo.nanosecond.valueOf", + "get options.relativeTo.offset", + "get options.relativeTo.offset.toString", + "call options.relativeTo.offset.toString", + "get options.relativeTo.second", + "get options.relativeTo.second.valueOf", + "call options.relativeTo.second.valueOf", + "get options.relativeTo.timeZone", + "get options.relativeTo.year", + "get options.relativeTo.year.valueOf", + "call options.relativeTo.year.valueOf", + // InterpretTemporalDateTimeFields + "call options.relativeTo.calendar.dateFromFields", + // ToRelativeTemporalObject again + "has options.relativeTo.timeZone.getOffsetNanosecondsFor", + "has options.relativeTo.timeZone.getPossibleInstantsFor", + "has options.relativeTo.timeZone.id", + // InterpretISODateTimeOffset + "get options.relativeTo.timeZone.getOffsetNanosecondsFor", + "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", + // AddDuration + "call options.relativeTo.timeZone.getOffsetNanosecondsFor", + // AddDuration → AddZonedDateTime 1 + "call options.relativeTo.calendar.dateAdd", + "call options.relativeTo.timeZone.getPossibleInstantsFor", + // AddDuration → AddZonedDateTime 2 + "call options.relativeTo.timeZone.getOffsetNanosecondsFor", + "call options.relativeTo.calendar.dateAdd", + "call options.relativeTo.timeZone.getPossibleInstantsFor", + // AddDuration → DifferenceZonedDateTime + "call options.relativeTo.timeZone.getOffsetNanosecondsFor", + // AddDuration → DifferenceZonedDateTime → DifferenceISODateTime + "call options.relativeTo.calendar.dateUntil", + // AddDuration → DifferenceZonedDateTime → AddZonedDateTime + "call options.relativeTo.calendar.dateAdd", + "call options.relativeTo.timeZone.getPossibleInstantsFor", + // AddDuration → DifferenceZonedDateTime → NanosecondsToDays + "call options.relativeTo.timeZone.getOffsetNanosecondsFor", + "call options.relativeTo.timeZone.getOffsetNanosecondsFor", + // AddDuration → DifferenceZonedDateTime → NanosecondsToDays → AddZonedDateTime 1 + "call options.relativeTo.timeZone.getPossibleInstantsFor", + // AddDuration → DifferenceZonedDateTime → NanosecondsToDays → AddZonedDateTime 2 + "call options.relativeTo.timeZone.getPossibleInstantsFor", +]); + +const zonedRelativeTo = TemporalHelpers.propertyBagObserver(actual, { + year: 2000, + month: 1, + monthCode: "M01", + day: 1, + hour: 0, + minute: 0, + second: 0, + millisecond: 0, + microsecond: 0, + nanosecond: 0, + offset: "+00:00", + calendar: TemporalHelpers.calendarObserver(actual, "options.relativeTo.calendar"), + timeZone: TemporalHelpers.timeZoneObserver(actual, "options.relativeTo.timeZone"), +}, "options.relativeTo"); + +instance.subtract(fields, createOptionsObserver(zonedRelativeTo)); +assert.compareArray(actual, expectedOpsForZonedRelativeTo, "order of operations with ZonedDateTime relativeTo"); +actual.splice(0); // clear + +const expectedOpsForZonedRelativeToNoDaysOperations = [ + // ToTemporalDurationRecord + "get fields.days", + "get fields.hours", + "get fields.hours.valueOf", + "call fields.hours.valueOf", + "get fields.microseconds", + "get fields.microseconds.valueOf", + "call fields.microseconds.valueOf", + "get fields.milliseconds", + "get fields.milliseconds.valueOf", + "call fields.milliseconds.valueOf", + "get fields.minutes", + "get fields.minutes.valueOf", + "call fields.minutes.valueOf", + "get fields.months", + "get fields.nanoseconds", + "get fields.nanoseconds.valueOf", + "call fields.nanoseconds.valueOf", + "get fields.seconds", + "get fields.seconds.valueOf", + "call fields.seconds.valueOf", + "get fields.weeks", + "get fields.years", + // ToRelativeTemporalObject + "get options.relativeTo", + "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", + // PrepareTemporalFields + "get options.relativeTo.day", + "get options.relativeTo.day.valueOf", + "call options.relativeTo.day.valueOf", + "get options.relativeTo.hour", + "get options.relativeTo.hour.valueOf", + "call options.relativeTo.hour.valueOf", + "get options.relativeTo.microsecond", + "get options.relativeTo.microsecond.valueOf", + "call options.relativeTo.microsecond.valueOf", + "get options.relativeTo.millisecond", + "get options.relativeTo.millisecond.valueOf", + "call options.relativeTo.millisecond.valueOf", + "get options.relativeTo.minute", + "get options.relativeTo.minute.valueOf", + "call options.relativeTo.minute.valueOf", + "get options.relativeTo.month", + "get options.relativeTo.month.valueOf", + "call options.relativeTo.month.valueOf", + "get options.relativeTo.monthCode", + "get options.relativeTo.monthCode.toString", + "call options.relativeTo.monthCode.toString", + "get options.relativeTo.nanosecond", + "get options.relativeTo.nanosecond.valueOf", + "call options.relativeTo.nanosecond.valueOf", + "get options.relativeTo.offset", + "get options.relativeTo.offset.toString", + "call options.relativeTo.offset.toString", + "get options.relativeTo.second", + "get options.relativeTo.second.valueOf", + "call options.relativeTo.second.valueOf", + "get options.relativeTo.timeZone", + "get options.relativeTo.year", + "get options.relativeTo.year.valueOf", + "call options.relativeTo.year.valueOf", + // InterpretTemporalDateTimeFields + "call options.relativeTo.calendar.dateFromFields", + // ToRelativeTemporalObject again + "has options.relativeTo.timeZone.getOffsetNanosecondsFor", + "has options.relativeTo.timeZone.getPossibleInstantsFor", + "has options.relativeTo.timeZone.id", + // InterpretISODateTimeOffset + "get options.relativeTo.timeZone.getOffsetNanosecondsFor", + "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); + +const noDaysFields = TemporalHelpers.propertyBagObserver(actual, { + hours: 1, + minutes: 1, + seconds: 1, + milliseconds: 1, + microseconds: 1, + nanoseconds: 1, +}, "fields"); + +noDaysInstance.subtract(noDaysFields, createOptionsObserver(zonedRelativeTo)); +assert.compareArray(actual, expectedOpsForZonedRelativeToNoDaysOperations, "order of operations with ZonedDateTime relativeTo and no units above days"); +actual.splice(0); // clear + +reportCompare(0, 0); |