mirror of
https://github.com/denoland/deno.git
synced 2025-08-04 02:48:24 +00:00
refactor(ext/node): enforce interior mutable for NodePermissions
to remove clones (#18831)
We can make `NodePermissions` rely on interior mutability (which the `PermissionsContainer` is already doing) in order to not have to clone everything all the time. This also reduces the chance of an accidental `borrow` while `borrrow_mut`.
This commit is contained in:
parent
667acb075c
commit
5b4a9b48ae
13 changed files with 59 additions and 65 deletions
|
@ -44,13 +44,13 @@ pub trait NodeEnv {
|
|||
}
|
||||
|
||||
pub trait NodePermissions {
|
||||
fn check_read(&mut self, path: &Path) -> Result<(), AnyError>;
|
||||
fn check_read(&self, path: &Path) -> Result<(), AnyError>;
|
||||
}
|
||||
|
||||
pub(crate) struct AllowAllNodePermissions;
|
||||
|
||||
impl NodePermissions for AllowAllNodePermissions {
|
||||
fn check_read(&mut self, _path: &Path) -> Result<(), AnyError> {
|
||||
fn check_read(&self, _path: &Path) -> Result<(), AnyError> {
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
@ -164,7 +164,7 @@ pub trait NpmResolver: std::fmt::Debug + Send + Sync {
|
|||
|
||||
fn ensure_read_permission(
|
||||
&self,
|
||||
permissions: &mut dyn NodePermissions,
|
||||
permissions: &dyn NodePermissions,
|
||||
path: &Path,
|
||||
) -> Result<(), AnyError>;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue