mirror of
https://github.com/denoland/deno.git
synced 2024-11-01 09:24:20 -04:00
f7fdb90fd5
* Moves how snapshots are supplied to the Isolate. Previously they were given by Behavior::startup_data() but it was only called once at startup. It makes more sense (and simplifies Behavior) to pass it to the constructor of Isolate. * Adds new libdeno type deno_snapshot instead of overloading deno_buf. * Adds new libdeno method to delete snapshot deno_snapshot_delete(). * Renames deno_get_snapshot() to deno_snapshot_new(). * Makes StartupData hold references to snapshots. This was implicit when it previously held a deno_buf but is made explicit now. Note that include_bytes!() returns a &'static [u8] and we want to avoid copying that.
56 lines
1.8 KiB
Rust
56 lines
1.8 KiB
Rust
// Copyright 2018-2019 the Deno authors. All rights reserved. MIT license.
|
|
use deno::{Script, StartupData};
|
|
|
|
pub fn deno_isolate_init() -> StartupData<'static> {
|
|
if cfg!(feature = "no-snapshot-init") {
|
|
debug!("Deno isolate init without snapshots.");
|
|
#[cfg(not(feature = "check-only"))]
|
|
let source_bytes =
|
|
include_bytes!(concat!(env!("GN_OUT_DIR"), "/gen/cli/bundle/main.js"));
|
|
#[cfg(feature = "check-only")]
|
|
let source_bytes = vec![];
|
|
|
|
StartupData::Script(Script {
|
|
filename: "gen/cli/bundle/main.js",
|
|
source: std::str::from_utf8(&source_bytes[..]).unwrap(),
|
|
})
|
|
} else {
|
|
debug!("Deno isolate init with snapshots.");
|
|
#[cfg(not(any(feature = "check-only", feature = "no-snapshot-init")))]
|
|
let data =
|
|
include_bytes!(concat!(env!("GN_OUT_DIR"), "/gen/cli/snapshot_deno.bin"));
|
|
#[cfg(any(feature = "check-only", feature = "no-snapshot-init"))]
|
|
let data = vec![];
|
|
|
|
StartupData::Snapshot(data)
|
|
}
|
|
}
|
|
|
|
pub fn compiler_isolate_init() -> StartupData<'static> {
|
|
if cfg!(feature = "no-snapshot-init") {
|
|
debug!("Compiler isolate init without snapshots.");
|
|
#[cfg(not(feature = "check-only"))]
|
|
let source_bytes = include_bytes!(concat!(
|
|
env!("GN_OUT_DIR"),
|
|
"/gen/cli/bundle/compiler.js"
|
|
));
|
|
#[cfg(feature = "check-only")]
|
|
let source_bytes = vec![];
|
|
|
|
StartupData::Script(Script {
|
|
filename: "gen/cli/bundle/compiler.js",
|
|
source: std::str::from_utf8(&source_bytes[..]).unwrap(),
|
|
})
|
|
} else {
|
|
debug!("Deno isolate init with snapshots.");
|
|
#[cfg(not(any(feature = "check-only", feature = "no-snapshot-init")))]
|
|
let data = include_bytes!(concat!(
|
|
env!("GN_OUT_DIR"),
|
|
"/gen/cli/snapshot_compiler.bin"
|
|
));
|
|
#[cfg(any(feature = "check-only", feature = "no-snapshot-init"))]
|
|
let data = vec![];
|
|
|
|
StartupData::Snapshot(data)
|
|
}
|
|
}
|