From bcd44ca773c442a23e21fd3d5595beef76385614 Mon Sep 17 00:00:00 2001 From: Philip Chimento Date: Thu, 2 Mar 2023 17:40:57 -0800 Subject: [PATCH] Temporal: Copy options object in Plain{Date,MonthDay,YearMonth}.{from,p.with} --- ...le-get-overflow-argument-string-invalid.js | 19 +++------- ...observable-get-overflow-argument-string.js | 29 +++++++-------- .../PlainDate/from/order-of-operations.js | 11 ++++-- .../PlainDate/prototype/with/custom.js | 7 ++-- .../prototype/with/order-of-operations.js | 8 ++++- ...le-get-overflow-argument-string-invalid.js | 21 +++++++++++ ...observable-get-overflow-argument-string.js | 36 +++++++++++++++++++ .../PlainMonthDay/from/order-of-operations.js | 12 +++++-- .../prototype/with/calendar-arguments.js | 7 ++-- .../prototype/with/order-of-operations.js | 12 +++++-- ...le-get-overflow-argument-string-invalid.js | 21 +++++++++++ ...observable-get-overflow-argument-string.js | 34 ++++++++++++++++++ .../from/order-of-operations.js | 12 +++++-- .../prototype/with/calendar-arguments.js | 7 ++-- .../prototype/with/order-of-operations.js | 12 +++++-- 15 files changed, 203 insertions(+), 45 deletions(-) create mode 100644 test/built-ins/Temporal/PlainMonthDay/from/observable-get-overflow-argument-string-invalid.js create mode 100644 test/built-ins/Temporal/PlainMonthDay/from/observable-get-overflow-argument-string.js create mode 100644 test/built-ins/Temporal/PlainYearMonth/from/observable-get-overflow-argument-string-invalid.js create mode 100644 test/built-ins/Temporal/PlainYearMonth/from/observable-get-overflow-argument-string.js diff --git a/test/built-ins/Temporal/PlainDate/from/observable-get-overflow-argument-string-invalid.js b/test/built-ins/Temporal/PlainDate/from/observable-get-overflow-argument-string-invalid.js index f0dee3ade9c..f3789e814d3 100644 --- a/test/built-ins/Temporal/PlainDate/from/observable-get-overflow-argument-string-invalid.js +++ b/test/built-ins/Temporal/PlainDate/from/observable-get-overflow-argument-string-invalid.js @@ -4,27 +4,18 @@ /*--- esid: sec-temporal.plaindate.from description: overflow property is extracted with ISO-invalid string argument. -info: | - 1. Perform ? ToTemporalOverflow(_options_). - - 1. If ! IsValidISODate(year, month, day) is false, throw a RangeError exception. includes: [compareArray.js, temporalHelpers.js] features: [Temporal] ---*/ const expected = [ - "get overflow", - "get overflow.toString", - "call overflow.toString", + "ownKeys options", + "getOwnPropertyDescriptor options.overflow", + "get options.overflow", ]; let actual = []; -const object = { - get overflow() { - actual.push("get overflow"); - return TemporalHelpers.toPrimitiveObserver(actual, "constrain", "overflow"); - } -}; +const options = TemporalHelpers.propertyBagObserver(actual, { overflow: "constrain" }, "options"); -assert.throws(RangeError, () => Temporal.PlainDate.from("2020-13-34", object)); +assert.throws(RangeError, () => Temporal.PlainDate.from("2020-13-34", options)); assert.compareArray(actual, expected); diff --git a/test/built-ins/Temporal/PlainDate/from/observable-get-overflow-argument-string.js b/test/built-ins/Temporal/PlainDate/from/observable-get-overflow-argument-string.js index c4f6599b6c5..e1dcc6795f6 100644 --- a/test/built-ins/Temporal/PlainDate/from/observable-get-overflow-argument-string.js +++ b/test/built-ins/Temporal/PlainDate/from/observable-get-overflow-argument-string.js @@ -4,30 +4,31 @@ /*--- esid: sec-temporal.plaindate.from description: overflow property is extracted with string argument. -info: | - 1. Perform ? ToTemporalOverflow(_options_). includes: [compareArray.js, temporalHelpers.js] features: [Temporal] ---*/ const expected = [ - "get overflow", - "get overflow.toString", - "call overflow.toString", + "ownKeys options", + "getOwnPropertyDescriptor options.overflow", + "get options.overflow", + "get options.overflow.toString", + "call options.overflow.toString", ]; let actual = []; -const object = { - get overflow() { - actual.push("get overflow"); - return TemporalHelpers.toPrimitiveObserver(actual, "reject", "overflow"); - } -}; +const options = TemporalHelpers.propertyBagObserver(actual, { overflow: "constrain" }, "options"); -const result = Temporal.PlainDate.from("2021-05-17", object); +const result = Temporal.PlainDate.from("2021-05-17", options); assert.compareArray(actual, expected, "Successful call"); TemporalHelpers.assertPlainDate(result, 2021, 5, "M05", 17); actual.splice(0); // empty it for the next check -assert.throws(TypeError, () => Temporal.PlainDate.from(7, object)); -assert.compareArray(actual, expected, "Failing call"); +const failureExpected = [ + "ownKeys options", + "getOwnPropertyDescriptor options.overflow", + "get options.overflow", +]; + +assert.throws(TypeError, () => Temporal.PlainDate.from(7, options)); +assert.compareArray(actual, failureExpected, "Failing call"); diff --git a/test/built-ins/Temporal/PlainDate/from/order-of-operations.js b/test/built-ins/Temporal/PlainDate/from/order-of-operations.js index e0f621e891b..05896453a65 100644 --- a/test/built-ins/Temporal/PlainDate/from/order-of-operations.js +++ b/test/built-ins/Temporal/PlainDate/from/order-of-operations.js @@ -9,6 +9,11 @@ features: [Temporal] ---*/ const expected = [ + "ownKeys options", + "getOwnPropertyDescriptor options.overflow", + "get options.overflow", + "getOwnPropertyDescriptor options.extra", + "get options.extra", "get fields.calendar", "has fields.calendar.dateAdd", "has fields.calendar.dateFromFields", @@ -48,7 +53,6 @@ const expected = [ "get fields.calendar.dateFromFields", "call fields.calendar.dateFromFields", // inside Calendar.p.dateFromFields - "get options.overflow", "get options.overflow.toString", "call options.overflow.toString", ]; @@ -63,7 +67,10 @@ const fields = TemporalHelpers.propertyBagObserver(actual, { calendar, }, "fields"); -const options = TemporalHelpers.propertyBagObserver(actual, { overflow: "constrain" }, "options"); +const options = TemporalHelpers.propertyBagObserver(actual, { + overflow: "constrain", + extra: "property", +}, "options"); const result = Temporal.PlainDate.from(fields, options); assert.compareArray(actual, expected, "order of operations"); diff --git a/test/built-ins/Temporal/PlainDate/prototype/with/custom.js b/test/built-ins/Temporal/PlainDate/prototype/with/custom.js index 46ecc26d4ca..d96fd3bcab5 100644 --- a/test/built-ins/Temporal/PlainDate/prototype/with/custom.js +++ b/test/built-ins/Temporal/PlainDate/prototype/with/custom.js @@ -8,7 +8,9 @@ features: [Temporal] ---*/ const result = new Temporal.PlainDate(1920, 5, 3); -const options = {}; +const options = { + extra: "property", +}; let calls = 0; class CustomCalendar extends Temporal.Calendar { constructor() { @@ -22,7 +24,8 @@ class CustomCalendar extends Temporal.Calendar { assert.sameValue(args[0].month, 11, "First argument: month"); assert.sameValue(args[0].monthCode, "M11", "First argument: monthCode"); assert.sameValue(args[0].year, 43, "First argument: year"); - assert.sameValue(args[1], options, "Second argument"); + assert.notSameValue(args[1], options, "Second argument is a copy of options"); + assert.sameValue(args[1].extra, "property", "All properties are copied"); return result; } } diff --git a/test/built-ins/Temporal/PlainDate/prototype/with/order-of-operations.js b/test/built-ins/Temporal/PlainDate/prototype/with/order-of-operations.js index 8ad2e977468..5924aff9bdf 100644 --- a/test/built-ins/Temporal/PlainDate/prototype/with/order-of-operations.js +++ b/test/built-ins/Temporal/PlainDate/prototype/with/order-of-operations.js @@ -12,6 +12,12 @@ const expected = [ // RejectObjectWithCalendarOrTimeZone "get fields.calendar", "get fields.timeZone", + // CopyDataProperties + "ownKeys options", + "getOwnPropertyDescriptor options.overflow", + "get options.overflow", + "getOwnPropertyDescriptor options.extra", + "get options.extra", // CalendarFields "get this.calendar.fields", "call this.calendar.fields", @@ -44,7 +50,6 @@ const expected = [ "get this.calendar.dateFromFields", "call this.calendar.dateFromFields", // inside Calendar.p.dateFromFields - "get options.overflow", "get options.overflow.toString", "call options.overflow.toString", ]; @@ -64,6 +69,7 @@ const fields = TemporalHelpers.propertyBagObserver(actual, { const options = TemporalHelpers.propertyBagObserver(actual, { overflow: "constrain", + extra: "property", }, "options"); instance.with(fields, options); diff --git a/test/built-ins/Temporal/PlainMonthDay/from/observable-get-overflow-argument-string-invalid.js b/test/built-ins/Temporal/PlainMonthDay/from/observable-get-overflow-argument-string-invalid.js new file mode 100644 index 00000000000..297ea0dfd3f --- /dev/null +++ b/test/built-ins/Temporal/PlainMonthDay/from/observable-get-overflow-argument-string-invalid.js @@ -0,0 +1,21 @@ +// Copyright (C) 2023 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-temporal.plainmonthday.from +description: overflow property is extracted with ISO-invalid string argument. +includes: [compareArray.js, temporalHelpers.js] +features: [Temporal] +---*/ + +const expected = [ + "ownKeys options", + "getOwnPropertyDescriptor options.overflow", + "get options.overflow", +]; + +let actual = []; +const options = TemporalHelpers.propertyBagObserver(actual, { overflow: "constrain" }, "options"); + +assert.throws(RangeError, () => Temporal.PlainMonthDay.from("13-34", options)); +assert.compareArray(actual, expected); diff --git a/test/built-ins/Temporal/PlainMonthDay/from/observable-get-overflow-argument-string.js b/test/built-ins/Temporal/PlainMonthDay/from/observable-get-overflow-argument-string.js new file mode 100644 index 00000000000..2dedb669b4c --- /dev/null +++ b/test/built-ins/Temporal/PlainMonthDay/from/observable-get-overflow-argument-string.js @@ -0,0 +1,36 @@ +// Copyright (C) 2023 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-temporal.plainmonthday.from +description: overflow property is extracted with string argument. +info: | + 1. Perform ? ToTemporalOverflow(_options_). +includes: [compareArray.js, temporalHelpers.js] +features: [Temporal] +---*/ + +const expected = [ + "ownKeys options", + "getOwnPropertyDescriptor options.overflow", + "get options.overflow", + "get options.overflow.toString", + "call options.overflow.toString", +]; + +let actual = []; +const options = TemporalHelpers.propertyBagObserver(actual, { overflow: "constrain" }, "options"); + +const result = Temporal.PlainMonthDay.from("05-17", options); +assert.compareArray(actual, expected, "Successful call"); +TemporalHelpers.assertPlainMonthDay(result, "M05", 17); + +actual.splice(0); // empty it for the next check +const failureExpected = [ + "ownKeys options", + "getOwnPropertyDescriptor options.overflow", + "get options.overflow", +]; + +assert.throws(TypeError, () => Temporal.PlainMonthDay.from(7, options)); +assert.compareArray(actual, failureExpected, "Failing call"); diff --git a/test/built-ins/Temporal/PlainMonthDay/from/order-of-operations.js b/test/built-ins/Temporal/PlainMonthDay/from/order-of-operations.js index 043b3461ceb..47a4d6d17e6 100644 --- a/test/built-ins/Temporal/PlainMonthDay/from/order-of-operations.js +++ b/test/built-ins/Temporal/PlainMonthDay/from/order-of-operations.js @@ -9,6 +9,12 @@ features: [Temporal] ---*/ const expected = [ + // CopyDataProperties + "ownKeys options", + "getOwnPropertyDescriptor options.overflow", + "get options.overflow", + "getOwnPropertyDescriptor options.extra", + "get options.extra", "get fields.calendar", "has fields.calendar.dateAdd", "has fields.calendar.dateFromFields", @@ -51,7 +57,6 @@ const expected = [ "get fields.calendar.monthDayFromFields", "call fields.calendar.monthDayFromFields", // inside Calendar.p.monthDayFromFields - "get options.overflow", "get options.overflow.toString", "call options.overflow.toString", ]; @@ -65,7 +70,10 @@ const fields = TemporalHelpers.propertyBagObserver(actual, { calendar: TemporalHelpers.calendarObserver(actual, "fields.calendar"), }, "fields"); -const options = TemporalHelpers.propertyBagObserver(actual, { overflow: "constrain" }, "options"); +const options = TemporalHelpers.propertyBagObserver(actual, { + overflow: "constrain", + extra: "property", +}, "options"); Temporal.PlainMonthDay.from(fields, options); assert.compareArray(actual, expected, "order of operations"); diff --git a/test/built-ins/Temporal/PlainMonthDay/prototype/with/calendar-arguments.js b/test/built-ins/Temporal/PlainMonthDay/prototype/with/calendar-arguments.js index aee39245f96..6bd5c7f5e6d 100644 --- a/test/built-ins/Temporal/PlainMonthDay/prototype/with/calendar-arguments.js +++ b/test/built-ins/Temporal/PlainMonthDay/prototype/with/calendar-arguments.js @@ -12,7 +12,9 @@ includes: [temporalHelpers.js] features: [Temporal] ---*/ -const options = {}; +const options = { + extra: "property", +}; class CustomCalendar extends Temporal.Calendar { constructor() { super("iso8601"); @@ -20,7 +22,8 @@ class CustomCalendar extends Temporal.Calendar { monthDayFromFields(...args) { assert.sameValue(args.length, 2, "args.length"); assert.sameValue(typeof args[0], "object", "args[0]"); - assert.sameValue(args[1], options, "args[1]"); + assert.notSameValue(args[1], options, "args[1] is a copy of options"); + assert.sameValue(args[1].extra, "property", "All properties are copied"); return super.monthDayFromFields(...args); } } diff --git a/test/built-ins/Temporal/PlainMonthDay/prototype/with/order-of-operations.js b/test/built-ins/Temporal/PlainMonthDay/prototype/with/order-of-operations.js index de51a90109e..06e6d712071 100644 --- a/test/built-ins/Temporal/PlainMonthDay/prototype/with/order-of-operations.js +++ b/test/built-ins/Temporal/PlainMonthDay/prototype/with/order-of-operations.js @@ -12,6 +12,12 @@ const expected = [ // RejectObjectWithCalendarOrTimeZone "get fields.calendar", "get fields.timeZone", + // CopyDataProperties + "ownKeys options", + "getOwnPropertyDescriptor options.overflow", + "get options.overflow", + "getOwnPropertyDescriptor options.extra", + "get options.extra", // CalendarFields "get this.calendar.fields", "call this.calendar.fields", @@ -40,7 +46,6 @@ const expected = [ "get this.calendar.monthDayFromFields", "call this.calendar.monthDayFromFields", // inside Calendar.p.monthDayFromFields - "get options.overflow", "get options.overflow.toString", "call options.overflow.toString", ]; @@ -58,7 +63,10 @@ const fields = TemporalHelpers.propertyBagObserver(actual, { day: 1.7, }, "fields"); -const options = TemporalHelpers.propertyBagObserver(actual, { overflow: "constrain" }, "options"); +const options = TemporalHelpers.propertyBagObserver(actual, { + overflow: "constrain", + extra: "property", +}, "options"); instance.with(fields, options); assert.compareArray(actual, expected, "order of operations"); diff --git a/test/built-ins/Temporal/PlainYearMonth/from/observable-get-overflow-argument-string-invalid.js b/test/built-ins/Temporal/PlainYearMonth/from/observable-get-overflow-argument-string-invalid.js new file mode 100644 index 00000000000..7fa6807b3ec --- /dev/null +++ b/test/built-ins/Temporal/PlainYearMonth/from/observable-get-overflow-argument-string-invalid.js @@ -0,0 +1,21 @@ +// Copyright (C) 2023 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-temporal.plainyearmonth.from +description: overflow property is extracted with ISO-invalid string argument. +includes: [compareArray.js, temporalHelpers.js] +features: [Temporal] +---*/ + +const expected = [ + "ownKeys options", + "getOwnPropertyDescriptor options.overflow", + "get options.overflow", +]; + +let actual = []; +const options = TemporalHelpers.propertyBagObserver(actual, { overflow: "constrain" }, "options"); + +assert.throws(RangeError, () => Temporal.PlainYearMonth.from("2020-13", options)); +assert.compareArray(actual, expected); diff --git a/test/built-ins/Temporal/PlainYearMonth/from/observable-get-overflow-argument-string.js b/test/built-ins/Temporal/PlainYearMonth/from/observable-get-overflow-argument-string.js new file mode 100644 index 00000000000..66eeb90b341 --- /dev/null +++ b/test/built-ins/Temporal/PlainYearMonth/from/observable-get-overflow-argument-string.js @@ -0,0 +1,34 @@ +// Copyright (C) 2023 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-temporal.plainyearmonth.from +description: overflow property is extracted with string argument. +includes: [compareArray.js, temporalHelpers.js] +features: [Temporal] +---*/ + +const expected = [ + "ownKeys options", + "getOwnPropertyDescriptor options.overflow", + "get options.overflow", + "get options.overflow.toString", + "call options.overflow.toString", +]; + +let actual = []; +const options = TemporalHelpers.propertyBagObserver(actual, { overflow: "constrain" }, "options"); + +const result = Temporal.PlainYearMonth.from("2021-05", options); +assert.compareArray(actual, expected, "Successful call"); +TemporalHelpers.assertPlainYearMonth(result, 2021, 5, "M05"); + +actual.splice(0); // empty it for the next check +const failureExpected = [ + "ownKeys options", + "getOwnPropertyDescriptor options.overflow", + "get options.overflow", +]; + +assert.throws(TypeError, () => Temporal.PlainYearMonth.from(7, options)); +assert.compareArray(actual, failureExpected, "Failing call"); diff --git a/test/built-ins/Temporal/PlainYearMonth/from/order-of-operations.js b/test/built-ins/Temporal/PlainYearMonth/from/order-of-operations.js index a641a5786cf..a437d1af8cc 100644 --- a/test/built-ins/Temporal/PlainYearMonth/from/order-of-operations.js +++ b/test/built-ins/Temporal/PlainYearMonth/from/order-of-operations.js @@ -9,6 +9,12 @@ features: [Temporal] ---*/ const expected = [ + // CopyDataProperties + "ownKeys options", + "getOwnPropertyDescriptor options.overflow", + "get options.overflow", + "getOwnPropertyDescriptor options.extra", + "get options.extra", // GetTemporalCalendarSlotValueWithISODefault "get fields.calendar", "has fields.calendar.dateAdd", @@ -49,7 +55,6 @@ const expected = [ "get fields.calendar.yearMonthFromFields", "call fields.calendar.yearMonthFromFields", // inside Calendar.p.yearMonthFromFields - "get options.overflow", "get options.overflow.toString", "call options.overflow.toString", ]; @@ -62,7 +67,10 @@ const fields = TemporalHelpers.propertyBagObserver(actual, { calendar: TemporalHelpers.calendarObserver(actual, "fields.calendar"), }, "fields"); -const options = TemporalHelpers.propertyBagObserver(actual, { overflow: "constrain" }, "options"); +const options = TemporalHelpers.propertyBagObserver(actual, { + overflow: "constrain", + extra: "property", +}, "options"); Temporal.PlainYearMonth.from(fields, options); assert.compareArray(actual, expected, "order of operations"); diff --git a/test/built-ins/Temporal/PlainYearMonth/prototype/with/calendar-arguments.js b/test/built-ins/Temporal/PlainYearMonth/prototype/with/calendar-arguments.js index 88332be0d18..33ac85a0e40 100644 --- a/test/built-ins/Temporal/PlainYearMonth/prototype/with/calendar-arguments.js +++ b/test/built-ins/Temporal/PlainYearMonth/prototype/with/calendar-arguments.js @@ -12,7 +12,9 @@ includes: [temporalHelpers.js] features: [Temporal] ---*/ -const options = {}; +const options = { + extra: "property", +}; class CustomCalendar extends Temporal.Calendar { constructor() { super("iso8601"); @@ -20,7 +22,8 @@ class CustomCalendar extends Temporal.Calendar { yearMonthFromFields(...args) { assert.sameValue(args.length, 2, "args.length"); assert.sameValue(typeof args[0], "object", "args[0]"); - assert.sameValue(args[1], options, "args[1]"); + assert.notSameValue(args[1], options, "args[1] is a copy of options"); + assert.sameValue(args[1].extra, "property", "All properties are copied"); return super.yearMonthFromFields(...args); } } diff --git a/test/built-ins/Temporal/PlainYearMonth/prototype/with/order-of-operations.js b/test/built-ins/Temporal/PlainYearMonth/prototype/with/order-of-operations.js index c6980bd375c..8fc854d1604 100644 --- a/test/built-ins/Temporal/PlainYearMonth/prototype/with/order-of-operations.js +++ b/test/built-ins/Temporal/PlainYearMonth/prototype/with/order-of-operations.js @@ -12,6 +12,12 @@ const expected = [ // RejectObjectWithCalendarOrTimeZone "get fields.calendar", "get fields.timeZone", + // CopyDataProperties + "ownKeys options", + "getOwnPropertyDescriptor options.overflow", + "get options.overflow", + "getOwnPropertyDescriptor options.extra", + "get options.extra", // CalendarFields "get this.calendar.fields", "call this.calendar.fields", @@ -39,7 +45,6 @@ const expected = [ "get this.calendar.yearMonthFromFields", "call this.calendar.yearMonthFromFields", // inside Calendar.p.yearMonthFromFields - "get options.overflow", "get options.overflow.toString", "call options.overflow.toString", ]; @@ -56,7 +61,10 @@ const fields = TemporalHelpers.propertyBagObserver(actual, { monthCode: "M01", }, "fields"); -const options = TemporalHelpers.propertyBagObserver(actual, { overflow: "constrain" }, "options"); +const options = TemporalHelpers.propertyBagObserver(actual, { + overflow: "constrain", + extra: "property", +}, "options"); instance.with(fields, options); assert.compareArray(actual, expected, "order of operations");