Skip to content
Open
Show file tree
Hide file tree
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
5 changes: 4 additions & 1 deletion src/jsc/webcore_types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -120,9 +120,12 @@ impl BlobContentType {
)
}

/// Heap-owned ASCII-lowercased copy of `slice`.
/// ASCII-lowercased copy of `slice`, heap-owned unless `slice` is empty.
#[inline]
pub fn from_lowercased(slice: &[u8]) -> Self {
if slice.is_empty() {
return Self::default();
}
let mut buf = vec![0u8; slice.len()];
bun_core::strings::copy_lowercase(slice, &mut buf);
Self::Owned(std::sync::Arc::from(buf))
Expand Down
27 changes: 15 additions & 12 deletions src/runtime/webcore/Blob.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1731,7 +1731,7 @@ impl BlobExt for Blob {
blob.offset.set(offset);
blob.size.set(len);

let content_type_was_allocated = content_type.is_owned() && !content_type.is_empty();
let content_type_was_given = !content_type.is_empty();
// infer the content type if it was not specified
if content_type.is_empty()
&& !self.content_type.get().is_owned()
Expand All @@ -1742,7 +1742,7 @@ impl BlobExt for Blob {
blob.content_type.set(content_type);
}
blob.content_type_was_set
.set(self.content_type_was_set.get() || content_type_was_allocated);
.set(self.content_type_was_set.get() || content_type_was_given);
Comment thread
robobun marked this conversation as resolved.
Resolved
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Resolved

let ptr = Blob::new(blob);
// SAFETY: `ptr` just came from `heap::alloc` in `Blob::new`. Spelled
Expand All @@ -1762,13 +1762,7 @@ impl BlobExt for Blob {
) -> JsResult<JSValue> {
let global_this = cx.global();

if self.size.get() == 0 {
let ptr = Blob::new(Blob::init_empty(global_this));
// SAFETY: `ptr` just came from `heap::alloc` in `Blob::new`; spelled
// `BlobExt::to_js(&*ptr, ..)` to pick the `&self` impl over the
// by-value `JsClass::to_js`.
return Ok(unsafe { BlobExt::to_js(&*ptr, global_this) });
}
let receiver_is_empty = self.size.get() == 0;

let size_i64 = i64::try_from(self.size.get()).unwrap_or(i64::MAX);

Expand Down Expand Up @@ -1802,14 +1796,23 @@ impl BlobExt for Blob {
}
}

let mut blob_content_type = BlobContentType::default();
if content_type.is_string() {
let blob_content_type = if content_type.is_string() {
let content_type_view = content_type.to_js_string_view(global_this)?;
let slicer = content_type_view.to_utf8();
let slice = slicer.slice();
if is_valid_blob_type(slice) {
blob_content_type = BlobContentType::from_script(slice);
BlobContentType::from_script(slice)
} else {
BlobContentType::default()
}
} else {
BlobContentType::default()
};

// Nothing of an empty receiver is kept: the slice is what `new Blob([], { type })` gives.
if receiver_is_empty {
let parent = Blob::init_empty(global_this);
return Ok(parent.get_slice_from(global_this, 0, 0, blob_content_type));
}
Comment thread
robobun marked this conversation as resolved.
Resolved

Ok(self.get_slice_from(global_this, relative_start, relative_end, blob_content_type))
Expand Down
Loading
Loading