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

As of https://github.com/tc39/proposal-temporal/pull/2219 PlainYearMonth's
add() and subtract() methods should be calling the calendar's
yearMonthFromFields() method with a null-prototype object as the options
parameter, due to the change in
AddDurationToOrSubtractDurationFromPlainYearMonth. This adds a test for
this behaviour.
This commit is contained in:
Philip Chimento 2022-06-26 10:29:46 +02:00 committed by Ms2ger
parent 0c33b09337
commit ca74e801b2
3 changed files with 41 additions and 0 deletions

View File

@ -903,6 +903,7 @@ var TemporalHelpers = {
class CalendarCheckOptionsPrototypePollution extends Temporal.Calendar {
constructor() {
super("iso8601");
this.yearMonthFromFieldsCallCount = 0;
this.dateUntilCallCount = 0;
}
@ -910,6 +911,12 @@ var TemporalHelpers = {
return "options-null-proto";
}
yearMonthFromFields(fields, options) {
this.yearMonthFromFieldsCallCount++;
assert.sameValue(Object.getPrototypeOf(options), null, "yearMonthFromFields should be called with null-prototype options");
return super.yearMonthFromFields(fields, options);
}
dateUntil(one, two, options) {
this.dateUntilCallCount++;
assert.sameValue(Object.getPrototypeOf(options), null, "dateUntil should be called with null-prototype options");

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.add
description: >
Calendar.yearMonthFromFields 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(2019, 6, calendar);
const argument = new Temporal.Duration(1, 1);
instance.add(argument);
assert.sameValue(calendar.yearMonthFromFieldsCallCount, 1, "yearMonthFromFields should be 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.subtract
description: >
Calendar.yearMonthFromFields 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(2019, 6, calendar);
const argument = new Temporal.Duration(1, 1);
instance.subtract(argument);
assert.sameValue(calendar.yearMonthFromFieldsCallCount, 1, "yearMonthFromFields should be called on the calendar");