boa
boa copied to clipboard
Restrict Direct Construction of `JsValue` to Ensure Invariants
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