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
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions crates/monty/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,13 @@ itertools = "0.14.0"
jiter = { version = "0.15.0", features = ["num-bigint"] }
monty-macros = { workspace = true }

# `std::time::Instant` panics on `wasm32-unknown-unknown`, so the resource
# tracker uses `web_time::Instant` (a `performance.now()`-backed drop-in) there
# to keep `max_duration` working when `monty` is embedded directly in a browser
# wasm module. Only that target needs it; every other target uses std directly.
[target.'cfg(all(target_arch = "wasm32", target_os = "unknown"))'.dependencies]
web-time = "1.1"

[features]
# ref-count-return changes behavior to return information on reference counts to check they're correct
# should be used for testing only
Expand Down
17 changes: 11 additions & 6 deletions crates/monty/src/resource.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
use std::{
cell::Cell,
error::Error,
fmt,
time::{Duration, Instant},
};
#[cfg(not(all(target_arch = "wasm32", target_os = "unknown")))]
use std::time::Instant;
use std::{cell::Cell, error::Error, fmt, time::Duration};

// `std::time::Instant::now()` panics ("time not implemented on this platform")
// on `wasm32-unknown-unknown`, so any `max_duration` limit aborts there. Swap in
// `web_time::Instant` (a `performance.now()`-backed drop-in) only for that
// target; every other target (native, WASI) keeps std, so the `web-time`
// dependency is pulled in only where it's needed (see Cargo.toml).
#[cfg(all(target_arch = "wasm32", target_os = "unknown"))]
use web_time::Instant;

use crate::{
ExcType, MontyException,
Expand Down
Loading