test262/test/built-ins/Temporal/PlainDateTime/compare/argument-calendar-fields-undefined.js
Philip Chimento 01f73e96ca Temporal: Add tests for avoiding observable iteration in CalendarFields
See https://github.com/tc39/proposal-temporal/pull/2316 which eliminated
an observable call to Array.prototype[Symbol.iterator]() in the case where
a calendar's 'fields' property was undefined.

The best way I've thought of to test this is to monkeypatch the
Array.prototype[Symbol.iterator]() method to make it throw. In some cases,
where we are actually expected to iterate the return value from a
Temporal.TimeZone's getPossibleInstantsFor() method, we have to provide a
custom method for that as well, that returns a non-Array iterable so we
don't call the patched Array.prototype[Symbol.iterator]().

This normative change reached consensus at the July 2022 TC39 plenary
meeting.
2022-10-11 12:23:47 +02:00

26 lines
823 B
JavaScript

// Copyright (C) 2022 Igalia, S.L. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-temporal.plaindatetime.prototype.compare
description: >
When calendar.fields is undefined, compare() doesn't perform an
observable array iteration to convert the property bag to PlainDateTime
features: [Temporal]
---*/
const calendar = new Temporal.Calendar("iso8601");
calendar.fields = undefined;
// Detect observable array iteration:
const oldIterator = Array.prototype[Symbol.iterator];
Array.prototype[Symbol.iterator] = function () {
throw new Test262Error(`array shouldn't be iterated: ${new Error().stack}`);
};
const arg = { year: 1981, month: 12, day: 15, calendar };
Temporal.PlainDateTime.compare(arg, arg);
Array.prototype[Symbol.iterator] = oldIterator;