diff --git a/harness/temporalHelpers.js b/harness/temporalHelpers.js index f19f3335af..368f8b3398 100644 --- a/harness/temporalHelpers.js +++ b/harness/temporalHelpers.js @@ -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"); diff --git a/test/built-ins/Temporal/PlainYearMonth/prototype/add/calendar-yearmonthfromfields-called-with-null-prototype-options.js b/test/built-ins/Temporal/PlainYearMonth/prototype/add/calendar-yearmonthfromfields-called-with-null-prototype-options.js new file mode 100644 index 0000000000..1f5a94efc2 --- /dev/null +++ b/test/built-ins/Temporal/PlainYearMonth/prototype/add/calendar-yearmonthfromfields-called-with-null-prototype-options.js @@ -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"); diff --git a/test/built-ins/Temporal/PlainYearMonth/prototype/subtract/calendar-yearmonthfromfields-called-with-null-prototype-options.js b/test/built-ins/Temporal/PlainYearMonth/prototype/subtract/calendar-yearmonthfromfields-called-with-null-prototype-options.js new file mode 100644 index 0000000000..6cef4aa2b1 --- /dev/null +++ b/test/built-ins/Temporal/PlainYearMonth/prototype/subtract/calendar-yearmonthfromfields-called-with-null-prototype-options.js @@ -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");