test262/test/built-ins/Temporal/Duration/compare/options-read-before-algorithmic-validation.js
Philip Chimento 5048ca6383 Temporal: Add tests for observable order of options get and cast
These tests cover the normative change approved in the July 2025 TC39
plenary. See https://github.com/tc39/proposal-temporal/pull/3130.
All properties of user-passed options objects should be read and cast
before any "algorithmic validation" is done.

This is a lot of tests, that cover every entry point where an options
object is passed in, where subsequently an exception can be thrown or user
code can be called.

However, the normative change only affects 10 of these tests:

- Instant.p.since,until,toString
- PlainDate.p.since,until
- PlainTime.p.since,until
- PlainYearMonth.p.since,until
- ZonedDateTime.p.toString

The other 35 tests simply close a gap in coverage.
2025-08-21 12:01:52 -07:00

23 lines
820 B
JavaScript

// Copyright (C) 2025 Igalia, S.L. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-temporal.duration.compare
description: All options properties are read before any algorithmic validation
includes: [compareArray.js, temporalHelpers.js]
features: [Temporal]
---*/
const expected = ["get options.relativeTo"];
const actual = [];
const options = TemporalHelpers.propertyBagObserver(actual, { relativeTo: undefined }, "options");
const d1 = new Temporal.Duration(0, 0, 0, /* days = */ 1);
const d2 = new Temporal.Duration(1);
assert.throws(RangeError, function () {
Temporal.Duration.compare(d1, d2, options);
}, "exception thrown when calendar units provided without relativeTo");
assert.compareArray(actual, expected, "all options should be read first");