From f6b617784f53497b0c59d6f6f1370cb2223e38f3 Mon Sep 17 00:00:00 2001 From: Marcus Weiner Date: Sun, 10 May 2020 03:00:40 +0200 Subject: [PATCH] Allow starting isolate from snapshot bytes on the heap (#5187) --- core/isolate.rs | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/core/isolate.rs b/core/isolate.rs index 37a9de2ad8..e3db18663b 100644 --- a/core/isolate.rs +++ b/core/isolate.rs @@ -125,6 +125,7 @@ impl From> for OwnedScript { pub enum Snapshot { Static(&'static [u8]), JustCreated(v8::StartupData), + Boxed(Box<[u8]>), } /// Represents data used to initialize isolate at startup @@ -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 { @@ -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