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

Remove dead code (#1983)

This commit is contained in:
andy finch 2019-03-21 15:52:30 -04:00 committed by Ryan Dahl
parent 93793dc455
commit 1499d57490
2 changed files with 0 additions and 225 deletions

View file

@ -1872,155 +1872,3 @@ fn op_worker_post_message(
});
Box::new(op)
}
/*
#[cfg(test)]
mod tests {
use super::*;
use crate::cli::Cli;
use crate::isolate_state::IsolateState;
use crate::permissions::{DenoPermissions, PermissionAccessor};
#[test]
fn fetch_module_meta_fails_without_read() {
let state = Arc::new(IsolateState::mock());
let permissions = DenoPermissions {
allow_write: PermissionAccessor::from(true),
allow_env: PermissionAccessor::from(true),
allow_net: PermissionAccessor::from(true),
allow_run: PermissionAccessor::from(true),
..Default::default()
};
let cli = Cli::new(None, state);
let builder = &mut FlatBufferBuilder::new();
let fetch_msg_args = msg::FetchModuleMetaDataArgs {
specifier: Some(builder.create_string("./somefile")),
referrer: Some(builder.create_string(".")),
};
let inner = msg::FetchModuleMetaData::create(builder, &fetch_msg_args);
let base_args = msg::BaseArgs {
inner: Some(inner.as_union_value()),
inner_type: msg::Any::FetchModuleMetaData,
..Default::default()
};
let base = msg::Base::create(builder, &base_args);
msg::finish_base_buffer(builder, base);
let data = builder.finished_data();
let final_msg = msg::get_root_as_base(&data);
let fetch_result =
op_fetch_module_meta_data(Box::new(&cli), &final_msg, deno_buf::empty()).wait();
match fetch_result {
Ok(_) => assert!(true),
Err(e) => assert_eq!(e.to_string(), permission_denied().to_string()),
}
}
#[test]
fn fetch_module_meta_fails_without_write() {
let state = Arc::new(IsolateState::mock());
let permissions = DenoPermissions {
allow_read: PermissionAccessor::from(true),
allow_env: PermissionAccessor::from(true),
allow_net: PermissionAccessor::from(true),
allow_run: PermissionAccessor::from(true),
..Default::default()
};
let cli = Cli::new(None, state, permissions);
let builder = &mut FlatBufferBuilder::new();
let fetch_msg_args = msg::FetchModuleMetaDataArgs {
specifier: Some(builder.create_string("./somefile")),
referrer: Some(builder.create_string(".")),
};
let inner = msg::FetchModuleMetaData::create(builder, &fetch_msg_args);
let base_args = msg::BaseArgs {
inner: Some(inner.as_union_value()),
inner_type: msg::Any::FetchModuleMetaData,
..Default::default()
};
let base = msg::Base::create(builder, &base_args);
msg::finish_base_buffer(builder, base);
let data = builder.finished_data();
let final_msg = msg::get_root_as_base(&data);
tokio_util::init(move || {
let fetch_result =
op_fetch_module_meta_data(&cli, &final_msg, deno_buf::empty()).wait();
match fetch_result {
Ok(_) => assert!(true),
Err(e) => assert_eq!(e.to_string(), permission_denied().to_string()),
}
})
}
#[test]
fn fetch_module_meta_fails_without_net() {
let state = Arc::new(IsolateState::mock());
let permissions = DenoPermissions {
allow_read: PermissionAccessor::from(true),
allow_write: PermissionAccessor::from(true),
allow_env: PermissionAccessor::from(true),
allow_run: PermissionAccessor::from(true),
..Default::default()
};
let cli = Cli::new(None, state, permissions);
let builder = &mut FlatBufferBuilder::new();
let fetch_msg_args = msg::FetchModuleMetaDataArgs {
specifier: Some(builder.create_string("./somefile")),
referrer: Some(builder.create_string(".")),
};
let inner = msg::FetchModuleMetaData::create(builder, &fetch_msg_args);
let base_args = msg::BaseArgs {
inner: Some(inner.as_union_value()),
inner_type: msg::Any::FetchModuleMetaData,
..Default::default()
};
let base = msg::Base::create(builder, &base_args);
msg::finish_base_buffer(builder, base);
let data = builder.finished_data();
let final_msg = msg::get_root_as_base(&data);
tokio_util::init(move || {
let fetch_result =
op_fetch_module_meta_data(&cli, &final_msg, deno_buf::empty()).wait();
match fetch_result {
Ok(_) => assert!(true),
Err(e) => assert_eq!(e.to_string(), permission_denied().to_string()),
}
})
}
#[test]
fn fetch_module_meta_not_permission_denied_with_permissions() {
let state = Arc::new(IsolateState::mock());
let permissions = DenoPermissions {
allow_read: PermissionAccessor::from(true),
allow_write: PermissionAccessor::from(true),
allow_net: PermissionAccessor::from(true),
..Default::default()
};
let cli = Cli::new(None, state, permissions);
let builder = &mut FlatBufferBuilder::new();
let fetch_msg_args = msg::FetchModuleMetaDataArgs {
specifier: Some(builder.create_string("./somefile")),
referrer: Some(builder.create_string(".")),
};
let inner = msg::FetchModuleMetaData::create(builder, &fetch_msg_args);
let base_args = msg::BaseArgs {
inner: Some(inner.as_union_value()),
inner_type: msg::Any::FetchModuleMetaData,
..Default::default()
};
let base = msg::Base::create(builder, &base_args);
msg::finish_base_buffer(builder, base);
let data = builder.finished_data();
let final_msg = msg::get_root_as_base(&data);
tokio_util::init(move || {
let fetch_result =
op_fetch_module_meta_data(&cli, &final_msg, deno_buf::empty()).wait();
match fetch_result {
Ok(_) => assert!(true),
Err(e) => assert!(e.to_string() != permission_denied().to_string()),
}
})
}
}
*/

