Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add v8::Isolate::snapshot_creator_from_existing_snapshot API #973

Merged
merged 36 commits into from
Oct 14, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
f4a35fe
add `existing_blob` to SnapshotCreator constructor
crowlKats May 18, 2022
15c9a52
fix & clean
crowlKats May 18, 2022
dc66ab1
temp
bartlomieju May 20, 2022
4196df8
update after merge
bartlomieju May 20, 2022
fbb081e
fix
crowlKats May 25, 2022
6f671c0
add from impls for startupdata
crowlKats May 25, 2022
25b6329
fmt
bartlomieju May 25, 2022
bc41fd3
SnapshotCreator::add_context
bartlomieju May 27, 2022
90cd740
v8::Context::from_snapshot()
bartlomieju May 29, 2022
558742e
add test for multiple snapshots
bartlomieju May 29, 2022
a5dfe4b
use test from Joyee
bartlomieju Jun 6, 2022
4cc07a5
add compile_and_run helper fn
bartlomieju Jun 7, 2022
a8a747a
compile_and_run is not needed because we have eval()
bartlomieju Jun 7, 2022
d8c7abd
use eval in more places
bartlomieju Jun 7, 2022
bace807
fix
bartlomieju Jun 7, 2022
66d427e
Fix all the worlds problems
piscisaureus Oct 4, 2022
57349c7
Update src/isolate_create_params.rs
crowlKats Oct 5, 2022
956097a
refactor: Change SnapshotCreator API
bartlomieju Oct 6, 2022
9816536
Merge branch 'main' into snapshotcreator_existing_blob
bartlomieju Oct 6, 2022
8a07324
fix after merge
bartlomieju Oct 6, 2022
d9fc712
temp
bartlomieju Oct 6, 2022
9493c93
make tests pass
bartlomieju Oct 13, 2022
714ea97
Merge branch 'main' into isolate_snapshot_creator
bartlomieju Oct 13, 2022
7b1b4dd
clippy?
bartlomieju Oct 13, 2022
c038ec8
clippy again?
bartlomieju Oct 13, 2022
29b2b79
rustfmt plz
bartlomieju Oct 13, 2022
b9af2a9
Merge branch 'main' into snapshotcreator_existing_blob
bartlomieju Oct 13, 2022
1dd7e48
Merge branch 'isolate_snapshot_creator' into snapshotcreator_existing…
bartlomieju Oct 13, 2022
88c3a1d
wip
bartlomieju Oct 13, 2022
8b2fc73
make private
bartlomieju Oct 13, 2022
3a65810
return OwnedIsolate from SnapshotCreator::new
bartlomieju Oct 13, 2022
4460a93
Merge branch 'isolate_snapshot_creator' into snapshotcreator_existing…
bartlomieju Oct 13, 2022
af0c6c5
forward function
bartlomieju Oct 13, 2022
20cf0c5
fix tests
bartlomieju Oct 13, 2022
a11d678
Merge branch 'main' into snapshotcreator_existing_blob
bartlomieju Oct 14, 2022
84c050a
reset CI
bartlomieju Oct 14, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
v8::Context::from_snapshot()
  • Loading branch information
bartlomieju authored and piscisaureus committed Sep 28, 2022
commit 90cd7401debe44d9938c4dca52bd2eb9384bb636
7 changes: 7 additions & 0 deletions src/binding.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1682,6 +1682,13 @@ void v8__Context__SetPromiseHooks(v8::Context& self, v8::Function& init_hook,
ptr_to_local(&after_hook), ptr_to_local(&resolve_hook));
}

const v8::Context* v8__Context__FromSnapshot(v8::Isolate* isolate,
size_t context_snapshot_index) {
v8::MaybeLocal<v8::Context> maybe_local = v8::Context::FromSnapshot(
isolate, context_snapshot_index);
return maybe_local_to_ptr(maybe_local);
}

const v8::String* v8__Message__Get(const v8::Message& self) {
return local_to_ptr(self.Get());
}
Expand Down
18 changes: 18 additions & 0 deletions src/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,10 @@ extern "C" {
index: c_int,
value: *mut c_void,
);
fn v8__Context__FromSnapshot(
isolate: *mut Isolate,
context_snapshot_index: usize,
) -> *const Context;
}

impl Context {
Expand Down Expand Up @@ -302,6 +306,20 @@ impl Context {
};
}
}

/// Create a new context from a (non-default) context snapshot. There
/// is no way to provide a global object template since we do not create
/// a new global object from template, but we can reuse a global object.
pub fn from_snapshot<'a>(
scope: &'a mut HandleScope,
context_snapshot_index: usize,
) -> Option<Local<'a, Context>> {
unsafe {
scope.cast_local(|sd| {
v8__Context__FromSnapshot(sd.get_isolate_mut(), context_snapshot_index)
})
}
}
}

struct ContextAnnex {
Expand Down