Skip to content

Commit

Permalink
Minor tweaks (denoland#2569)
Browse files Browse the repository at this point in the history
1. Separate Snapshot and Script StartupData functions based on cfg "no-snapshot-init"
2. Replace deprecated Once::ONCE_INIT with Once::new (rust-lang/rust#61757)
3. Elide lifetime
4. Fix typos
  • Loading branch information
95th authored and ry committed Jun 23, 2019
1 parent b9fbd55 commit 6fa6828
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 55 deletions.
103 changes: 54 additions & 49 deletions cli/startup_data.rs
@@ -1,56 +1,61 @@
// Copyright 2018-2019 the Deno authors. All rights reserved. MIT license.
use deno::{Script, StartupData};
#[cfg(feature = "no-snapshot-init")]
use deno::Script;

use deno::StartupData;

#[cfg(feature = "no-snapshot-init")]
pub fn deno_isolate_init() -> StartupData<'static> {
debug!("Deno isolate init without snapshots.");
#[cfg(not(feature = "check-only"))]
let source =
include_str!(concat!(env!("GN_OUT_DIR"), "/gen/cli/bundle/main.js"));
#[cfg(feature = "check-only")]
let source = "";

StartupData::Script(Script {
filename: "gen/cli/bundle/main.js",
source,
})
}

#[cfg(not(feature = "no-snapshot-init"))]
pub fn deno_isolate_init() -> StartupData<'static> {
if cfg!(feature = "no-snapshot-init") {
debug!("Deno isolate init without snapshots.");
#[cfg(not(feature = "check-only"))]
let source_bytes =
include_bytes!(concat!(env!("GN_OUT_DIR"), "/gen/cli/bundle/main.js"));
#[cfg(feature = "check-only")]
let source_bytes = b"";

StartupData::Script(Script {
filename: "gen/cli/bundle/main.js",
source: std::str::from_utf8(&source_bytes[..]).unwrap(),
})
} else {
debug!("Deno isolate init with snapshots.");
#[cfg(not(any(feature = "check-only", feature = "no-snapshot-init")))]
let data =
include_bytes!(concat!(env!("GN_OUT_DIR"), "/gen/cli/snapshot_deno.bin"));
#[cfg(any(feature = "check-only", feature = "no-snapshot-init"))]
let data = b"";

StartupData::Snapshot(data)
}
debug!("Deno isolate init with snapshots.");
#[cfg(not(feature = "check-only"))]
let data =
include_bytes!(concat!(env!("GN_OUT_DIR"), "/gen/cli/snapshot_deno.bin"));
#[cfg(feature = "check-only")]
let data = b"";

StartupData::Snapshot(data)
}

#[cfg(feature = "no-snapshot-init")]
pub fn compiler_isolate_init() -> StartupData<'static> {
if cfg!(feature = "no-snapshot-init") {
debug!("Compiler isolate init without snapshots.");
#[cfg(not(feature = "check-only"))]
let source_bytes = include_bytes!(concat!(
env!("GN_OUT_DIR"),
"/gen/cli/bundle/compiler.js"
));
#[cfg(feature = "check-only")]
let source_bytes = b"";

StartupData::Script(Script {
filename: "gen/cli/bundle/compiler.js",
source: std::str::from_utf8(&source_bytes[..]).unwrap(),
})
} else {
debug!("Deno isolate init with snapshots.");
#[cfg(not(any(feature = "check-only", feature = "no-snapshot-init")))]
let data = include_bytes!(concat!(
env!("GN_OUT_DIR"),
"/gen/cli/snapshot_compiler.bin"
));
#[cfg(any(feature = "check-only", feature = "no-snapshot-init"))]
let data = b"";

StartupData::Snapshot(data)
}
debug!("Compiler isolate init without snapshots.");
#[cfg(not(feature = "check-only"))]
let source =
include_str!(concat!(env!("GN_OUT_DIR"), "/gen/cli/bundle/compiler.js"));
#[cfg(feature = "check-only")]
let source = "";

StartupData::Script(Script {
filename: "gen/cli/bundle/compiler.js",
source,
})
}

#[cfg(not(feature = "no-snapshot-init"))]
pub fn compiler_isolate_init() -> StartupData<'static> {
debug!("Deno isolate init with snapshots.");
#[cfg(not(feature = "check-only"))]
let data = include_bytes!(concat!(
env!("GN_OUT_DIR"),
"/gen/cli/snapshot_compiler.bin"
));
#[cfg(feature = "check-only")]
let data = b"";

StartupData::Snapshot(data)
}
12 changes: 6 additions & 6 deletions core/isolate.rs
Expand Up @@ -25,7 +25,7 @@ use libc::c_void;
use std::ffi::CStr;
use std::ffi::CString;
use std::ptr::null;
use std::sync::{Arc, Mutex, Once, ONCE_INIT};
use std::sync::{Arc, Mutex, Once};

pub type Buf = Box<[u8]>;

Expand Down Expand Up @@ -55,8 +55,8 @@ struct OwnedScript {
pub filename: String,
}

impl<'a> From<Script<'a>> for OwnedScript {
fn from(s: Script<'a>) -> OwnedScript {
impl From<Script<'_>> for OwnedScript {
fn from(s: Script) -> OwnedScript {
OwnedScript {
source: s.source.to_string(),
filename: s.filename.to_string(),
Expand Down Expand Up @@ -133,10 +133,10 @@ impl Drop for Isolate {
}
}

static DENO_INIT: Once = ONCE_INIT;
static DENO_INIT: Once = Once::new();

impl Isolate {
/// startup_data defines the snapshot or script used at startup to initalize
/// startup_data defines the snapshot or script used at startup to initialize
/// the isolate.
pub fn new(startup_data: StartupData, will_snapshot: bool) -> Self {
DENO_INIT.call_once(|| {
Expand All @@ -157,7 +157,7 @@ impl Isolate {

let mut startup_script: Option<OwnedScript> = None;

// Seperate into Option values for each startup type
// Separate into Option values for each startup type
match startup_data {
StartupData::Script(d) => {
startup_script = Some(d.into());
Expand Down

0 comments on commit 6fa6828

Please sign in to comment.