test262/test/built-ins/Temporal/PlainDateTime/from/order-of-operations.js
Philip Chimento ea11e0e787 Temporal: Further coverage and tweaks for removing Calendar/TimeZone objs
Tweak some tests to provide coverage of new execution paths in the spec,
such as calling GetOptionsObject inside ToTemporal___; add a few new tests
for things that weren't covered before, such as rounding a PlainDateTime
at the edge of the range; and tweak the tests verifying when the
properties of the options bag are read, which I made a mistake in #4119.

See: https://github.com/tc39/proposal-temporal/pull/2925
2024-08-22 14:00:43 -07:00

96 lines
2.8 KiB
JavaScript

// 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.plaindatetime.from
description: Properties on an object passed to from() are accessed in the correct order
includes: [compareArray.js, temporalHelpers.js]
features: [Temporal]
---*/
const expectedOptionsReading = [
// GetTemporalOverflowOption
"get options.overflow",
"get options.overflow.toString",
"call options.overflow.toString",
];
const expected = [
// GetTemporalCalendarSlotValueWithISODefault
"get fields.calendar",
// PrepareTemporalFields
"get fields.day",
"get fields.day.valueOf",
"call fields.day.valueOf",
"get fields.hour",
"get fields.hour.valueOf",
"call fields.hour.valueOf",
"get fields.microsecond",
"get fields.microsecond.valueOf",
"call fields.microsecond.valueOf",
"get fields.millisecond",
"get fields.millisecond.valueOf",
"call fields.millisecond.valueOf",
"get fields.minute",
"get fields.minute.valueOf",
"call fields.minute.valueOf",
"get fields.month",
"get fields.month.valueOf",
"call fields.month.valueOf",
"get fields.monthCode",
"get fields.monthCode.toString",
"call fields.monthCode.toString",
"get fields.nanosecond",
"get fields.nanosecond.valueOf",
"call fields.nanosecond.valueOf",
"get fields.second",
"get fields.second.valueOf",
"call fields.second.valueOf",
"get fields.year",
"get fields.year.valueOf",
"call fields.year.valueOf",
].concat(expectedOptionsReading);
const actual = [];
const fields = TemporalHelpers.propertyBagObserver(actual, {
year: 1.7,
month: 1.7,
monthCode: "M01",
day: 1.7,
hour: 1.7,
minute: 1.7,
second: 1.7,
millisecond: 1.7,
microsecond: 1.7,
nanosecond: 1.7,
calendar: "iso8601",
}, "fields", ["calendar"]);
const options = TemporalHelpers.propertyBagObserver(actual, {
overflow: "constrain",
extra: "property",
}, "options");
Temporal.PlainDateTime.from(fields, options);
assert.compareArray(actual, expected, "order of operations");
actual.splice(0); // clear for next test
Temporal.PlainDateTime.from(new Temporal.PlainDateTime(2000, 5, 2), options);
assert.compareArray(actual, expectedOptionsReading, "order of operations when cloning a PlainDateTime instance");
actual.splice(0);
Temporal.PlainDateTime.from(new Temporal.PlainDate(2000, 5, 2), options);
assert.compareArray(actual, expectedOptionsReading, "order of operations when converting a PlainDate instance");
actual.splice(0);
Temporal.PlainDateTime.from(new Temporal.ZonedDateTime(0n, "UTC"), options);
assert.compareArray(actual, expectedOptionsReading, "order of operations when converting a ZonedDateTime instance");
actual.splice(0);
Temporal.PlainDateTime.from("2001-05-02", options);
assert.compareArray(actual, expectedOptionsReading, "order of operations when parsing a string");