0
0
Fork 0
mirror of https://github.com/denoland/rusty_v8.git synced 2024-11-21 15:04:33 -05:00

add existing_blob to SnapshotCreator constructor

This commit is contained in:
crowlkats 2022-05-18 14:58:49 +02:00 committed by Bert Belder
parent 4e08bd7917
commit f4a35fe7e5
No known key found for this signature in database
GPG key ID: 7A77887B2E2ED461
3 changed files with 40 additions and 6 deletions

View file

@ -2328,8 +2328,9 @@ bool v8__Proxy__IsRevoked(const v8::Proxy& self) {
void v8__Proxy__Revoke(const v8::Proxy& self) { ptr_to_local(&self)->Revoke(); }
void v8__SnapshotCreator__CONSTRUCT(uninit_t<v8::SnapshotCreator>* buf,
const intptr_t* external_references) {
construct_in_place<v8::SnapshotCreator>(buf, external_references);
const intptr_t* external_references,
StartupData* existing_blob) {
construct_in_place<v8::SnapshotCreator>(buf, external_references, existing_blob);
}
void v8__SnapshotCreator__DESTRUCT(v8::SnapshotCreator* self) {

View file

@ -18,6 +18,7 @@ extern "C" {
fn v8__SnapshotCreator__CONSTRUCT(
buf: *mut MaybeUninit<SnapshotCreator>,
external_references: *const intptr_t,
existing_blob: *const StartupData,
);
fn v8__SnapshotCreator__DESTRUCT(this: *mut SnapshotCreator);
fn v8__SnapshotCreator__GetIsolate(
@ -95,17 +96,23 @@ impl SnapshotCreator {
/// Create and enter an isolate, and set it up for serialization.
/// The isolate is created from scratch.
#[inline(always)]
pub fn new(external_references: Option<&'static ExternalReferences>) -> Self {
pub fn new(external_references: Option<&'static ExternalReferences>, existing_blob: Option<StartupData>) -> Self {
let mut snapshot_creator: MaybeUninit<Self> = MaybeUninit::uninit();
let external_references_ptr = if let Some(er) = external_references {
er.as_ptr()
} else {
std::ptr::null()
};
let existing_blob_ptr = if let Some(er) = existing_blob {
&er
} else {
std::ptr::null()
};
unsafe {
v8__SnapshotCreator__CONSTRUCT(
&mut snapshot_creator,
external_references_ptr,
existing_blob_ptr,
);
snapshot_creator.assume_init()
}

View file

@ -3480,7 +3480,7 @@ fn snapshot_creator() {
let context_data_index;
let context_data_index_2;
let startup_data = {
let mut snapshot_creator = v8::SnapshotCreator::new(None);
let mut snapshot_creator = v8::SnapshotCreator::new(None, None);
// TODO(ry) this shouldn't be necessary. workaround unfinished business in
// the scope type system.
let mut isolate = unsafe { snapshot_creator.get_owned_isolate() };
@ -3511,6 +3511,26 @@ fn snapshot_creator() {
.unwrap()
};
assert!(startup_data.len() > 0);
let startup_data = {
let mut snapshot_creator = v8::SnapshotCreator::new(None, Some(startup_data));
let mut isolate = unsafe { snapshot_creator.get_owned_isolate() };
{
let scope = &mut v8::HandleScope::new(&mut isolate);
let context = v8::Context::new(scope);
let scope = &mut v8::ContextScope::new(scope, context);
let source = v8::String::new(scope, "b = 2 + 3").unwrap();
let script = v8::Script::compile(scope, source, None).unwrap();
script.run(scope).unwrap();
snapshot_creator.set_default_context(context);
}
std::mem::forget(isolate); // TODO(ry) this shouldn't be necessary.
snapshot_creator
.create_blob(v8::FunctionCodeHandling::Clear)
.unwrap()
};
// Now we try to load up the snapshot and check that 'a' has the correct
// value.
{
@ -3526,6 +3546,12 @@ fn snapshot_creator() {
let true_val = v8::Boolean::new(scope, true).into();
assert!(result.same_value(true_val));
let source = v8::String::new(scope, "b === 5").unwrap();
let script = v8::Script::compile(scope, source, None).unwrap();
let result = script.run(scope).unwrap();
let true_val = v8::Boolean::new(scope, true).into();
assert!(result.same_value(true_val));
let isolate_data = scope
.get_isolate_data_from_snapshot_once::<v8::Value>(isolate_data_index);
assert!(isolate_data.unwrap() == v8::Number::new(scope, 1.0));
@ -3575,7 +3601,7 @@ fn external_references() {
// First we create the snapshot, there is a single global variable 'a' set to
// the value 3.
let startup_data = {
let mut snapshot_creator = v8::SnapshotCreator::new(Some(refs));
let mut snapshot_creator = v8::SnapshotCreator::new(Some(refs), None);
// TODO(ry) this shouldn't be necessary. workaround unfinished business in
// the scope type system.
let mut isolate = unsafe { snapshot_creator.get_owned_isolate() };
@ -4998,7 +5024,7 @@ fn module_snapshot() {
let _setup_guard = setup();
let startup_data = {
let mut snapshot_creator = v8::SnapshotCreator::new(None);
let mut snapshot_creator = v8::SnapshotCreator::new(None, None);
// TODO(ry) this shouldn't be necessary. workaround unfinished business in
// the scope type system.
let mut isolate = unsafe { snapshot_creator.get_owned_isolate() };