deno/cli/cli_behavior.rs
Ryan Dahl f7fdb90fd5
core: snapshot improvements (#2052)
* Moves how snapshots are supplied to the Isolate. Previously they were
  given by Behavior::startup_data() but it was only called once at
  startup. It makes more sense (and simplifies Behavior) to pass it to the
  constructor of Isolate.
* Adds new libdeno type deno_snapshot instead of overloading
  deno_buf.
* Adds new libdeno method to delete snapshot deno_snapshot_delete().
* Renames deno_get_snapshot() to deno_snapshot_new().
* Makes StartupData hold references to snapshots. This was implicit when
  it previously held a deno_buf but is made explicit now. Note that
  include_bytes!() returns a &'static [u8] and we want to avoid
  copying that.
2019-04-08 10:12:43 -04:00

40 lines
852 B
Rust

// Copyright 2018-2019 the Deno authors. All rights reserved. MIT license.
use crate::isolate_state::*;
use crate::ops;
use deno::deno_buf;
use deno::Behavior;
use deno::Op;
use std::sync::Arc;
/// Implements deno::Behavior for the main Deno command-line.
pub struct CliBehavior {
pub state: Arc<IsolateState>,
}
impl CliBehavior {
pub fn new(state: Arc<IsolateState>) -> Self {
Self { state }
}
}
impl IsolateStateContainer for &CliBehavior {
fn state(&self) -> Arc<IsolateState> {
self.state.clone()
}
}
impl IsolateStateContainer for CliBehavior {
fn state(&self) -> Arc<IsolateState> {
self.state.clone()
}
}
impl Behavior for CliBehavior {
fn dispatch(
&mut self,
control: &[u8],
zero_copy: deno_buf,
) -> (bool, Box<Op>) {
ops::dispatch_all(self, control, zero_copy, ops::op_selector_std)
}
}