From c37e0e5a51db1ce8919f92637a58ef1f84270ff6 Mon Sep 17 00:00:00 2001 From: Philip Chimento Date: Wed, 28 Jan 2026 16:20:25 -0800 Subject: [PATCH] Temporal: Order of operations in PlainYearMonth.p.add/subtract The recent normative change disallowing addition of weeks and lower units (https://github.com/tc39/proposal-temporal/pull/3253) should be implemented such that the exception is thrown after all options are read and cast. --- .../add/options-read-before-algorithmic-validation.js | 9 +++++++++ .../options-read-before-algorithmic-validation.js | 9 +++++++++ 2 files changed, 18 insertions(+) diff --git a/test/built-ins/Temporal/PlainYearMonth/prototype/add/options-read-before-algorithmic-validation.js b/test/built-ins/Temporal/PlainYearMonth/prototype/add/options-read-before-algorithmic-validation.js index 3f9bb7bbd37..e93e660308c 100644 --- a/test/built-ins/Temporal/PlainYearMonth/prototype/add/options-read-before-algorithmic-validation.js +++ b/test/built-ins/Temporal/PlainYearMonth/prototype/add/options-read-before-algorithmic-validation.js @@ -26,3 +26,12 @@ assert.throws(RangeError, function () { instance.add(new Temporal.Duration(0, 1), options); }, "exception thrown when converting -271821-04 to date"); assert.compareArray(actual, expected, "all options should be read first"); + +actual.splice(0); // clear + +const instance2 = new Temporal.PlainYearMonth(1999, 12); + +assert.throws(RangeError, function () { + instance2.add(new Temporal.Duration(0, 0, 1), options); +}, "exception thrown when attempting to add too-low unit"); +assert.compareArray(actual, expected, "all options should be read first"); diff --git a/test/built-ins/Temporal/PlainYearMonth/prototype/subtract/options-read-before-algorithmic-validation.js b/test/built-ins/Temporal/PlainYearMonth/prototype/subtract/options-read-before-algorithmic-validation.js index 96873b0eb10..ee5d9c6e5f3 100644 --- a/test/built-ins/Temporal/PlainYearMonth/prototype/subtract/options-read-before-algorithmic-validation.js +++ b/test/built-ins/Temporal/PlainYearMonth/prototype/subtract/options-read-before-algorithmic-validation.js @@ -26,3 +26,12 @@ assert.throws(RangeError, function () { instance.subtract(new Temporal.Duration(0, -1), options); }, "exception thrown when converting -271821-04 to date"); assert.compareArray(actual, expected, "all options should be read first"); + +actual.splice(0); // clear + +const instance2 = new Temporal.PlainYearMonth(1999, 12); + +assert.throws(RangeError, function () { + instance2.add(new Temporal.Duration(0, 0, 1), options); +}, "exception thrown when attempting to add too-low unit"); +assert.compareArray(actual, expected, "all options should be read first");