refactor: rename ThreadSafeState, use RefCell for mutable state (#3931)

* rename ThreadSafeState to State
* State stores InnerState wrapped in Rc and RefCell
This commit is contained in:
Bartek Iwańczuk 2020-02-08 20:34:31 +01:00 committed by GitHub
parent 619a24390f
commit cdba5ab6fc
31 changed files with 454 additions and 464 deletions

View file

@ -6,7 +6,7 @@ use crate::deno_error::ErrorKind;
use crate::fs as deno_fs;
use crate::ops::dispatch_json::JsonResult;
use crate::ops::json_op;
use crate::state::ThreadSafeState;
use crate::state::State;
use deno_core::*;
use remove_dir_all::remove_dir_all;
use std::convert::From;
@ -19,7 +19,7 @@ use std::os::unix::fs::MetadataExt;
#[cfg(unix)]
use std::os::unix::fs::PermissionsExt;
pub fn init(i: &mut Isolate, s: &ThreadSafeState) {
pub fn init(i: &mut Isolate, s: &State) {
i.register_op("chdir", s.core_op(json_op(s.stateful_op(op_chdir))));
i.register_op("mkdir", s.core_op(json_op(s.stateful_op(op_mkdir))));
i.register_op("chmod", s.core_op(json_op(s.stateful_op(op_chmod))));
@ -48,7 +48,7 @@ struct ChdirArgs {
}
fn op_chdir(
_state: &ThreadSafeState,
_state: &State,
args: Value,
_zero_copy: Option<ZeroCopyBuf>,
) -> Result<JsonOp, ErrBox> {
@ -67,7 +67,7 @@ struct MkdirArgs {
}
fn op_mkdir(
state: &ThreadSafeState,
state: &State,
args: Value,
_zero_copy: Option<ZeroCopyBuf>,
) -> Result<JsonOp, ErrBox> {
@ -94,7 +94,7 @@ struct ChmodArgs {
}
fn op_chmod(
state: &ThreadSafeState,
state: &State,
args: Value,
_zero_copy: Option<ZeroCopyBuf>,
) -> Result<JsonOp, ErrBox> {
@ -128,7 +128,7 @@ struct ChownArgs {
}
fn op_chown(
state: &ThreadSafeState,
state: &State,
args: Value,
_zero_copy: Option<ZeroCopyBuf>,
) -> Result<JsonOp, ErrBox> {
@ -156,7 +156,7 @@ struct RemoveArgs {
}
fn op_remove(
state: &ThreadSafeState,
state: &State,
args: Value,
_zero_copy: Option<ZeroCopyBuf>,
) -> Result<JsonOp, ErrBox> {
@ -191,7 +191,7 @@ struct CopyFileArgs {
}
fn op_copy_file(
state: &ThreadSafeState,
state: &State,
args: Value,
_zero_copy: Option<ZeroCopyBuf>,
) -> Result<JsonOp, ErrBox> {
@ -290,7 +290,7 @@ struct StatArgs {
}
fn op_stat(
state: &ThreadSafeState,
state: &State,
args: Value,
_zero_copy: Option<ZeroCopyBuf>,
) -> Result<JsonOp, ErrBox> {
@ -320,7 +320,7 @@ struct RealpathArgs {
}
fn op_realpath(
state: &ThreadSafeState,
state: &State,
args: Value,
_zero_copy: Option<ZeroCopyBuf>,
) -> Result<JsonOp, ErrBox> {
@ -352,7 +352,7 @@ struct ReadDirArgs {
}
fn op_read_dir(
state: &ThreadSafeState,
state: &State,
args: Value,
_zero_copy: Option<ZeroCopyBuf>,
) -> Result<JsonOp, ErrBox> {
@ -389,7 +389,7 @@ struct RenameArgs {
}
fn op_rename(
state: &ThreadSafeState,
state: &State,
args: Value,
_zero_copy: Option<ZeroCopyBuf>,
) -> Result<JsonOp, ErrBox> {
@ -418,7 +418,7 @@ struct LinkArgs {
}
fn op_link(
state: &ThreadSafeState,
state: &State,
args: Value,
_zero_copy: Option<ZeroCopyBuf>,
) -> Result<JsonOp, ErrBox> {
@ -446,7 +446,7 @@ struct SymlinkArgs {
}
fn op_symlink(
state: &ThreadSafeState,
state: &State,
args: Value,
_zero_copy: Option<ZeroCopyBuf>,
) -> Result<JsonOp, ErrBox> {
@ -478,7 +478,7 @@ struct ReadLinkArgs {
}
fn op_read_link(
state: &ThreadSafeState,
state: &State,
args: Value,
_zero_copy: Option<ZeroCopyBuf>,
) -> Result<JsonOp, ErrBox> {
@ -506,7 +506,7 @@ struct TruncateArgs {
}
fn op_truncate(
state: &ThreadSafeState,
state: &State,
args: Value,
_zero_copy: Option<ZeroCopyBuf>,
) -> Result<JsonOp, ErrBox> {
@ -535,7 +535,7 @@ struct MakeTempDirArgs {
}
fn op_make_temp_dir(
state: &ThreadSafeState,
state: &State,
args: Value,
_zero_copy: Option<ZeroCopyBuf>,
) -> Result<JsonOp, ErrBox> {
@ -575,7 +575,7 @@ struct Utime {
}
fn op_utime(
state: &ThreadSafeState,
state: &State,
args: Value,
_zero_copy: Option<ZeroCopyBuf>,
) -> Result<JsonOp, ErrBox> {
@ -590,7 +590,7 @@ fn op_utime(
}
fn op_cwd(
_state: &ThreadSafeState,
_state: &State,
_args: Value,
_zero_copy: Option<ZeroCopyBuf>,
) -> Result<JsonOp, ErrBox> {