Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
// Copyright 2018-2021 the Deno authors. All rights reserved. MIT license.
use deno_core::{JsRuntime, RuntimeOptions, Snapshot};
fn main() {
// create snapshot
let mut runtime = JsRuntime::new(RuntimeOptions {
will_snapshot: true,
..Default::default()
});
runtime.execute("<init>", "globalThis.x = 1").unwrap();
let snapshot = runtime.snapshot();
let snapshot_slice: &[u8] = &*snapshot;
println!("Snapshot size: {} bytes", snapshot_slice.len());
// restore from snapshot
let mut restored = JsRuntime::new(RuntimeOptions {
startup_snapshot: Some(Snapshot::JustCreated(snapshot)),
..Default::default()
});
restored
.execute(
"<usage>",
r#"
function print(value) {
Deno.core.print(value.toString()+"\n");
}
print(globalThis.x);
"#,
)
.unwrap();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment