Temporal: Update tests to use internal slot in TimeZone and Calendar.id

In https://github.com/tc39/proposal-temporal/pull/2411, to be proposed for
consensus in TC39 in December, the .id getter of TimeZone and Calendar
should no longer call toString().
This commit is contained in:
Philip Chimento 2022-10-19 09:31:35 -07:00 committed by Philip Chimento
parent 7988e3eb65
commit 0fc42035eb
5 changed files with 12 additions and 32 deletions

View File

@ -3,17 +3,13 @@
/*--- /*---
esid: sec-get-temporal.timezone.prototype.id esid: sec-get-temporal.timezone.prototype.id
description: Getter calls toString() and returns its value description: Getter does not call toString(), returns the ID from internal slot
includes: [compareArray.js, temporalHelpers.js] includes: [compareArray.js, temporalHelpers.js]
features: [Temporal] features: [Temporal]
---*/ ---*/
const actual = []; const actual = [];
const expected = [ const expected = [];
"get [Symbol.toPrimitive]",
"get toString",
"call timeZone.toString",
];
const timeZone = new Temporal.TimeZone("UTC"); const timeZone = new Temporal.TimeZone("UTC");
TemporalHelpers.observeProperty(actual, timeZone, Symbol.toPrimitive, undefined); TemporalHelpers.observeProperty(actual, timeZone, Symbol.toPrimitive, undefined);
@ -24,4 +20,4 @@ TemporalHelpers.observeProperty(actual, timeZone, "toString", function () {
const result = timeZone.id; const result = timeZone.id;
assert.compareArray(actual, expected); assert.compareArray(actual, expected);
assert.sameValue(result, "time zone"); assert.sameValue(result, "UTC");

View File

@ -1,25 +0,0 @@
// Copyright (C) 2020 Igalia, S.L. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-get-temporal.timezone.prototype.id
description: TypeError thrown when toString property not present
includes: [compareArray.js]
features: [Temporal]
---*/
const actual = [];
const expected = [
"get timeZone.toString",
];
const timeZone = new Temporal.TimeZone("UTC");
Object.defineProperty(timeZone, "toString", {
get() {
actual.push("get timeZone.toString");
return undefined;
},
});
assert.throws(TypeError, () => timeZone.id);
assert.compareArray(actual, expected);

View File

@ -11,6 +11,9 @@ class TwoBasedCalendar extends Temporal.Calendar {
constructor() { constructor() {
super("iso8601"); super("iso8601");
} }
get id() {
return "two-based";
}
toString() { toString() {
return "two-based"; return "two-based";
} }

View File

@ -11,6 +11,9 @@ class SubminuteTimeZone extends Temporal.TimeZone {
constructor() { constructor() {
super("-00:00:01.111111111"); super("-00:00:01.111111111");
} }
get id() {
return "Custom/Subminute";
}
toString() { toString() {
return "Custom/Subminute"; return "Custom/Subminute";
} }

View File

@ -11,6 +11,9 @@ class CustomUTCSubclass extends Temporal.TimeZone {
constructor() { constructor() {
super("UTC"); super("UTC");
} }
get id() {
return "Etc/Custom/UTC_Subclass";
}
toString() { toString() {
return "Etc/Custom/UTC_Subclass"; return "Etc/Custom/UTC_Subclass";
} }