Skip to content
Open
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
15 changes: 13 additions & 2 deletions test/built-ins/Temporal/Duration/compare/order-of-operations.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ includes: [compareArray.js, temporalHelpers.js]
features: [Temporal]
---*/

const expected = [
const expectedOpsForPrimitiveOptions = [
// ToTemporalDuration on first argument
"get one.days",
"get one.days.valueOf",
Expand Down Expand Up @@ -71,9 +71,11 @@ const expected = [
"get two.years",
"get two.years.valueOf",
"call two.years.valueOf",
];
const expected = expectedOpsForPrimitiveOptions.concat([
// ToRelativeTemporalObject
"get options.relativeTo",
];
]);
const actual = [];

// basic order of observable operations with no relativeTo
Expand All @@ -85,6 +87,15 @@ Temporal.Duration.compare(
assert.compareArray(actual, expected, "order of operations");
actual.splice(0); // clear

assert.throws(TypeError, () => Temporal.Duration.compare(
createDurationPropertyBagObserver("one", 0, 0, 0, 7),
createDurationPropertyBagObserver("two", 0, 0, 0, 6),
null
));
assert.compareArray(actual, expectedOpsForPrimitiveOptions,
"duration fields are read before TypeError is thrown for primitive options");
actual.splice(0); // clear

// Check fast path for temporal objects.
function checkTemporalObject(object) {
["year", "month", "monthCode", "day", "hour", "minute", "second", "millisecond", "microsecond", "nanosecond"].forEach((property) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,11 @@ includes: [compareArray.js, temporalHelpers.js]
features: [Temporal]
---*/

const expected = [
const expectedOpsForPrimitiveOptions = [
"get other.toString",
"call other.toString",
];
const expected = expectedOpsForPrimitiveOptions.concat([
"get options.largestUnit",
"get options.largestUnit.toString",
"call options.largestUnit.toString",
Expand All @@ -23,7 +25,7 @@ const expected = [
"get options.smallestUnit",
"get options.smallestUnit.toString",
"call options.smallestUnit.toString",
];
]);
const actual = [];

const instance = new Temporal.Instant(1_000_000_000_000_000_000n);
Expand All @@ -45,3 +47,9 @@ instance.since(TemporalHelpers.toPrimitiveObserver(actual, "2001-09-09T01:46:40Z
assert.compareArray(actual, expected, "order of operations with identical instants");

actual.splice(0); // clear

assert.throws(TypeError, () => instance.since(TemporalHelpers.toPrimitiveObserver(actual, "1970-01-01T00:00Z", "other"), null));
assert.compareArray(actual, expectedOpsForPrimitiveOptions,
"other instant is converted before TypeError is thrown for primitive options");

actual.splice(0); // clear
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,11 @@ includes: [compareArray.js, temporalHelpers.js]
features: [Temporal]
---*/

const expected = [
const expectedOpsForPrimitiveOptions = [
"get other.toString",
"call other.toString",
];
const expected = expectedOpsForPrimitiveOptions.concat([
"get options.largestUnit",
"get options.largestUnit.toString",
"call options.largestUnit.toString",
Expand All @@ -23,7 +25,7 @@ const expected = [
"get options.smallestUnit",
"get options.smallestUnit.toString",
"call options.smallestUnit.toString",
];
]);
const actual = [];

const instance = new Temporal.Instant(1_000_000_000_000_000_000n);
Expand All @@ -45,3 +47,9 @@ instance.until(TemporalHelpers.toPrimitiveObserver(actual, "2001-09-09T01:46:40Z
assert.compareArray(actual, expected, "order of operations with identical instants");

actual.splice(0); // clear

assert.throws(TypeError, () => instance.until(TemporalHelpers.toPrimitiveObserver(actual, "1970-01-01T00:00Z", "other"), null));
assert.compareArray(actual, expectedOpsForPrimitiveOptions,
"other instant is converted before TypeError is thrown for primitive options");

actual.splice(0); // clear
13 changes: 11 additions & 2 deletions test/built-ins/Temporal/PlainDate/from/order-of-operations.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ const expectedOptionsReading = [
"call options.overflow.toString",
];

const expected = [
const expectedOpsForPrimitiveOptions = [
"get fields.calendar",
"get fields.day",
"get fields.day.valueOf",
Expand All @@ -28,7 +28,8 @@ const expected = [
"get fields.year",
"get fields.year.valueOf",
"call fields.year.valueOf",
].concat(expectedOptionsReading);
];
const expected = expectedOpsForPrimitiveOptions.concat(expectedOptionsReading);
const actual = [];

const fields = TemporalHelpers.propertyBagObserver(actual, {
Expand Down Expand Up @@ -66,3 +67,11 @@ actual.splice(0);

Temporal.PlainDate.from("2001-05-02", options);
assert.compareArray(actual, expectedOptionsReading, "order of operations when parsing a string");

actual.splice(0);

assert.throws(TypeError, () => Temporal.PlainDate.from(fields, null));
assert.compareArray(actual, expectedOpsForPrimitiveOptions,
"item fields are read before TypeError is thrown for primitive options");

actual.splice(0); // clear
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ includes: [compareArray.js, temporalHelpers.js]
features: [Temporal]
---*/

const expected = [
const expectedOpsForPrimitiveOptions = [
// ToTemporalDurationRecord
"get fields.days",
"get fields.days.valueOf",
Expand Down Expand Up @@ -40,10 +40,12 @@ const expected = [
"get fields.years",
"get fields.years.valueOf",
"call fields.years.valueOf",
];
const expected = expectedOpsForPrimitiveOptions.concat([
"get options.overflow",
"get options.overflow.toString",
"call options.overflow.toString",
];
]);
const actual = [];

const instance = new Temporal.PlainDate(2000, 5, 2, "iso8601");
Expand All @@ -69,3 +71,9 @@ instance.add(fields, options);
assert.compareArray(actual, expected, "order of operations");

actual.splice(0); // clear

assert.throws(TypeError, () => instance.add(fields, null));
assert.compareArray(actual, expectedOpsForPrimitiveOptions,
"duration fields are read before TypeError is thrown for primitive options");

actual.splice(0); // clear
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ includes: [compareArray.js, temporalHelpers.js]
features: [Temporal]
---*/

const expected = [
const expectedOpsForPrimitiveOptions = [
// ToTemporalDate
"get other.calendar",
"get other.day",
Expand All @@ -23,6 +23,8 @@ const expected = [
"get other.year",
"get other.year.valueOf",
"call other.year.valueOf",
];
const expected = expectedOpsForPrimitiveOptions.concat([
// GetDifferenceSettings
"get options.largestUnit",
"get options.largestUnit.toString",
Expand All @@ -36,7 +38,7 @@ const expected = [
"get options.smallestUnit",
"get options.smallestUnit.toString",
"call options.smallestUnit.toString",
];
]);
const actual = [];

const instance = new Temporal.PlainDate(2000, 5, 2, "iso8601");
Expand Down Expand Up @@ -65,3 +67,8 @@ function createOptionsObserver({ smallestUnit = "days", largestUnit = "auto", ro
instance.since(otherDatePropertyBag, createOptionsObserver({ largestUnit: "years" }));
assert.compareArray(actual, expected, "order of operations");
actual.splice(0); // clear

assert.throws(TypeError, () => instance.since(otherDatePropertyBag, null));
assert.compareArray(actual, expectedOpsForPrimitiveOptions,
"other date fields are read before TypeError is thrown for primitive options");
actual.splice(0); // clear
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ includes: [compareArray.js, temporalHelpers.js]
features: [Temporal]
---*/

const expected = [
const expectedOpsForPrimitiveOptions = [
// ToTemporalDurationRecord
"get fields.days",
"get fields.days.valueOf",
Expand Down Expand Up @@ -40,10 +40,12 @@ const expected = [
"get fields.years",
"get fields.years.valueOf",
"call fields.years.valueOf",
];
const expected = expectedOpsForPrimitiveOptions.concat([
"get options.overflow",
"get options.overflow.toString",
"call options.overflow.toString",
];
]);
const actual = [];

const instance = new Temporal.PlainDate(2000, 5, 2, "iso8601");
Expand All @@ -69,3 +71,9 @@ instance.subtract(fields, options);
assert.compareArray(actual, expected, "order of operations");

actual.splice(0); // clear

assert.throws(TypeError, () => instance.subtract(fields, null));
assert.compareArray(actual, expectedOpsForPrimitiveOptions,
"duration fields are read before TypeError is thrown for primitive options");

actual.splice(0); // clear
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ includes: [compareArray.js, temporalHelpers.js]
features: [Temporal]
---*/

const expected = [
const expectedOpsForPrimitiveOptions = [
// ToTemporalDate
"get other.calendar",
"get other.day",
Expand All @@ -23,6 +23,8 @@ const expected = [
"get other.year",
"get other.year.valueOf",
"call other.year.valueOf",
];
const expected = expectedOpsForPrimitiveOptions.concat([
// GetDifferenceSettings
"get options.largestUnit",
"get options.largestUnit.toString",
Expand All @@ -36,7 +38,7 @@ const expected = [
"get options.smallestUnit",
"get options.smallestUnit.toString",
"call options.smallestUnit.toString",
];
]);
const actual = [];

const instance = new Temporal.PlainDate(2000, 5, 2, "iso8601");
Expand Down Expand Up @@ -65,3 +67,8 @@ function createOptionsObserver({ smallestUnit = "days", largestUnit = "auto", ro
instance.until(otherDatePropertyBag, createOptionsObserver({ largestUnit: "years" }));
assert.compareArray(actual, expected, "order of operations");
actual.splice(0); // clear

assert.throws(TypeError, () => instance.until(otherDatePropertyBag, null));
assert.compareArray(actual, expectedOpsForPrimitiveOptions,
"other date fields are read before TypeError is thrown for primitive options");
actual.splice(0); // clear
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ includes: [compareArray.js, temporalHelpers.js]
features: [Temporal]
---*/

const expected = [
const expectedOpsForPrimitiveOptions = [
// RejectObjectWithCalendarOrTimeZone
"get fields.calendar",
"get fields.timeZone",
Expand All @@ -25,11 +25,13 @@ const expected = [
"get fields.year",
"get fields.year.valueOf",
"call fields.year.valueOf",
];
const expected = expectedOpsForPrimitiveOptions.concat([
// GetTemporalOverflowOption
"get options.overflow",
"get options.overflow.toString",
"call options.overflow.toString",
];
]);
const actual = [];

const instance = new Temporal.PlainDate(2000, 5, 2, "iso8601");
Expand All @@ -50,3 +52,11 @@ const options = TemporalHelpers.propertyBagObserver(actual, {

instance.with(fields, options);
assert.compareArray(actual, expected, "order of operations");

actual.splice(0); // clear

assert.throws(TypeError, () => instance.with(fields, null));
assert.compareArray(actual, expectedOpsForPrimitiveOptions,
"argument fields are read before TypeError is thrown for primitive options");

actual.splice(0); // clear
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ const expectedOptionsReading = [
"call options.overflow.toString",
];

const expected = [
const expectedOpsForPrimitiveOptions = [
// GetTemporalCalendarSlotValueWithISODefault
"get fields.calendar",
// PrepareTemporalFields
Expand Down Expand Up @@ -49,7 +49,8 @@ const expected = [
"get fields.year",
"get fields.year.valueOf",
"call fields.year.valueOf",
].concat(expectedOptionsReading);
];
const expected = expectedOpsForPrimitiveOptions.concat(expectedOptionsReading);
const actual = [];

const fields = TemporalHelpers.propertyBagObserver(actual, {
Expand Down Expand Up @@ -93,3 +94,11 @@ actual.splice(0);

Temporal.PlainDateTime.from("2001-05-02", options);
assert.compareArray(actual, expectedOptionsReading, "order of operations when parsing a string");

actual.splice(0);

assert.throws(TypeError, () => Temporal.PlainDateTime.from(fields, null));
assert.compareArray(actual, expectedOpsForPrimitiveOptions,
"item fields are read before TypeError is thrown for primitive options");

actual.splice(0); // clear
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ includes: [compareArray.js, temporalHelpers.js]
features: [Temporal]
---*/

const expected = [
const expectedOpsForPrimitiveOptions = [
// ToTemporalDurationRecord
"get fields.days",
"get fields.days.valueOf",
Expand Down Expand Up @@ -40,10 +40,12 @@ const expected = [
"get fields.years",
"get fields.years.valueOf",
"call fields.years.valueOf",
];
const expected = expectedOpsForPrimitiveOptions.concat([
"get options.overflow",
"get options.overflow.toString",
"call options.overflow.toString",
];
]);
const actual = [];

const instance = new Temporal.PlainDateTime(2000, 5, 2, 12, 34, 56, 987, 654, 321, "iso8601");
Expand All @@ -69,3 +71,9 @@ instance.add(fields, options);
assert.compareArray(actual, expected, "order of operations");

actual.splice(0); // clear

assert.throws(TypeError, () => instance.add(fields, null));
assert.compareArray(actual, expectedOpsForPrimitiveOptions,
"duration fields are read before TypeError is thrown for primitive options");

actual.splice(0); // clear
Loading
Loading