Skip to content

Commit

Permalink
Fix worker clips
Browse files Browse the repository at this point in the history
  • Loading branch information
rscarson committed Jul 11, 2024
1 parent 364952a commit 7253223
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/js_value/map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ impl Map {
let value = local.get(scope, key.into())?;

let value = v8::Global::new(scope, value);
Some(crate::js_value::Value::from_v8(value).ok()?)
crate::js_value::Value::from_v8(value).ok()
}

pub(crate) fn get_string_keys(&self, scope: &mut HandleScope) -> Vec<String> {
Expand Down
6 changes: 2 additions & 4 deletions src/js_value/string.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,7 @@ impl String {
pub(crate) fn to_utf16_buffer(&self, scope: &mut HandleScope<'_>) -> Vec<u16> {
let local = self.0.as_local(scope);
let u16_len = local.length();
let mut buffer = Vec::with_capacity(u16_len);
buffer.resize(u16_len, 0);
let mut buffer = vec![0; u16_len];

local.write(scope, &mut buffer, 0, WriteOptions::NO_NULL_TERMINATION);
buffer
Expand All @@ -52,8 +51,7 @@ impl String {
pub(crate) fn to_utf8_buffer(&self, scope: &mut HandleScope<'_>) -> Vec<u8> {
let local = self.0.as_local(scope);
let u8_len = local.utf8_length(scope);
let mut buffer = Vec::with_capacity(u8_len);
buffer.resize(u8_len, 0);
let mut buffer = vec![0; u8_len];

local.write_utf8(scope, &mut buffer, None, WriteOptions::NO_NULL_TERMINATION);
buffer
Expand Down
8 changes: 8 additions & 0 deletions src/worker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,14 @@ where
self.workers.len()
}

/// Check if the pool is empty
/// This will be true if the pool has no workers
/// This can happen if the pool was created with 0 workers
/// Which is not particularly useful, but is allowed
pub fn is_empty(&self) -> bool {
self.workers.is_empty()
}

/// Get a worker by its index in the pool
pub fn worker_by_id(&self, id: usize) -> Option<Rc<RefCell<Worker<W>>>> {
Some(Rc::clone(self.workers.get(id)?))
Expand Down

0 comments on commit 7253223

Please sign in to comment.