mirror of
https://github.com/denoland/deno.git
synced 2025-03-03 09:31:22 -05:00
parent
46b1c653c0
commit
986513c080
1 changed files with 29 additions and 12 deletions
|
@ -142,11 +142,19 @@ impl Drop for JsRuntime {
|
|||
}
|
||||
}
|
||||
|
||||
#[allow(clippy::missing_safety_doc)]
|
||||
pub unsafe fn v8_init() {
|
||||
let platform = v8::new_default_platform().unwrap();
|
||||
v8::V8::initialize_platform(platform);
|
||||
fn v8_init(v8_platform: Option<v8::UniquePtr<v8::Platform>>) {
|
||||
// Include 10MB ICU data file.
|
||||
#[repr(C, align(16))]
|
||||
struct IcuData([u8; 10413584]);
|
||||
static ICU_DATA: IcuData = IcuData(*include_bytes!("icudtl.dat"));
|
||||
v8::icu::set_common_data(&ICU_DATA.0).unwrap();
|
||||
|
||||
let v8_platform = v8_platform
|
||||
.unwrap_or_else(v8::new_default_platform)
|
||||
.unwrap();
|
||||
v8::V8::initialize_platform(v8_platform);
|
||||
v8::V8::initialize();
|
||||
|
||||
let argv = vec![
|
||||
"".to_string(),
|
||||
"--wasm-test-streaming".to_string(),
|
||||
|
@ -192,20 +200,19 @@ pub struct RuntimeOptions {
|
|||
|
||||
/// Isolate creation parameters.
|
||||
pub create_params: Option<v8::CreateParams>,
|
||||
|
||||
/// V8 platform instance to use. Used when Deno initializes V8
|
||||
/// (which it only does once), otherwise it's silenty dropped.
|
||||
pub v8_platform: Option<v8::UniquePtr<v8::Platform>>,
|
||||
}
|
||||
|
||||
impl JsRuntime {
|
||||
/// Only constructor, configuration is done through `options`.
|
||||
pub fn new(mut options: RuntimeOptions) -> Self {
|
||||
let v8_platform = options.v8_platform.take();
|
||||
|
||||
static DENO_INIT: Once = Once::new();
|
||||
DENO_INIT.call_once(|| {
|
||||
// Include 10MB ICU data file.
|
||||
#[repr(C, align(16))]
|
||||
struct IcuData([u8; 10413584]);
|
||||
static ICU_DATA: IcuData = IcuData(*include_bytes!("icudtl.dat"));
|
||||
v8::icu::set_common_data(&ICU_DATA.0).unwrap();
|
||||
unsafe { v8_init() };
|
||||
});
|
||||
DENO_INIT.call_once(move || v8_init(v8_platform));
|
||||
|
||||
let has_startup_snapshot = options.startup_snapshot.is_some();
|
||||
|
||||
|
@ -2381,4 +2388,14 @@ main();
|
|||
// Test that the script specifier is a URL: `deno:<repo-relative path>`.
|
||||
assert!(error_string.contains("deno:core/core.js"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_v8_platform() {
|
||||
let options = RuntimeOptions {
|
||||
v8_platform: Some(v8::new_default_platform()),
|
||||
..Default::default()
|
||||
};
|
||||
let mut runtime = JsRuntime::new(options);
|
||||
runtime.execute("<none>", "").unwrap();
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue