fix(temporal): align Duration toLocaleString with spec fallback and i…#5255
Open
Veercodeprog wants to merge 1 commit intoboa-dev:mainfrom
Open
fix(temporal): align Duration toLocaleString with spec fallback and i…#5255Veercodeprog wants to merge 1 commit intoboa-dev:mainfrom
Veercodeprog wants to merge 1 commit intoboa-dev:mainfrom
Conversation
…mprove valueOf error
nekevss
reviewed
Mar 25, 2026
Member
nekevss
left a comment
There was a problem hiding this comment.
I'm unclear on the purpose for this PR.
The implementation deleted is the exact same implementation as Duration::to_json, so we are just adding an unnecessary level of indirection for the same output.
There is probably a good argument that a more descriptive value_of message could be made, but this would be across all Temporal built-ins. But I think I'd expect it a bit more similar to the preexisting error message.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR brings
Temporal.Duration.prototype.toLocaleString()andTemporal.Duration.prototype.valueOf()closer to the Temporal spec.Since Boa does not currently implement
Intl.DurationFormat,Duration.prototype.toLocaleString()should follow the spec-defined fallback behavior. In practice, that means returning the same serialized output astoJSON().This change also keeps
Duration.prototype.valueOf()as a throwing method, while updating the error message to point users to the APIs that are actually appropriate for comparison and string conversion.Motivation
toLocaleString()previously produced output equivalent to the default duration serialization, but the implementation did not clearly reflect the spec's fallback path when ECMA-402 duration formatting is unavailable.valueOf()already threw as expected, but the error message was not aligned with the spec note and did not direct users toward the best alternatives.Changes
Temporal.Duration.prototype.toLocaleString()toLocaleString()delegate totoJSON().localesandoptions, even though those arguments are currently ignored.Intl.DurationFormatis not implemented yet.Temporal.Duration.prototype.valueOf()TypeError.Temporal.Duration.compare()Temporal.Duration.prototype.toString()Tests
Added test coverage for the following cases in
core/engine/src/builtins/temporal/duration/tests.rs:toLocaleString()returns the same result astoJSON().toLocaleString(locales, options)still returns the same result while Intl-backed formatting is not implemented.valueOf()throwsTypeErrorwith the updated error message.Testing