Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
address pr notes
  • Loading branch information
bdemann committed Apr 19, 2023
commit 5b89a3f5ffa2c85e2a16460227d0415fa31d29ca
22 changes: 9 additions & 13 deletions vm/src/stdlib/time.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,21 +89,17 @@ mod time {
Ok(duration_since_system_now(vm)?.as_secs_f64())
}

#[cfg(all(target_arch = "wasm32", not(target_os = "wasi")))]
#[cfg(all(target_arch = "wasm32", not(target_os = "wasi"), feature = "wasmbind"))]
fn _time(_vm: &VirtualMachine) -> PyResult<f64> {
#[cfg(feature = "wasmbind")]
{
use wasm_bindgen::prelude::*;
#[wasm_bindgen]
extern "C" {
type Date;
#[wasm_bindgen(static_method_of = Date)]
fn now() -> f64;
}
// Date.now returns unix time in milliseconds, we want it in seconds
return Ok(Date::now() / 1000.0);
use wasm_bindgen::prelude::*;
#[wasm_bindgen]
extern "C" {
type Date;
#[wasm_bindgen(static_method_of = Date)]
fn now() -> f64;
}
panic!("Date not available")
// Date.now returns unix time in milliseconds, we want it in seconds
return Ok(Date::now() / 1000.0);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
return Ok(Date::now() / 1000.0);
Ok(Date::now() / 1000.0)

}

#[pyfunction]
Expand Down
21 changes: 9 additions & 12 deletions vm/src/vm/vm_object.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,20 +24,17 @@ impl VirtualMachine {
};
panic!("{msg}; {after}")
}
#[cfg(all(target_arch = "wasm32", not(target_os = "wasi")))]
#[cfg(all(target_arch = "wasm32", not(target_os = "wasi"), feature = "wasmbind"))]
{
#[cfg(feature = "wasmbind")]
{
use wasm_bindgen::prelude::*;
#[wasm_bindgen]
extern "C" {
#[wasm_bindgen(js_namespace = console)]
fn error(s: &str);
}
let mut s = String::new();
self.write_exception(&mut s, &exc).unwrap();
error(&s);
use wasm_bindgen::prelude::*;
#[wasm_bindgen]
extern "C" {
#[wasm_bindgen(js_namespace = console)]
fn error(s: &str);
}
let mut s = String::new();
self.write_exception(&mut s, &exc).unwrap();
error(&s);
panic!("{}; exception backtrace above", msg)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will fail to compile if the wasmbind feature is not enabled.

}
}
Expand Down