summaryrefslogtreecommitdiff
path: root/cli/startup_data.rs
diff options
context:
space:
mode:
authorRyan Dahl <ry@tinyclouds.org>2019-04-08 10:12:43 -0400
committerGitHub <noreply@github.com>2019-04-08 10:12:43 -0400
commitf7fdb90fd51e340ea598c055bb3573d3cdfbdaa8 (patch)
tree40db117b3a9fd2ac70e3b5551195e21eef464138 /cli/startup_data.rs
parentcdb72afd8d91978573f0fa897844aee853983b44 (diff)
core: snapshot improvements (#2052)
* 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.
Diffstat (limited to 'cli/startup_data.rs')
-rw-r--r--cli/startup_data.rs21
1 files changed, 8 insertions, 13 deletions
diff --git a/cli/startup_data.rs b/cli/startup_data.rs
index 61891ced4..1a77915e9 100644
--- a/cli/startup_data.rs
+++ b/cli/startup_data.rs
@@ -1,8 +1,7 @@
// Copyright 2018-2019 the Deno authors. All rights reserved. MIT license.
-use deno::deno_buf;
use deno::{Script, StartupData};
-pub fn deno_isolate_init() -> 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"))]
@@ -12,8 +11,8 @@ pub fn deno_isolate_init() -> StartupData {
let source_bytes = vec![];
StartupData::Script(Script {
- filename: "gen/cli/bundle/main.js".to_string(),
- source: std::str::from_utf8(&source_bytes[..]).unwrap().to_string(),
+ filename: "gen/cli/bundle/main.js",
+ source: std::str::from_utf8(&source_bytes[..]).unwrap(),
})
} else {
debug!("Deno isolate init with snapshots.");
@@ -23,13 +22,11 @@ pub fn deno_isolate_init() -> StartupData {
#[cfg(any(feature = "check-only", feature = "no-snapshot-init"))]
let data = vec![];
- unsafe {
- StartupData::Snapshot(deno_buf::from_raw_parts(data.as_ptr(), data.len()))
- }
+ StartupData::Snapshot(data)
}
}
-pub fn compiler_isolate_init() -> StartupData {
+pub fn compiler_isolate_init() -> StartupData<'static> {
if cfg!(feature = "no-snapshot-init") {
debug!("Compiler isolate init without snapshots.");
#[cfg(not(feature = "check-only"))]
@@ -41,8 +38,8 @@ pub fn compiler_isolate_init() -> StartupData {
let source_bytes = vec![];
StartupData::Script(Script {
- filename: "gen/cli/bundle/compiler.js".to_string(),
- source: std::str::from_utf8(&source_bytes[..]).unwrap().to_string(),
+ filename: "gen/cli/bundle/compiler.js",
+ source: std::str::from_utf8(&source_bytes[..]).unwrap(),
})
} else {
debug!("Deno isolate init with snapshots.");
@@ -54,8 +51,6 @@ pub fn compiler_isolate_init() -> StartupData {
#[cfg(any(feature = "check-only", feature = "no-snapshot-init"))]
let data = vec![];
- unsafe {
- StartupData::Snapshot(deno_buf::from_raw_parts(data.as_ptr(), data.len()))
- }
+ StartupData::Snapshot(data)
}
}