From 1499d57490f2d928e57b21c992e559fc403cad42 Mon Sep 17 00:00:00 2001 From: andy finch Date: Thu, 21 Mar 2019 15:52:30 -0400 Subject: [PATCH] Remove dead code (#1983) --- cli/ops.rs | 152 -------------------------------------------- src/cli_behavior.rs | 73 --------------------- 2 files changed, 225 deletions(-) delete mode 100644 src/cli_behavior.rs diff --git a/cli/ops.rs b/cli/ops.rs index 6d0acef043..a0605f64bb 100644 --- a/cli/ops.rs +++ b/cli/ops.rs @@ -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()), - } - }) - } -} -*/ diff --git a/src/cli_behavior.rs b/src/cli_behavior.rs deleted file mode 100644 index f30ae789fd..0000000000 --- a/src/cli_behavior.rs +++ /dev/null @@ -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, - pub state: Arc, -} - -impl CliBehavior { - pub fn new( - startup_data: Option, - state: Arc, - ) -> Self { - Self { - startup_data, - state, - } - } -} - -impl Behavior for CliBehavior { - fn startup_data(&mut self) -> Option { - 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) { - ops::dispatch_cli(self, control, zero_copy) - } -} - -impl IsolateStateContainer for CliBehavior { - fn state(&self) -> Arc { - self.state.clone() - } -} - -impl IsolateStateContainer for &CliBehavior { - fn state(&self) -> Arc { - self.state.clone() - } -} \ No newline at end of file