From b5d3192914e9b107ce4f5df4f77e625865d337c7 Mon Sep 17 00:00:00 2001 From: Philip Chimento Date: Mon, 17 Oct 2022 17:39:27 -0700 Subject: [PATCH] Temporal: Test Calendar.p.mergeFields enumeration changes This tests the normative changes in https://github.com/tc39/proposal-temporal/pull/2245, which achieved consensus in the July 2022 TC39 meeting, specifically as they apply to the Temporal.Calendar.prototype.mergeFields method. Due to the use of the pre-existing spec operation CopyDataProperties, now symbol keys are merged into the return value, and the order of observable property operations has changed from a batch of [[GetOwnProperty]] followed by a batch of [[Get]], to a series of interleaved [[GetOwnProperty]]/[[Get]] pairs. --- .../mergeFields/non-string-properties.js | 6 +-- .../mergeFields/order-of-operations.js | 45 +++++++++++++++++++ 2 files changed, 48 insertions(+), 3 deletions(-) create mode 100644 test/built-ins/Temporal/Calendar/prototype/mergeFields/order-of-operations.js diff --git a/test/built-ins/Temporal/Calendar/prototype/mergeFields/non-string-properties.js b/test/built-ins/Temporal/Calendar/prototype/mergeFields/non-string-properties.js index 2a48dbf62c..68f861c1f7 100644 --- a/test/built-ins/Temporal/Calendar/prototype/mergeFields/non-string-properties.js +++ b/test/built-ins/Temporal/Calendar/prototype/mergeFields/non-string-properties.js @@ -4,7 +4,7 @@ /*--- esid: sec-temporal.calendar.prototype.mergefields -description: Only string keys from the arguments are merged +description: Both string and symbol keys from the arguments are merged info: | 1. Let calendar be the this value. 2. Perform ? RequireInternalSlot(calendar, [[InitializedTemporalCalendar]]). @@ -50,6 +50,6 @@ const foo = Symbol("foo"); const bar = Symbol("bar"); assertEntriesEqual( cal.mergeFields({ [foo]: 1 }, { [bar]: 2 }), - [], - "symbol keys are not merged" + [[foo, 1], [bar, 2]], + "symbol keys are also merged" ); diff --git a/test/built-ins/Temporal/Calendar/prototype/mergeFields/order-of-operations.js b/test/built-ins/Temporal/Calendar/prototype/mergeFields/order-of-operations.js new file mode 100644 index 0000000000..7bc01a5736 --- /dev/null +++ b/test/built-ins/Temporal/Calendar/prototype/mergeFields/order-of-operations.js @@ -0,0 +1,45 @@ +// 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.calendar.prototype.mergefields +description: Properties on objects passed to mergeFields() are accessed in the correct order +features: [Temporal] +includes: [compareArray.js, temporalHelpers.js] +---*/ + +const expected = [ + "ownKeys fields", + "getOwnPropertyDescriptor fields.year", + "get fields.year", + "getOwnPropertyDescriptor fields.month", + "get fields.month", + "getOwnPropertyDescriptor fields.day", + "get fields.day", + "getOwnPropertyDescriptor fields.extra", + "get fields.extra", + "ownKeys additionalFields", + "getOwnPropertyDescriptor additionalFields.3", + "get additionalFields.3", + "getOwnPropertyDescriptor additionalFields.monthCode", + "get additionalFields.monthCode", + "getOwnPropertyDescriptor additionalFields[Symbol('extra')]", + "get additionalFields[Symbol('extra')]", +]; +const actual = []; + +const fields = TemporalHelpers.propertyBagObserver(actual, { + year: 2022, + month: 10, + day: 17, + extra: "extra property", +}, "fields"); +const additionalFields = TemporalHelpers.propertyBagObserver(actual, { + [Symbol("extra")]: "extra symbol property", + monthCode: "M10", + 3: "extra array index property", +}, "additionalFields"); + +const instance = new Temporal.Calendar("iso8601"); +instance.mergeFields(fields, additionalFields); +assert.compareArray(actual, expected, "order of observable operations");