Skip to content

Commit

Permalink
improve StartupData lifetimes
Browse files Browse the repository at this point in the history
  • Loading branch information
ry committed Apr 4, 2019
1 parent fe05d8d commit 9a92f86
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 13 deletions.
8 changes: 4 additions & 4 deletions cli/startup_data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ pub fn deno_isolate_init() -> StartupData<'static> {
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.");
Expand All @@ -38,8 +38,8 @@ pub fn compiler_isolate_init() -> StartupData<'static> {
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.");
Expand Down
4 changes: 2 additions & 2 deletions core/http_bench.rs
Original file line number Diff line number Diff line change
Expand Up @@ -163,8 +163,8 @@ fn main() {
let js_source = include_str!("http_bench.js");

let startup_data = StartupData::Script(Script {
source: js_source.to_string(),
filename: "http_bench.js".to_string(),
source: js_source,
filename: "http_bench.js",
});

let isolate = deno::Isolate::new(startup_data, HttpBench());
Expand Down
12 changes: 5 additions & 7 deletions core/isolate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,16 +51,16 @@ impl Future for PendingOp {
}

/// Stores a script used to initalize a Isolate
pub struct Script {
pub source: String,
pub filename: String,
pub struct Script<'a> {
pub source: &'a str,
pub filename: &'a str,
}

/// Represents data used to initialize isolate at startup
/// either a binary snapshot or a javascript source file
/// in the form of the StartupScript struct.
pub enum StartupData<'a> {
Script(Script),
Script(Script<'a>),
Snapshot(&'a [u8]),
None,
}
Expand Down Expand Up @@ -149,9 +149,7 @@ impl<B: Behavior> Isolate<B> {

// If we want to use execute this has to happen here sadly.
if let Some(s) = startup_script {
core_isolate
.execute(s.filename.as_str(), s.source.as_str())
.unwrap()
core_isolate.execute(s.filename, s.source).unwrap()
};

core_isolate
Expand Down

0 comments on commit 9a92f86

Please sign in to comment.