mirror of https://github.com/tc39/test262.git
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:
parent
0c33b09337
commit
ca74e801b2
|
@ -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");
|
||||
|
|
|
@ -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");
|
|
@ -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");
|
Loading…
Reference in New Issue