summaryrefslogtreecommitdiff
path: root/cli/ops/permissions.rs
diff options
context:
space:
mode:
authorBartek IwaƄczuk <biwanczuk@gmail.com>2020-09-20 01:17:35 +0200
committerGitHub <noreply@github.com>2020-09-20 01:17:35 +0200
commitb657d743a22802b8232fbf558f2f00bf2942096f (patch)
treee3a3047e78b6bd9c9e3f551f99f5e80e32de079d /cli/ops/permissions.rs
parentaaa5e6613a739f8e2ff7579b69c2504bcdc37d4f (diff)
refactor: remove CliState, use OpState, add CliModuleLoader (#7588)
- remove "CliState.workers" and "CliState.next_worker_id", instead store them on "OpState" using type aliases. - remove "CliState.global_timer" and "CliState.start_time", instead store them on "OpState" using type aliases. - remove "CliState.is_internal", instead pass it to Worker::new - move "CliState::permissions" to "OpState" - move "CliState::main_module" to "OpState" - move "CliState::global_state" to "OpState" - move "CliState::check_unstable()" to "GlobalState" - change "cli_state()" to "global_state()" - change "deno_core::ModuleLoader" trait to pass "OpState" to callbacks - rename "CliState" to "CliModuleLoader"
Diffstat (limited to 'cli/ops/permissions.rs')
-rw-r--r--cli/ops/permissions.rs10
1 files changed, 4 insertions, 6 deletions
diff --git a/cli/ops/permissions.rs b/cli/ops/permissions.rs
index 2cdb03e31..54dda78bc 100644
--- a/cli/ops/permissions.rs
+++ b/cli/ops/permissions.rs
@@ -1,5 +1,6 @@
// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license.
+use crate::permissions::Permissions;
use deno_core::error::custom_error;
use deno_core::error::AnyError;
use deno_core::OpState;
@@ -27,8 +28,7 @@ pub fn op_query_permission(
_zero_copy: &mut [ZeroCopyBuf],
) -> Result<Value, AnyError> {
let args: PermissionArgs = serde_json::from_value(args)?;
- let cli_state = super::cli_state(state);
- let permissions = cli_state.permissions.borrow();
+ let permissions = state.borrow::<Permissions>();
let path = args.path.as_deref();
let perm = match args.name.as_ref() {
"read" => permissions.query_read(&path.as_deref().map(Path::new)),
@@ -54,8 +54,7 @@ pub fn op_revoke_permission(
_zero_copy: &mut [ZeroCopyBuf],
) -> Result<Value, AnyError> {
let args: PermissionArgs = serde_json::from_value(args)?;
- let cli_state = super::cli_state(state);
- let mut permissions = cli_state.permissions.borrow_mut();
+ let permissions = state.borrow_mut::<Permissions>();
let path = args.path.as_deref();
let perm = match args.name.as_ref() {
"read" => permissions.revoke_read(&path.as_deref().map(Path::new)),
@@ -81,8 +80,7 @@ pub fn op_request_permission(
_zero_copy: &mut [ZeroCopyBuf],
) -> Result<Value, AnyError> {
let args: PermissionArgs = serde_json::from_value(args)?;
- let cli_state = super::cli_state(state);
- let permissions = &mut cli_state.permissions.borrow_mut();
+ let permissions = state.borrow_mut::<Permissions>();
let path = args.path.as_deref();
let perm = match args.name.as_ref() {
"read" => permissions.request_read(&path.as_deref().map(Path::new)),