Skip to content

Restrict Direct Construction of JsValue to Ensure Invariants #3761

@HalidOdat

Description

@HalidOdat

The problem lies in the ability for users to manually construct a JsValue::Rational from a f64 value that fits within an i32, as JsValue is a public enum.

A proposed solution is to introduce a struct that encapsulates the JsValue enum. By doing so, construction of JsValue::Rational would be limited to its respective constructor functions.

This would allow us to remove many checks that are done to see if a JsValue::Rational f64 value can fit in a i32.

Additional Information

Related to #1373 , something similar was done in #1830 here

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions