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
2 changes: 1 addition & 1 deletion src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ impl Error {
};

// Combine all the parts
format!("{position_part}{source_line_part}{msg_part}",)
format!("{position_part}{source_line_part}{msg_part}")
} else {
self.to_string()
};
Expand Down
2 changes: 1 addition & 1 deletion src/ext/broadcast_channel/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ mod test {
/// This test is identical to the original test from origin/master that verified
/// JavaScript ↔ Rust bidirectional communication.
///
/// BroadcastChannelWrapper has been restored to maintain full backward compatibility
/// `BroadcastChannelWrapper` has been restored to maintain full backward compatibility
/// with origin/master behavior.
#[test]
fn test_broadcast_channel() {
Expand Down
33 changes: 17 additions & 16 deletions src/ext/broadcast_channel/wrapper.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
//!
//! ## Example
//!
//! ### JavaScript ↔ Rust (BroadcastChannelWrapper)
//! ### JavaScript ↔ Rust (`BroadcastChannelWrapper`)
//! ```rust,ignore
//! use rustyscript::{BroadcastChannelWrapper, Runtime, RuntimeOptions};
//!
Expand All @@ -35,7 +35,7 @@
//! // JavaScript BroadcastChannel('my_channel') receives this message
//! ```
//!
//! ### Rust ↔ Rust (IsolatedBroadcastChannel)
//! ### Rust ↔ Rust (`IsolatedBroadcastChannel`)
//! ```rust,ignore
//! use rustyscript::{IsolatedBroadcastChannel, Runtime, RuntimeOptions};
//!
Expand All @@ -61,7 +61,7 @@ use uuid::Uuid;

use crate::{big_json_args, Error, Runtime};

/// Message type matching deno_web's internal InMemoryChannelMessage structure
/// Message type matching `deno_web`'s internal `InMemoryChannelMessage` structure
#[derive(Clone, Debug)]
struct InMemoryChannelMessage {
name: Arc<String>,
Expand All @@ -73,7 +73,7 @@ struct InMemoryChannelMessage {
///
/// Takes care of some of the boilerplate for serialization/deserialization.
/// Messages are serialized through the JavaScript runtime to ensure compatibility
/// with the JavaScript BroadcastChannel API.
/// with the JavaScript `BroadcastChannel` API.
///
/// This wrapper shares the same underlying channel as JavaScript's `BroadcastChannel`,
/// enabling bidirectional Rust ↔ JavaScript communication.
Expand All @@ -91,7 +91,7 @@ pub struct BroadcastChannelWrapper {
impl BroadcastChannelWrapper {
/// Create a new broadcast channel wrapper and subscribe to the channel
///
/// This wrapper shares the same underlying channel as JavaScript's BroadcastChannel,
/// This wrapper shares the same underlying channel as JavaScript's `BroadcastChannel`,
/// enabling bidirectional communication.
///
/// Unsubscribe is called when the wrapper is dropped
Expand All @@ -108,8 +108,7 @@ impl BroadcastChannelWrapper {
//
// We can access the field by transmuting to the inner type:
let sender: &Arc<Mutex<broadcast::Sender<InMemoryChannelMessage>>> = unsafe {
&*(channel as *const InMemoryBroadcastChannel
as *const Arc<Mutex<broadcast::Sender<InMemoryChannelMessage>>>)
&*std::ptr::from_ref::<InMemoryBroadcastChannel>(channel).cast::<Arc<Mutex<broadcast::Sender<InMemoryChannelMessage>>>>()
};

let sender = sender.clone();
Expand Down Expand Up @@ -180,6 +179,8 @@ impl BroadcastChannelWrapper {
runtime: &mut Runtime,
timeout: Option<Duration>,
) -> Result<Option<T>, Error> {
use tokio::sync::broadcast::error::RecvError::{Closed, Lagged};

let mut guard = self.receiver.lock().await;
let (broadcast_rx, cancel_rx) = &mut *guard;

Expand All @@ -197,12 +198,11 @@ impl BroadcastChannelWrapper {
}
};

use tokio::sync::broadcast::error::RecvError::*;
match result {
Err(Closed) => return Ok(None),
Err(Lagged(_)) => continue, // Backlogged, messages dropped - try again
Ok(message) if message.uuid == self.uuid => continue, // Self-send, skip
Ok(message) if *message.name != self.name => continue, // Different channel name
Err(Lagged(_)) => {} // Backlogged, messages dropped - try again
Ok(message) if message.uuid == self.uuid => {} // Self-send, skip
Ok(message) if *message.name != self.name => {} // Different channel name
Ok(message) => {
// Deserialize through JavaScript for compatibility
let data: T = runtime
Expand Down Expand Up @@ -392,6 +392,8 @@ impl IsolatedBroadcastChannelWrapper {
runtime: &mut Runtime,
timeout: Option<Duration>,
) -> Result<Option<T>, Error> {
use tokio::sync::broadcast::error::RecvError::{Closed, Lagged};

let mut guard = self.receiver.lock().await;
let (broadcast_rx, cancel_rx) = &mut *guard;

Expand All @@ -409,12 +411,11 @@ impl IsolatedBroadcastChannelWrapper {
}
};

use tokio::sync::broadcast::error::RecvError::*;
match result {
Err(Closed) => return Ok(None),
Err(Lagged(_)) => continue, // Backlogged, messages dropped - try again
Ok(message) if message.sender_id == self.uuid => continue, // Self-send, skip
Ok(message) if *message.name != self.name => continue, // Different channel name
Err(Lagged(_)) => {} // Backlogged, messages dropped - try again
Ok(message) if message.sender_id == self.uuid => {} // Self-send, skip
Ok(message) if *message.name != self.name => {} // Different channel name
Ok(message) => {
// Deserialize through JavaScript for compatibility
let data: T = runtime
Expand Down Expand Up @@ -464,7 +465,7 @@ impl Drop for IsolatedBroadcastChannelWrapper {
#[cfg(test)]
mod test {
use super::*;
use crate::{Module, Runtime, RuntimeOptions};
use crate::{Runtime, RuntimeOptions};

#[test]
fn test_isolated_broadcast_channel_send_recv() {
Expand Down
2 changes: 1 addition & 1 deletion src/ext/io/tty_unix.rs
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ fn console_size_from_fd(fd: std::os::unix::prelude::RawFd) -> Result<ConsoleSize
// SAFETY: libc calls
unsafe {
let mut size: libc::winsize = std::mem::zeroed();
if libc::ioctl(fd, libc::TIOCGWINSZ, &mut size as *mut _) != 0 {
if libc::ioctl(fd, libc::TIOCGWINSZ, std::ptr::from_mut(&mut size)) != 0 {
return Err(Error::last_os_error());
}
Ok(ConsoleSize {
Expand Down
3 changes: 1 addition & 2 deletions src/ext/runtime/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -240,8 +240,7 @@ fn create_web_worker_callback(options: WebWorkerCallbackOptions) -> Arc<CreateWe
deno_version: env!("CARGO_PKG_VERSION").to_string(),
args: vec![],
cpu_count: std::thread::available_parallelism()
.map(std::num::NonZero::get)
.unwrap_or(1),
.map_or(1, std::num::NonZero::get),
log_level: WorkerLogLevel::default(),
enable_op_summary_metrics: false,
enable_testing_features: false,
Expand Down
3 changes: 2 additions & 1 deletion src/ext/web/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,9 @@ pub use permissions::{
WebPermissions,
};

/// Stub for a node op deno_net expects to find
/// Stub for a node op `deno_net` expects to find
/// We return None to show no cert available
#[cfg(not(feature = "node_experimental"))]
#[deno_core::op2]
#[serde]
pub fn op_tls_peer_certificate(
Expand Down
6 changes: 3 additions & 3 deletions src/ext/web/permissions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -640,10 +640,10 @@ impl_sys_permission_kinds!(
#[derive(Clone, Debug)]
pub struct PermissionsContainer(pub Arc<dyn WebPermissions>);

/// Convert WebPermissions to deno_permissions::PermissionsOptions
/// Convert `WebPermissions` to `deno_permissions::PermissionsOptions`
///
/// This function probes the WebPermissions trait methods to determine
/// what should be allowed, then converts to PermissionsOptions format.
/// This function probes the `WebPermissions` trait methods to determine
/// what should be allowed, then converts to `PermissionsOptions` format.
///
/// - For `DefaultWebPermissions` (or equivalent allow-all): returns options that allow everything
/// - For restrictive permissions (e.g., `AllowlistWebPermissions`): returns options that deny by default
Expand Down
2 changes: 1 addition & 1 deletion src/inner_runtime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ fn decode_args_to_globals(
let len = arr.length();
let mut result = Vec::with_capacity(len as usize);
for i in 0..len {
let index = v8::Integer::new(&context_scope, i as i32);
let index = v8::Integer::new(&context_scope, i.cast_signed());
if let Some(arg) = arr.get(&context_scope, index.into()) {
let isolate: &v8::Isolate = &context_scope;
result.push(v8::Global::new(isolate, arg));
Expand Down
2 changes: 1 addition & 1 deletion src/module_loader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,7 @@ mod test {
}
}

/// Test backward compatibility for ImportProvider trait
/// Test backward compatibility for `ImportProvider` trait
#[test]
fn test_import_provider_backward_compat() {
use deno_core::RequestedModuleType;
Expand Down
9 changes: 7 additions & 2 deletions src/op_whitelist.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ macro_rules! whitelist {
}

/// Get the global whitelist of ops.
#[must_use]
pub fn get_whitelist() -> &'static OpWhitelist {
&WHITELIST
}
Expand Down Expand Up @@ -243,11 +244,13 @@ whitelist!(
pub struct OpWhitelist(&'static [OpSrc]);
impl OpWhitelist {
/// Create a new list of safe ops.
#[must_use]
pub const fn new(ops: &'static [OpSrc]) -> Self {
OpWhitelist(ops)
}

/// Check if the whitelist contains a specific op.
#[must_use]
pub fn contains_op(&self, op: &str) -> bool {
self.0.iter().any(|src| src.contains_op(op))
}
Expand All @@ -274,7 +277,8 @@ pub struct OpSrc {
pub stubs: &'static [&'static str],
}
impl OpSrc {
/// Create a new OpSrc.
/// Create a new `OpSrc`.
#[must_use]
pub const fn new(
src: &'static str,
ops: &'static [&'static str],
Expand All @@ -283,7 +287,8 @@ impl OpSrc {
OpSrc { src, ops, stubs }
}

/// Check if the OpSrc contains a specific op.
/// Check if the `OpSrc` contains a specific op.
#[must_use]
pub fn contains_op(&self, op: &str) -> bool {
self.ops.contains(&op) || self.stubs.contains(&op)
}
Expand Down
4 changes: 1 addition & 3 deletions src/traits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,9 +75,7 @@ impl ToV8String for str {
// This is safe because the HandleScope is already on the stack and pinned.
// This pattern is used throughout the codebase for V8 API compatibility.
let scope_ref: &v8::PinnedRef<HandleScope<'a>> = unsafe {
std::mem::transmute::<&HandleScope<'a>, &v8::PinnedRef<HandleScope<'a>>>(
std::ptr::from_mut(scope).as_ref().unwrap(),
)
&*std::ptr::from_mut(scope).cast::<v8::PinnedRef<HandleScope<'a>>>()
};
v8::String::new(scope_ref, self).ok_or_else(|| Error::V8Encoding(self.to_string()))
}
Expand Down