View file

@ -1,73 +0,0 @@
// Copyright 2018-2019 the Deno authors. All rights reserved. MIT license.
#![allow(unused_variables)]
#![allow(dead_code)]
use crate::isolate_state::IsolateStateContainer;
use crate::isolate_state::IsolateState;
use crate::ops;
use deno_core::deno_buf;
use deno_core::deno_mod;
use deno_core::Behavior;
use deno_core::Op;
use deno_core::StartupData;
use std::sync::atomic::Ordering;
use std::sync::Arc;
// Buf represents a byte array returned from a "Op". The message might be empty
// (which will be translated into a null object on the javascript side) or it is
// a heap allocated opaque sequence of bytes. Usually a flatbuffer message.
pub type Buf = Box<[u8]>;
/// Implements deno_core::Behavior for the main Deno command-line.
pub struct CliBehavior {
startup_data: Option<StartupData>,
pub state: Arc<IsolateState>,
}
impl CliBehavior {
pub fn new(
startup_data: Option<StartupData>,
state: Arc<IsolateState>,
) -> Self {
Self {
startup_data,
state,
}
}
}
impl Behavior for CliBehavior {
fn startup_data(&mut self) -> Option<StartupData> {
self.startup_data.take()
}
fn resolve(&mut self, specifier: &str, referrer: deno_mod) -> deno_mod {
self
.state
.metrics
.resolve_count
.fetch_add(1, Ordering::Relaxed);
let mut modules = self.state.modules.lock().unwrap();
modules.resolve_cb(&self.state.dir, specifier, referrer)
}
fn dispatch(
&mut self,
control: &[u8],
zero_copy: deno_buf,
) -> (bool, Box<Op>) {
ops::dispatch_cli(self, control, zero_copy)
}
}
impl IsolateStateContainer for CliBehavior {
fn state(&self) -> Arc<IsolateState> {
self.state.clone()
}
}
impl IsolateStateContainer for &CliBehavior {
fn state(&self) -> Arc<IsolateState> {
self.state.clone()
}
}