Skip to content

Commit

Permalink
Update spec comment
Browse files Browse the repository at this point in the history
  • Loading branch information
HalidOdat committed Apr 11, 2023
1 parent 140ff28 commit f09c45d
Showing 1 changed file with 3 additions and 4 deletions.
7 changes: 3 additions & 4 deletions boa_engine/src/builtins/string/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2185,21 +2185,20 @@ impl String {
length.to_integer_or_infinity(context)?
};

// 8. Set intLength to the result of clamping intLength between 0 and size.
// 9. Set intLength to the result of clamping intLength between 0 and size.
let int_length = match int_length {
IntegerOrInfinity::NegativeInfinity => 0,
IntegerOrInfinity::PositiveInfinity => size,
IntegerOrInfinity::Integer(i) => i.clamp(0, size),
} as usize;

// 9. Let intEnd be min(intStart + intLength, size).
// 10. Let intEnd be min(intStart + intLength, size).
let int_end = min(int_start + int_length, size as usize);

// 11. Return the substring of S from intStart to intEnd.
if let Some(substr) = s.get(int_start..int_end) {
// 11. Return the substring of S from intStart to intEnd.
Ok(js_string!(substr).into())
} else {
// 10. If intStart ≥ intEnd, return the empty String.
Ok(js_string!().into())
}
}
Expand Down

0 comments on commit f09c45d

Please sign in to comment.