Skip to content

Commit

Permalink
limit toFixed() digits argument between 0 and 100 inclusive
Browse files Browse the repository at this point in the history
  • Loading branch information
Jacherr committed Mar 21, 2024
1 parent d6168ee commit b508fa0
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions crates/dash_vm/src/js_std/number.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,14 @@ pub fn to_fixed(cx: CallContext) -> Result<Value, Value> {
.map(|n| n as usize)
.unwrap_or(0);

if decimals > 100 {
throw!(
cx.scope,
RangeError,
"toFixed() fractional digits must be between 0 and 100 inclusive"
)
};

let re = format!("{num:.decimals$}");

Ok(Value::String(cx.scope.intern(re.as_ref()).into()))
Expand Down

0 comments on commit b508fa0

Please sign in to comment.