Skip to content

Commit

Permalink
Allow starting isolate from snapshot bytes on the heap (#5187)
Browse files Browse the repository at this point in the history
  • Loading branch information
mraerino committed May 10, 2020
1 parent d8f5b37 commit f6b6177
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions core/isolate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ impl From<Script<'_>> for OwnedScript {
pub enum Snapshot {
Static(&'static [u8]),
JustCreated(v8::StartupData),
Boxed(Box<[u8]>),
}

/// Represents data used to initialize isolate at startup
Expand Down Expand Up @@ -250,6 +251,7 @@ impl CoreIsolate {
params = match snapshot {
Snapshot::Static(data) => params.snapshot_blob(data),
Snapshot::JustCreated(data) => params.snapshot_blob(data),
Snapshot::Boxed(data) => params.snapshot_blob(data),
};
true
} else {
Expand Down Expand Up @@ -1175,6 +1177,20 @@ pub mod tests {
let mut isolate2 = CoreIsolate::new(startup_data, false);
js_check(isolate2.execute("check.js", "if (a != 3) throw Error('x')"));
}

#[test]
fn test_from_boxed_snapshot() {
let snapshot = {
let mut isolate = CoreIsolate::new(StartupData::None, true);
js_check(isolate.execute("a.js", "a = 1 + 2"));
let snap: &[u8] = &*isolate.snapshot();
Vec::from(snap).into_boxed_slice()
};

let startup_data = StartupData::Snapshot(Snapshot::Boxed(snapshot));
let mut isolate2 = CoreIsolate::new(startup_data, false);
js_check(isolate2.execute("check.js", "if (a != 3) throw Error('x')"));
}
}

// TODO(piscisaureus): rusty_v8 should implement the Error trait on
Expand Down

0 comments on commit f6b6177

Please sign in to comment.