Change Temporal.TimeZone.prototype.toJSON not to call toString

Normative PR: https://github.com/tc39/proposal-temporal/pull/2482
This commit is contained in:
Philip Chimento 2023-01-20 13:30:07 -08:00 committed by Philip Chimento
parent 8c37094e1f
commit 0178aa2114
3 changed files with 4 additions and 45 deletions

View File

@ -3,25 +3,21 @@
/*---
esid: sec-temporal.timezone.prototype.tojson
description: toJSON() calls toString() and returns its value
description: toJSON() returns the internal slot value
includes: [compareArray.js, temporalHelpers.js]
features: [Temporal]
---*/
const actual = [];
const expected = [
'get [Symbol.toPrimitive]',
'get toString',
'call timeZone.toString',
];
const timeZone = new Temporal.TimeZone("UTC");
TemporalHelpers.observeProperty(actual, timeZone, Symbol.toPrimitive, undefined);
TemporalHelpers.observeProperty(actual, timeZone, "id", "Etc/Bogus");
TemporalHelpers.observeProperty(actual, timeZone, "toString", function () {
actual.push("call timeZone.toString");
return "Etc/TAI";
});
const result = timeZone.toJSON();
assert.sameValue(result, 'Etc/TAI', 'toString');
assert.compareArray(actual, expected);
assert.sameValue(result, "UTC", "toJSON gets the internal slot value");
assert.compareArray(actual, [], "should not invoke any observable operations");

View File

@ -1,24 +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-temporal.timezone.prototype.tojson
description: TypeError thrown when toString property not present
includes: [compareArray.js, temporalHelpers.js]
features: [Temporal]
---*/
const actual = [];
const expected = [
'get [Symbol.toPrimitive]',
'get toString',
'get valueOf',
];
const timeZone = new Temporal.TimeZone("UTC");
TemporalHelpers.observeProperty(actual, timeZone, Symbol.toPrimitive, undefined);
TemporalHelpers.observeProperty(actual, timeZone, "toString", undefined);
TemporalHelpers.observeProperty(actual, timeZone, "valueOf", Object.prototype.valueOf);
assert.throws(TypeError, () => timeZone.toJSON());
assert.compareArray(actual, expected);

View File

@ -1,13 +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-temporal.timezone.prototype.tojson
description: TypeError thrown when toString property not present
features: [Temporal]
---*/
const tz = Temporal.TimeZone.from('UTC');
tz.toString = undefined;
assert.throws(TypeError, () => tz.toJSON());