2024-01-01 14:58:21 -05:00
|
|
|
// Copyright 2018-2024 the Deno authors. All rights reserved. MIT license.
|
2023-01-13 02:51:32 -05:00
|
|
|
|
2022-11-21 08:36:26 -05:00
|
|
|
use deno_core::Snapshot;
|
2023-03-08 10:44:04 -05:00
|
|
|
use log::debug;
|
2022-11-21 08:36:26 -05:00
|
|
|
|
2023-08-05 19:47:15 -04:00
|
|
|
#[cfg(not(feature = "__runtime_js_sources"))]
|
2023-03-16 23:19:46 -04:00
|
|
|
static CLI_SNAPSHOT: &[u8] =
|
|
|
|
include_bytes!(concat!(env!("OUT_DIR"), "/CLI_SNAPSHOT.bin"));
|
2022-11-21 08:36:26 -05:00
|
|
|
|
2023-08-05 19:47:15 -04:00
|
|
|
pub fn deno_isolate_init() -> Option<Snapshot> {
|
2023-03-08 10:44:04 -05:00
|
|
|
debug!("Deno isolate init with snapshots.");
|
2023-08-05 19:47:15 -04:00
|
|
|
#[cfg(not(feature = "__runtime_js_sources"))]
|
|
|
|
{
|
|
|
|
Some(Snapshot::Static(CLI_SNAPSHOT))
|
|
|
|
}
|
|
|
|
#[cfg(feature = "__runtime_js_sources")]
|
|
|
|
{
|
|
|
|
None
|
|
|
|
}
|
2022-11-21 08:36:26 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
#[cfg(test)]
|
|
|
|
mod tests {
|
|
|
|
use super::*;
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn runtime_snapshot() {
|
|
|
|
let mut js_runtime = deno_core::JsRuntime::new(deno_core::RuntimeOptions {
|
2023-08-05 19:47:15 -04:00
|
|
|
startup_snapshot: deno_isolate_init(),
|
2022-11-21 08:36:26 -05:00
|
|
|
..Default::default()
|
|
|
|
});
|
|
|
|
js_runtime
|
2023-04-04 08:46:31 -04:00
|
|
|
.execute_script_static(
|
2022-11-21 08:36:26 -05:00
|
|
|
"<anon>",
|
|
|
|
r#"
|
|
|
|
if (!(bootstrap.mainRuntime && bootstrap.workerRuntime)) {
|
|
|
|
throw Error("bad");
|
|
|
|
}
|
|
|
|
"#,
|
|
|
|
)
|
|
|
|
.unwrap();
|
|
|
|
}
|
|
|
|
}
|