Temporal: Test observable calendar.dateUntil() calls with null-prototype options

As of https://github.com/tc39/proposal-temporal/pull/2219 since() and
until() methods should be calling the calendar's dateUntil() method with a
null-prototype object as the options parameter, due to the change in
MergeLargestUnitOption. This adds a test for this behaviour.
This commit is contained in:
Philip Chimento 2022-06-26 10:28:06 +02:00 committed by Ms2ger
parent 5e564b96e7
commit 0c33b09337
9 changed files with 161 additions and 0 deletions

View File

@ -895,6 +895,31 @@ var TemporalHelpers = {
assert.compareArray(actual, expected, "property getters not called"); assert.compareArray(actual, expected, "property getters not called");
}, },
/*
* A custom calendar used in prototype pollution checks. Verifies that methods
* are always called with a null-prototype options object.
*/
calendarCheckOptionsPrototypePollution() {
class CalendarCheckOptionsPrototypePollution extends Temporal.Calendar {
constructor() {
super("iso8601");
this.dateUntilCallCount = 0;
}
toString() {
return "options-null-proto";
}
dateUntil(one, two, options) {
this.dateUntilCallCount++;
assert.sameValue(Object.getPrototypeOf(options), null, "dateUntil should be called with null-prototype options");
return super.dateUntil(one, two, options);
}
}
return new CalendarCheckOptionsPrototypePollution();
},
/* /*
* A custom calendar that asserts its dateAdd() method is called with the * A custom calendar that asserts its dateAdd() method is called with the
* options parameter having the value undefined. * options parameter having the value undefined.

View File

@ -0,0 +1,17 @@
// 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.plaindate.prototype.since
description: >
Calendar.dateUntil method is called with a null-prototype object as the
options value when call originates internally
includes: [temporalHelpers.js]
features: [Temporal]
---*/
const calendar = TemporalHelpers.calendarCheckOptionsPrototypePollution();
const instance = new Temporal.PlainDate(2000, 5, 2, calendar);
const argument = new Temporal.PlainDate(2022, 6, 14, calendar);
instance.since(argument);
assert.sameValue(calendar.dateUntilCallCount, 1, "dateUntil should have been called on the calendar");

View File

@ -0,0 +1,17 @@
// 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.plaindate.prototype.until
description: >
Calendar.dateUntil method is called with a null-prototype object as the
options value when call originates internally
includes: [temporalHelpers.js]
features: [Temporal]
---*/
const calendar = TemporalHelpers.calendarCheckOptionsPrototypePollution();
const instance = new Temporal.PlainDate(2000, 5, 2, calendar);
const argument = new Temporal.PlainDate(2022, 6, 14, calendar);
instance.until(argument);
assert.sameValue(calendar.dateUntilCallCount, 1, "dateUntil should have been called on the calendar");

View File

@ -0,0 +1,17 @@
// 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.since
description: >
Calendar.dateUntil method is called with a null-prototype object as the
options value when call originates internally
includes: [temporalHelpers.js]
features: [Temporal]
---*/
const calendar = TemporalHelpers.calendarCheckOptionsPrototypePollution();
const instance = new Temporal.PlainDateTime(2000, 5, 2, 12, 34, 56, 987, 654, 321, calendar);
const argument = new Temporal.PlainDateTime(2022, 6, 14, 18, 21, 36, 660, 690, 387, calendar);
instance.since(argument);
assert.sameValue(calendar.dateUntilCallCount, 1, "dateUntil should have been called on the calendar");

View File

@ -0,0 +1,17 @@
// 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.until
description: >
Calendar.dateUntil method is called with a null-prototype object as the
options value when call originates internally
includes: [temporalHelpers.js]
features: [Temporal]
---*/
const calendar = TemporalHelpers.calendarCheckOptionsPrototypePollution();
const instance = new Temporal.PlainDateTime(2000, 5, 2, 12, 34, 56, 987, 654, 321, calendar);
const argument = new Temporal.PlainDateTime(2022, 6, 14, 18, 21, 36, 660, 690, 387, calendar);
instance.until(argument);
assert.sameValue(calendar.dateUntilCallCount, 1, "dateUntil should have been called on the calendar");

View File

@ -0,0 +1,17 @@
// 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.plainyearmonth.prototype.since
description: >
Calendar.dateUntil method is called with a null-prototype object as the
options value when call originates internally
includes: [temporalHelpers.js]
features: [Temporal]
---*/
const calendar = TemporalHelpers.calendarCheckOptionsPrototypePollution();
const instance = new Temporal.PlainYearMonth(2000, 5, calendar);
const argument = new Temporal.PlainYearMonth(2022, 6, calendar);
instance.since(argument);
assert.sameValue(calendar.dateUntilCallCount, 1, "dateUntil should have been called on the calendar");

View File

@ -0,0 +1,17 @@
// 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.plainyearmonth.prototype.until
description: >
Calendar.dateUntil method is called with a null-prototype object as the
options value when call originates internally
includes: [temporalHelpers.js]
features: [Temporal]
---*/
const calendar = TemporalHelpers.calendarCheckOptionsPrototypePollution();
const instance = new Temporal.PlainYearMonth(2000, 5, calendar);
const argument = new Temporal.PlainYearMonth(2022, 6, calendar);
instance.until(argument);
assert.sameValue(calendar.dateUntilCallCount, 1, "dateUntil should have been called on the calendar");

View File

@ -0,0 +1,17 @@
// 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.zoneddatetime.prototype.since
description: >
Calendar.dateUntil method is called with a null-prototype object as the
options value when call originates internally
includes: [temporalHelpers.js]
features: [Temporal]
---*/
const calendar = TemporalHelpers.calendarCheckOptionsPrototypePollution();
const instance = new Temporal.ZonedDateTime(0n, "UTC", calendar);
const argument = new Temporal.ZonedDateTime(1_000_000_000_000_000_000n, "UTC", calendar);
instance.since(argument, { largestUnit: "year" });
assert.sameValue(calendar.dateUntilCallCount, 2, "dateUntil should have been called on the calendar");

View File

@ -0,0 +1,17 @@
// 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.zoneddatetime.prototype.until
description: >
Calendar.dateUntil method is called with a null-prototype object as the
options value when call originates internally
includes: [temporalHelpers.js]
features: [Temporal]
---*/
const calendar = TemporalHelpers.calendarCheckOptionsPrototypePollution();
const instance = new Temporal.ZonedDateTime(0n, "UTC", calendar);
const argument = new Temporal.ZonedDateTime(1_000_000_000_000_000_000n, "UTC", calendar);
instance.until(argument, { largestUnit: "year" });
assert.sameValue(calendar.dateUntilCallCount, 2, "dateUntil should have been called on the calendar");