Skip to content

Commit

Permalink
Normative: Change TimeZone.prototype.toJSON not to call toString
Browse files Browse the repository at this point in the history
The toJSON method should return the value in the internal slot, instead of
making an observable call to toString.

See: #1808
  • Loading branch information
ptomato committed Feb 18, 2023
1 parent 6e50526 commit 2db24fa
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 2 deletions.
3 changes: 3 additions & 0 deletions docs/cookbook/stockExchangeTimeZone.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,9 @@ class NYSETimeZone extends Temporal.TimeZone {
toString() {
return 'NYSE';
}
toJSON() {
return 'NYSE';
}
}

const tzNYSE = Object.freeze(new NYSETimeZone());
Expand Down
2 changes: 1 addition & 1 deletion polyfill/lib/timezone.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ export class TimeZone {
}
toJSON() {
if (!ES.IsTemporalTimeZone(this)) throw new TypeError('invalid receiver');
return ES.ToString(this);
return GetSlot(this, TIMEZONE_ID);
}
static from(item) {
const timeZoneSlotValue = ES.ToTemporalTimeZoneSlotValue(item);
Expand Down
2 changes: 1 addition & 1 deletion spec/timezone.html
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,7 @@ <h1>Temporal.TimeZone.prototype.toJSON ( )</h1>
<emu-alg>
1. Let _timeZone_ be the *this* value.
1. Perform ? RequireInternalSlot(_timeZone_, [[InitializedTemporalTimeZone]]).
1. Return ? ToString(_timeZone_).
1. Return _timeZone_.[[Identifier]].
</emu-alg>
</emu-clause>
</emu-clause>
Expand Down

0 comments on commit 2db24fa

Please sign in to comment.