2023-01-02 16:00:42 -05:00
|
|
|
// Copyright 2018-2023 the Deno authors. All rights reserved. MIT license.
|
2022-07-04 18:12:41 -04:00
|
|
|
use deno_core::Snapshot;
|
|
|
|
use log::debug;
|
|
|
|
use once_cell::sync::Lazy;
|
|
|
|
|
2022-11-21 08:36:26 -05:00
|
|
|
pub static RUNTIME_SNAPSHOT: Lazy<Box<[u8]>> = Lazy::new(
|
2022-07-04 18:12:41 -04:00
|
|
|
#[allow(clippy::uninit_vec)]
|
|
|
|
#[cold]
|
|
|
|
#[inline(never)]
|
|
|
|
|| {
|
2022-11-21 08:36:26 -05:00
|
|
|
static COMPRESSED_RUNTIME_SNAPSHOT: &[u8] =
|
|
|
|
include_bytes!(concat!(env!("OUT_DIR"), "/RUNTIME_SNAPSHOT.bin"));
|
2022-07-04 18:12:41 -04:00
|
|
|
|
|
|
|
let size =
|
2022-11-21 08:36:26 -05:00
|
|
|
u32::from_le_bytes(COMPRESSED_RUNTIME_SNAPSHOT[0..4].try_into().unwrap())
|
2022-07-04 18:12:41 -04:00
|
|
|
as usize;
|
|
|
|
let mut vec = Vec::with_capacity(size);
|
|
|
|
|
|
|
|
// SAFETY: vec is allocated with exact snapshot size (+ alignment)
|
|
|
|
// SAFETY: non zeroed bytes are overwritten with decompressed snapshot
|
|
|
|
unsafe {
|
|
|
|
vec.set_len(size);
|
|
|
|
}
|
|
|
|
|
2022-11-21 08:36:26 -05:00
|
|
|
lzzzz::lz4::decompress(&COMPRESSED_RUNTIME_SNAPSHOT[4..], &mut vec)
|
|
|
|
.unwrap();
|
2022-07-04 18:12:41 -04:00
|
|
|
|
|
|
|
vec.into_boxed_slice()
|
|
|
|
},
|
|
|
|
);
|
|
|
|
|
|
|
|
pub fn deno_isolate_init() -> Snapshot {
|
|
|
|
debug!("Deno isolate init with snapshots.");
|
2022-11-21 08:36:26 -05:00
|
|
|
Snapshot::Static(&RUNTIME_SNAPSHOT)
|
2022-07-04 18:12:41 -04:00
|
|
|
}
|
|
|
|
|
2023-02-08 16:40:18 -05:00
|
|
|
#[cfg(feature = "snapshot_from_snapshot")]
|
|
|
|
pub static SOURCE_CODE_FOR_99_MAIN_JS: &str = include_str!("js/99_main.js");
|