diff options
author | Bartek IwaĆczuk <biwanczuk@gmail.com> | 2022-07-05 00:12:41 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-07-05 00:12:41 +0200 |
commit | a919a5dd1167b79f267cbed7312b3a7d296d429f (patch) | |
tree | 73b7b1a8b5daef3ab7ad9c07423c4907a23a0269 /snapshots/lib.rs | |
parent | 06934db883e9ae64c7603f98051676cbcf90994f (diff) |
Revert "refactor(snapshots): to their own crate (#14794)" (#15076)
This reverts commit fd5a12d7e25dc53238e2bbcffe970e646c1035f3.
Diffstat (limited to 'snapshots/lib.rs')
-rw-r--r-- | snapshots/lib.rs | 77 |
1 files changed, 0 insertions, 77 deletions
diff --git a/snapshots/lib.rs b/snapshots/lib.rs deleted file mode 100644 index 1d0b3ceb3..000000000 --- a/snapshots/lib.rs +++ /dev/null @@ -1,77 +0,0 @@ -use deno_core::Snapshot; -use once_cell::sync::Lazy; -use std::convert::TryInto; - -pub fn tsc_snapshot() -> Snapshot { - Snapshot::Static(&*COMPILER_SNAPSHOT) -} - -static COMPILER_SNAPSHOT: Lazy<Box<[u8]>> = Lazy::new( - #[cold] - #[inline(never)] - || { - static COMPRESSED_COMPILER_SNAPSHOT: &[u8] = - include_bytes!(concat!(env!("OUT_DIR"), "/COMPILER_SNAPSHOT.bin")); - - zstd::bulk::decompress( - &COMPRESSED_COMPILER_SNAPSHOT[4..], - u32::from_le_bytes(COMPRESSED_COMPILER_SNAPSHOT[0..4].try_into().unwrap()) - as usize, - ) - .unwrap() - .into_boxed_slice() - }, -); - -pub fn cli_snapshot() -> Snapshot { - Snapshot::Static(&*CLI_SNAPSHOT) -} - -static CLI_SNAPSHOT: Lazy<Box<[u8]>> = Lazy::new( - #[allow(clippy::uninit_vec)] - #[cold] - #[inline(never)] - || { - static COMPRESSED_CLI_SNAPSHOT: &[u8] = - include_bytes!(concat!(env!("OUT_DIR"), "/CLI_SNAPSHOT.bin")); - - let size = - u32::from_le_bytes(COMPRESSED_CLI_SNAPSHOT[0..4].try_into().unwrap()) - 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); - } - - lzzzz::lz4::decompress(&COMPRESSED_CLI_SNAPSHOT[4..], &mut vec).unwrap(); - - vec.into_boxed_slice() - }, -); - -#[cfg(test)] -mod tests { - use deno_runtime::deno_core; - - #[test] - fn cli_snapshot() { - let mut js_runtime = deno_core::JsRuntime::new(deno_core::RuntimeOptions { - startup_snapshot: Some(crate::cli_snapshot()), - ..Default::default() - }); - js_runtime - .execute_script( - "<anon>", - r#" - if (!(bootstrap.mainRuntime && bootstrap.workerRuntime)) { - throw Error("bad"); - } - console.log("we have console.log!!!"); - "#, - ) - .unwrap(); - } -} |