| Crates.io | jstime_core |
| lib.rs | jstime_core |
| version | 0.65.0 |
| created_at | 2020-08-26 04:07:42.620577+00 |
| updated_at | 2025-12-02 07:06:11.814198+00 |
| description | Another JS Runtime |
| homepage | |
| repository | https://github.com/jstime/jstime |
| max_upload_size | |
| id | 280848 |
| size | 7,585,013 |
The core JavaScript runtime library for jstime. This crate provides the fundamental functionality for executing JavaScript code using the V8 engine.
jstime_core is designed to be:
Add to your Cargo.toml:
[dependencies]
jstime_core = "0.64.0"
use jstime_core as jstime;
fn main() {
// Initialize V8
jstime::init(None);
// Create runtime instance
let options = jstime::Options::default();
let mut runtime = jstime::JSTime::new(options);
// Execute JavaScript
match runtime.run_script("console.log('Hello from jstime!')", "script.js") {
Ok(result) => println!("Result: {}", result),
Err(error) => eprintln!("Error: {}", error),
}
}
use jstime_core as jstime;
fn main() {
jstime::init(None);
let options = jstime::Options::default();
let mut runtime = jstime::JSTime::new(options);
// Import and execute a module
match runtime.import("./my-module.js") {
Ok(_) => println!("Module executed successfully"),
Err(error) => eprintln!("Error: {}", error),
}
}
For performance-critical code or benchmarking, enable JIT warmup to allow V8's TurboFan compiler to optimize the code:
use jstime_core as jstime;
fn main() {
jstime::init(None);
// Create runtime with 10 warmup iterations
let options = jstime::Options::default()
.with_warmup(10);
let mut runtime = jstime::JSTime::new(options);
// Script will be executed 10 times for warmup, then once for actual execution
match runtime.run_script("/* compute-intensive code */", "bench.js") {
Ok(result) => println!("Result: {}", result),
Err(error) => eprintln!("Error: {}", error),
}
}
The warmup runs execute the script multiple times before the actual execution, allowing V8's JIT compiler to profile and optimize hot code paths. This is particularly useful for:
Note: Use warmup judiciously - it adds upfront cost. Default is 0 (no warmup) for optimal startup time.
jstime_core provides these JavaScript APIs:
console.log(), console.error(), etc.setTimeout(), setInterval()performance.now()queueMicrotask()fetch(), Headers, Request, ResponseReadableStream, WritableStream, TransformStreamURL, URLSearchParamsEvent, EventTargetatob(), btoa()structuredClone()TextEncoder, TextDecodercrypto.getRandomValues(), crypto.randomUUID(), crypto.subtle.digest()node:fs/promises moduleprocess.env, process.argv, process.cwd(), process.exit()import/export with top-level awaitSee docs/README.md for overview and docs/apis/ for detailed API documentation.
core/
├── src/
│ ├── builtins/ # Built-in JavaScript APIs
│ │ ├── README.md # Built-ins documentation
│ │ ├── *_impl.rs # Rust implementations
│ │ └── *.js # JavaScript polyfills
│ ├── event_loop.rs # Event loop implementation
│ ├── isolate_state.rs # V8 isolate state management
│ ├── js_loading.rs # Script compilation
│ ├── module.rs # ES module system
│ ├── script.rs # Script execution
│ └── lib.rs # Public API
├── tests/ # Integration tests
│ ├── README.md # Testing documentation
│ ├── common/ # Test utilities
│ ├── fixtures/ # Test fixtures
│ └── test_*.rs # Test files
├── Cargo.toml # Package configuration
└── README.md # This file
# Debug build
cargo build -p jstime_core
# Release build
cargo build -p jstime_core --release
# Run all tests
cargo test -p jstime_core
# Run with output
cargo test -p jstime_core -- --nocapture
Licensed under the Apache License, Version 2.0. See LICENSE for details.
See CONTRIBUTING.md for guidelines.