mirror of
https://github.com/denoland/rusty_v8.git
synced 2024-11-24 15:19:31 -05:00
SnapshotCreator changes for libdeno (#176)
This commit is contained in:
parent
dbeeace93c
commit
19398816ab
5 changed files with 55 additions and 17 deletions
|
@ -1,19 +1,28 @@
|
|||
// Copyright 2019-2020 the Deno authors. All rights reserved. MIT license.
|
||||
use crate::function::FunctionCallback;
|
||||
use crate::support::intptr_t;
|
||||
use std::ffi::c_void;
|
||||
use crate::AccessorNameGetterCallback;
|
||||
use crate::FunctionCallback;
|
||||
use crate::MessageCallback;
|
||||
|
||||
#[derive(Clone, Copy)]
|
||||
pub union ExternalReference {
|
||||
pub function: FunctionCallback,
|
||||
pub getter: AccessorNameGetterCallback,
|
||||
pub message: MessageCallback,
|
||||
}
|
||||
|
||||
pub struct ExternalReferences {
|
||||
null_terminated: Vec<*const libc::c_void>,
|
||||
null_terminated: Vec<*const std::ffi::c_void>,
|
||||
}
|
||||
|
||||
unsafe impl Sync for ExternalReferences {}
|
||||
|
||||
impl ExternalReferences {
|
||||
pub fn new(refs: &[FunctionCallback]) -> Self {
|
||||
pub fn new(refs: &[ExternalReference]) -> Self {
|
||||
let mut null_terminated = Vec::with_capacity(refs.len() + 1);
|
||||
for r in refs {
|
||||
null_terminated.push(*r as *const c_void);
|
||||
let ptr = unsafe { std::mem::transmute(*r) };
|
||||
null_terminated.push(ptr);
|
||||
}
|
||||
null_terminated.push(std::ptr::null());
|
||||
Self { null_terminated }
|
||||
|
|
|
@ -138,8 +138,7 @@ impl Isolate {
|
|||
pub fn new(params: UniqueRef<CreateParams>) -> OwnedIsolate {
|
||||
// TODO: support CreateParams.
|
||||
crate::V8::assert_initialized();
|
||||
let isolate_ptr = unsafe { v8__Isolate__New(params.into_raw()) };
|
||||
OwnedIsolate(NonNull::new(isolate_ptr).unwrap())
|
||||
unsafe { new_owned_isolate(v8__Isolate__New(params.into_raw())) }
|
||||
}
|
||||
|
||||
/// Initial configuration parameters for a new Isolate.
|
||||
|
@ -310,6 +309,11 @@ impl Isolate {
|
|||
}
|
||||
}
|
||||
|
||||
/// Internal method for constructing an OwnedIsolate.
|
||||
pub unsafe fn new_owned_isolate(isolate_ptr: *mut Isolate) -> OwnedIsolate {
|
||||
OwnedIsolate(NonNull::new(isolate_ptr).unwrap())
|
||||
}
|
||||
|
||||
/// Same as Isolate but gets disposed when it goes out of scope.
|
||||
pub struct OwnedIsolate(NonNull<Isolate>);
|
||||
|
||||
|
|
19
src/lib.rs
19
src/lib.rs
|
@ -86,11 +86,21 @@ pub use callback_scope::CallbackScope;
|
|||
pub use context::Context;
|
||||
pub use data::*;
|
||||
pub use exception::*;
|
||||
pub use external_references::ExternalReference;
|
||||
pub use external_references::ExternalReferences;
|
||||
pub use function::{FunctionCallbackInfo, ReturnValue};
|
||||
pub use function::FunctionCallback;
|
||||
pub use function::FunctionCallbackInfo;
|
||||
pub use function::ReturnValue;
|
||||
pub use global::Global;
|
||||
pub use handle_scope::{EscapableHandleScope, HandleScope, ToLocal};
|
||||
pub use isolate::*;
|
||||
pub use isolate::CreateParams;
|
||||
pub use isolate::HostImportModuleDynamicallyCallback;
|
||||
pub use isolate::HostInitializeImportMetaObjectCallback;
|
||||
pub use isolate::InIsolate;
|
||||
pub use isolate::Isolate;
|
||||
pub use isolate::MessageCallback;
|
||||
pub use isolate::OwnedIsolate;
|
||||
pub use isolate::PromiseRejectCallback;
|
||||
pub use local::Local;
|
||||
pub use locker::Locker;
|
||||
pub use module::*;
|
||||
|
@ -101,7 +111,10 @@ pub use promise::{PromiseRejectEvent, PromiseRejectMessage, PromiseState};
|
|||
pub use property::PropertyCallbackInfo;
|
||||
pub use script::{Script, ScriptOrigin};
|
||||
pub use script_or_module::ScriptOrModule;
|
||||
pub use snapshot::{FunctionCodeHandling, SnapshotCreator, StartupData};
|
||||
pub use snapshot::FunctionCodeHandling;
|
||||
pub use snapshot::OwnedStartupData;
|
||||
pub use snapshot::SnapshotCreator;
|
||||
pub use snapshot::StartupData;
|
||||
pub use string::NewStringType;
|
||||
pub use support::MaybeBool;
|
||||
pub use support::SharedRef;
|
||||
|
|
|
@ -1,15 +1,15 @@
|
|||
use std::borrow::Borrow;
|
||||
use std::marker::PhantomData;
|
||||
use std::mem::MaybeUninit;
|
||||
use std::ops::Deref;
|
||||
use std::ops::DerefMut;
|
||||
|
||||
use crate::external_references::ExternalReferences;
|
||||
use crate::support::int;
|
||||
use crate::support::intptr_t;
|
||||
use crate::Context;
|
||||
use crate::Isolate;
|
||||
use crate::Local;
|
||||
use crate::OwnedIsolate;
|
||||
use std::borrow::Borrow;
|
||||
use std::marker::PhantomData;
|
||||
use std::mem::MaybeUninit;
|
||||
use std::ops::Deref;
|
||||
use std::ops::DerefMut;
|
||||
|
||||
extern "C" {
|
||||
fn v8__SnapshotCreator__CONSTRUCT(
|
||||
|
@ -142,6 +142,16 @@ impl SnapshotCreator {
|
|||
}
|
||||
}
|
||||
|
||||
/// This is marked unsafe because it should be called at most once per snapshot
|
||||
/// creator.
|
||||
// TODO Because the SnapshotCreator creates its own isolate, we need a way to
|
||||
// get an owned handle to it. This is a questionable design which ought to be
|
||||
// revisited after the libdeno integration is complete.
|
||||
pub unsafe fn get_owned_isolate(&mut self) -> OwnedIsolate {
|
||||
let isolate_ptr = v8__SnapshotCreator__GetIsolate(self);
|
||||
crate::isolate::new_owned_isolate(isolate_ptr)
|
||||
}
|
||||
|
||||
/// Returns the isolate prepared by the snapshot creator.
|
||||
pub fn get_isolate(&mut self) -> &Isolate {
|
||||
unsafe { v8__SnapshotCreator__GetIsolate(self) }
|
||||
|
|
|
@ -1550,7 +1550,9 @@ fn snapshot_creator() {
|
|||
|
||||
lazy_static! {
|
||||
static ref EXTERNAL_REFERENCES: v8::ExternalReferences =
|
||||
v8::ExternalReferences::new(&[fn_callback]);
|
||||
v8::ExternalReferences::new(&[v8::ExternalReference {
|
||||
function: fn_callback
|
||||
}]);
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
|
Loading…
Reference in a new issue