Skip to content

Commit

Permalink
Temporal: Test Calendar.p.mergeFields enumeration changes
Browse files Browse the repository at this point in the history
This tests the normative changes in
tc39/proposal-temporal#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.
  • Loading branch information
ptomato authored and Ms2ger committed Oct 20, 2022
1 parent 99bc91e commit b5d3192
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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]]).
Expand Down Expand Up @@ -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"
);
Original file line number Diff line number Diff line change
@@ -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");

0 comments on commit b5d3192

Please sign in to comment.