Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
andrieshiemstra committed Jan 5, 2024
1 parent e384b33 commit 4a5936d
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 11 deletions.
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ hirofa_utils = "0.7"
backtrace = "0.3.67"

libquickjs-sys = {package="hirofa-quickjs-sys", git='https://github.com/HiRoFa/quickjs-sys', features=["bellard"]}
#libquickjs-sys = {package="hirofa-quickjs-sys", path='../quickjs-sys', features=["bellard"]}
lazy_static = "1.4.0"
log = "0.4"
num_cpus = "1"
Expand Down
1 change: 1 addition & 0 deletions src/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ pub struct QuickJsRuntimeBuilder {
impl QuickJsRuntimeBuilder {
/// build an EsRuntime
pub fn build(self) -> QuickJsRuntimeFacade {
log::debug!("QuickJsRuntimeBuilder.build");
QuickJsRuntimeFacade::new(self)
}

Expand Down
11 changes: 6 additions & 5 deletions src/features/console.rs
Original file line number Diff line number Diff line change
Expand Up @@ -330,12 +330,12 @@ pub mod tests {
use crate::jsutils::Script;
use std::thread;
use std::time::Duration;
use swc_timer::tracing;


#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
pub async fn test_console() {
eprintln!("> test_console");

/*
let loglevel = log::LevelFilter::Info;
tracing_log::LogTracer::builder()
Expand Down Expand Up @@ -363,11 +363,12 @@ pub mod tests {
//
});
println!("< init");

// Send log using a macro defined in the create log
log::error!("Logger initialized");
tracing::error!("via tracing");
*/
// Send log using a macro defined in the create log


log::info!("> test_console");
let rt = QuickJsRuntimeBuilder::new().build();
Expand All @@ -387,6 +388,6 @@ pub mod tests {
.expect("test_console.es failed");
log::info!("< test_console");

thread::sleep(Duration::from_secs(15));
thread::sleep(Duration::from_secs(1));
}
}
3 changes: 3 additions & 0 deletions src/quickjs_utils/json.rs
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,9 @@ pub mod tests {
#[test]
fn test_json() {
let rt = init_test_rt();

log::info!("Starting json test");

rt.exe_rt_task_in_event_loop(|q_js_rt| {
let q_ctx = q_js_rt.get_main_realm();

Expand Down
12 changes: 6 additions & 6 deletions src/quickjs_utils/typedarrays.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ pub unsafe fn new_array_buffer(
buf: Vec<u8>,
) -> Result<QuickJsValueAdapter, JsError> {
#[cfg(target_pointer_width = "64")]
let length = buf.len() as u64;
let length = buf.len();
#[cfg(target_pointer_width = "32")]
let length = buf.len() as u32;

Expand Down Expand Up @@ -157,7 +157,7 @@ pub unsafe fn new_array_buffer_copy(
buf: &[u8],
) -> Result<QuickJsValueAdapter, JsError> {
#[cfg(target_pointer_width = "64")]
let length = buf.len() as u64;
let length = buf.len();
#[cfg(target_pointer_width = "32")]
let length = buf.len() as u32;

Expand Down Expand Up @@ -208,13 +208,13 @@ pub unsafe fn detach_array_buffer_buffer(
})
} else {
#[cfg(target_pointer_width = "64")]
let mut len: u64 = 0;
let mut len:usize = 0;
#[cfg(target_pointer_width = "32")]
let mut len: u32 = 0;

let ptr = q::JS_GetArrayBuffer(ctx, &mut len, *array_buffer.borrow_value());

Vec::from_raw_parts(ptr, len as usize, len as usize)
Vec::from_raw_parts(ptr, len as usize, len as _)

Check failure on line 217 in src/quickjs_utils/typedarrays.rs

View workflow job for this annotation

GitHub Actions / clippy

casting to the same type is unnecessary (`usize` -> `usize`)

error: casting to the same type is unnecessary (`usize` -> `usize`) --> src/quickjs_utils/typedarrays.rs:217:34 | 217 | Vec::from_raw_parts(ptr, len as usize, len as _) | ^^^^^^^^^^^^ help: try: `len` | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#unnecessary_cast
};

q::JS_DetachArrayBuffer(ctx, *array_buffer.borrow_value());
Expand Down Expand Up @@ -244,13 +244,13 @@ pub unsafe fn get_array_buffer_buffer_copy(
debug_assert!(is_array_buffer(ctx, array_buffer));

#[cfg(target_pointer_width = "64")]
let mut len: u64 = 0;
let mut len: usize = 0;
#[cfg(target_pointer_width = "32")]
let mut len: u32 = 0;

let ptr = q::JS_GetArrayBuffer(ctx, &mut len, *array_buffer.borrow_value());

let slice = std::slice::from_raw_parts(ptr, len as usize);
let slice = std::slice::from_raw_parts(ptr, len as _);

Ok(slice.to_vec())
}
Expand Down

0 comments on commit 4a5936d

Please sign in to comment.