Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Merged by Bors] - Added a bit more integer operation consistency to ByteDataBlock creation #2272

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions boa_engine/src/builtins/array_buffer/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -748,13 +748,17 @@ impl ArrayBuffer {
pub fn create_byte_data_block(size: u64, context: &mut Context) -> JsResult<Vec<u8>> {
// 1. Let db be a new Data Block value consisting of size bytes. If it is impossible to
// create such a Data Block, throw a RangeError exception.
let size = size.try_into().map_err(|e| {
context.construct_range_error(format!("couldn't allocate the data block: {e}"))
})?;

let mut data_block = Vec::new();
data_block.try_reserve(size as usize).map_err(|e| {
data_block.try_reserve(size).map_err(|e| {
context.construct_range_error(format!("couldn't allocate the data block: {e}"))
})?;

// 2. Set all of the bytes of db to 0.
data_block.resize(size as usize, 0);
data_block.resize(size, 0);

// 3. Return db.
Ok(data_block)
Expand Down