mirror of
https://github.com/denoland/deno.git
synced 2024-12-22 07:14:47 -05:00
move runtime ops to serde ops (#9828)
This commit is contained in:
parent
62716422b9
commit
b59151f39e
13 changed files with 176 additions and 264 deletions
|
@ -118,7 +118,7 @@ fn into_string(s: std::ffi::OsString) -> Result<String, AnyError> {
|
|||
|
||||
#[derive(Deserialize)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
struct OpenArgs {
|
||||
pub struct OpenArgs {
|
||||
path: String,
|
||||
mode: Option<u32>,
|
||||
options: OpenOptions,
|
||||
|
@ -127,7 +127,7 @@ struct OpenArgs {
|
|||
#[derive(Deserialize, Default, Debug)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
#[serde(default)]
|
||||
struct OpenOptions {
|
||||
pub struct OpenOptions {
|
||||
read: bool,
|
||||
write: bool,
|
||||
create: bool,
|
||||
|
@ -138,9 +138,8 @@ struct OpenOptions {
|
|||
|
||||
fn open_helper(
|
||||
state: &mut OpState,
|
||||
args: Value,
|
||||
args: OpenArgs,
|
||||
) -> Result<(PathBuf, std::fs::OpenOptions), AnyError> {
|
||||
let args: OpenArgs = serde_json::from_value(args)?;
|
||||
let path = Path::new(&args.path).to_path_buf();
|
||||
|
||||
let mut open_options = std::fs::OpenOptions::new();
|
||||
|
@ -181,7 +180,7 @@ fn open_helper(
|
|||
|
||||
fn op_open_sync(
|
||||
state: &mut OpState,
|
||||
args: Value,
|
||||
args: OpenArgs,
|
||||
_zero_copy: &mut [ZeroCopyBuf],
|
||||
) -> Result<Value, AnyError> {
|
||||
let (path, open_options) = open_helper(state, args)?;
|
||||
|
@ -194,7 +193,7 @@ fn op_open_sync(
|
|||
|
||||
async fn op_open_async(
|
||||
state: Rc<RefCell<OpState>>,
|
||||
args: Value,
|
||||
args: OpenArgs,
|
||||
_zero_copy: BufVec,
|
||||
) -> Result<Value, AnyError> {
|
||||
let (path, open_options) = open_helper(&mut state.borrow_mut(), args)?;
|
||||
|
@ -208,14 +207,13 @@ async fn op_open_async(
|
|||
|
||||
#[derive(Deserialize)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
struct SeekArgs {
|
||||
pub struct SeekArgs {
|
||||
rid: i32,
|
||||
offset: i64,
|
||||
whence: i32,
|
||||
}
|
||||
|
||||
fn seek_helper(args: Value) -> Result<(u32, SeekFrom), AnyError> {
|
||||
let args: SeekArgs = serde_json::from_value(args)?;
|
||||
fn seek_helper(args: SeekArgs) -> Result<(u32, SeekFrom), AnyError> {
|
||||
let rid = args.rid as u32;
|
||||
let offset = args.offset;
|
||||
let whence = args.whence as u32;
|
||||
|
@ -234,7 +232,7 @@ fn seek_helper(args: Value) -> Result<(u32, SeekFrom), AnyError> {
|
|||
|
||||
fn op_seek_sync(
|
||||
state: &mut OpState,
|
||||
args: Value,
|
||||
args: SeekArgs,
|
||||
_zero_copy: &mut [ZeroCopyBuf],
|
||||
) -> Result<Value, AnyError> {
|
||||
let (rid, seek_from) = seek_helper(args)?;
|
||||
|
@ -249,7 +247,7 @@ fn op_seek_sync(
|
|||
|
||||
async fn op_seek_async(
|
||||
state: Rc<RefCell<OpState>>,
|
||||
args: Value,
|
||||
args: SeekArgs,
|
||||
_zero_copy: BufVec,
|
||||
) -> Result<Value, AnyError> {
|
||||
let (rid, seek_from) = seek_helper(args)?;
|
||||
|
@ -274,16 +272,15 @@ async fn op_seek_async(
|
|||
|
||||
#[derive(Deserialize)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
struct FdatasyncArgs {
|
||||
pub struct FdatasyncArgs {
|
||||
rid: i32,
|
||||
}
|
||||
|
||||
fn op_fdatasync_sync(
|
||||
state: &mut OpState,
|
||||
args: Value,
|
||||
args: FdatasyncArgs,
|
||||
_zero_copy: &mut [ZeroCopyBuf],
|
||||
) -> Result<Value, AnyError> {
|
||||
let args: FdatasyncArgs = serde_json::from_value(args)?;
|
||||
let rid = args.rid as u32;
|
||||
StdFileResource::with(state, rid, |r| match r {
|
||||
Ok(std_file) => std_file.sync_data().map_err(AnyError::from),
|
||||
|
@ -294,10 +291,9 @@ fn op_fdatasync_sync(
|
|||
|
||||
async fn op_fdatasync_async(
|
||||
state: Rc<RefCell<OpState>>,
|
||||
args: Value,
|
||||
args: FdatasyncArgs,
|
||||
_zero_copy: BufVec,
|
||||
) -> Result<Value, AnyError> {
|
||||
let args: FdatasyncArgs = serde_json::from_value(args)?;
|
||||
let rid = args.rid as u32;
|
||||
|
||||
let resource = state
|
||||
|
@ -320,16 +316,15 @@ async fn op_fdatasync_async(
|
|||
|
||||
#[derive(Deserialize)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
struct FsyncArgs {
|
||||
pub struct FsyncArgs {
|
||||
rid: i32,
|
||||
}
|
||||
|
||||
fn op_fsync_sync(
|
||||
state: &mut OpState,
|
||||
args: Value,
|
||||
args: FsyncArgs,
|
||||
_zero_copy: &mut [ZeroCopyBuf],
|
||||
) -> Result<Value, AnyError> {
|
||||
let args: FsyncArgs = serde_json::from_value(args)?;
|
||||
let rid = args.rid as u32;
|
||||
StdFileResource::with(state, rid, |r| match r {
|
||||
Ok(std_file) => std_file.sync_all().map_err(AnyError::from),
|
||||
|
@ -340,10 +335,9 @@ fn op_fsync_sync(
|
|||
|
||||
async fn op_fsync_async(
|
||||
state: Rc<RefCell<OpState>>,
|
||||
args: Value,
|
||||
args: FsyncArgs,
|
||||
_zero_copy: BufVec,
|
||||
) -> Result<Value, AnyError> {
|
||||
let args: FsyncArgs = serde_json::from_value(args)?;
|
||||
let rid = args.rid as u32;
|
||||
|
||||
let resource = state
|
||||
|
@ -366,17 +360,16 @@ async fn op_fsync_async(
|
|||
|
||||
#[derive(Deserialize)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
struct FstatArgs {
|
||||
pub struct FstatArgs {
|
||||
rid: i32,
|
||||
}
|
||||
|
||||
fn op_fstat_sync(
|
||||
state: &mut OpState,
|
||||
args: Value,
|
||||
args: FstatArgs,
|
||||
_zero_copy: &mut [ZeroCopyBuf],
|
||||
) -> Result<Value, AnyError> {
|
||||
super::check_unstable(state, "Deno.fstat");
|
||||
let args: FstatArgs = serde_json::from_value(args)?;
|
||||
let rid = args.rid as u32;
|
||||
let metadata = StdFileResource::with(state, rid, |r| match r {
|
||||
Ok(std_file) => std_file.metadata().map_err(AnyError::from),
|
||||
|
@ -387,12 +380,11 @@ fn op_fstat_sync(
|
|||
|
||||
async fn op_fstat_async(
|
||||
state: Rc<RefCell<OpState>>,
|
||||
args: Value,
|
||||
args: FstatArgs,
|
||||
_zero_copy: BufVec,
|
||||
) -> Result<Value, AnyError> {
|
||||
super::check_unstable2(&state, "Deno.fstat");
|
||||
|
||||
let args: FstatArgs = serde_json::from_value(args)?;
|
||||
let rid = args.rid as u32;
|
||||
|
||||
let resource = state
|
||||
|
@ -414,17 +406,17 @@ async fn op_fstat_async(
|
|||
}
|
||||
|
||||
#[derive(Deserialize)]
|
||||
struct UmaskArgs {
|
||||
pub struct UmaskArgs {
|
||||
mask: Option<u32>,
|
||||
}
|
||||
|
||||
#[allow(clippy::unnecessary_wraps)]
|
||||
fn op_umask(
|
||||
state: &mut OpState,
|
||||
args: Value,
|
||||
args: UmaskArgs,
|
||||
_zero_copy: &mut [ZeroCopyBuf],
|
||||
) -> Result<Value, AnyError> {
|
||||
super::check_unstable(state, "Deno.umask");
|
||||
let args: UmaskArgs = serde_json::from_value(args)?;
|
||||
// TODO implement umask for Windows
|
||||
// see https://github.com/nodejs/node/blob/master/src/node_process_methods.cc
|
||||
// and https://docs.microsoft.com/fr-fr/cpp/c-runtime-library/reference/umask?view=vs-2019
|
||||
|
@ -452,16 +444,15 @@ fn op_umask(
|
|||
}
|
||||
|
||||
#[derive(Deserialize)]
|
||||
struct ChdirArgs {
|
||||
pub struct ChdirArgs {
|
||||
directory: String,
|
||||
}
|
||||
|
||||
fn op_chdir(
|
||||
state: &mut OpState,
|
||||
args: Value,
|
||||
args: ChdirArgs,
|
||||
_zero_copy: &mut [ZeroCopyBuf],
|
||||
) -> Result<Value, AnyError> {
|
||||
let args: ChdirArgs = serde_json::from_value(args)?;
|
||||
let d = PathBuf::from(&args.directory);
|
||||
state.borrow::<Permissions>().read.check(&d)?;
|
||||
set_current_dir(&d)?;
|
||||
|
@ -470,7 +461,7 @@ fn op_chdir(
|
|||
|
||||
#[derive(Deserialize)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
struct MkdirArgs {
|
||||
pub struct MkdirArgs {
|
||||
path: String,
|
||||
recursive: bool,
|
||||
mode: Option<u32>,
|
||||
|
@ -478,10 +469,9 @@ struct MkdirArgs {
|
|||
|
||||
fn op_mkdir_sync(
|
||||
state: &mut OpState,
|
||||
args: Value,
|
||||
args: MkdirArgs,
|
||||
_zero_copy: &mut [ZeroCopyBuf],
|
||||
) -> Result<Value, AnyError> {
|
||||
let args: MkdirArgs = serde_json::from_value(args)?;
|
||||
let path = Path::new(&args.path).to_path_buf();
|
||||
let mode = args.mode.unwrap_or(0o777) & 0o777;
|
||||
state.borrow::<Permissions>().write.check(&path)?;
|
||||
|
@ -499,10 +489,9 @@ fn op_mkdir_sync(
|
|||
|
||||
async fn op_mkdir_async(
|
||||
state: Rc<RefCell<OpState>>,
|
||||
args: Value,
|
||||
args: MkdirArgs,
|
||||
_zero_copy: BufVec,
|
||||
) -> Result<Value, AnyError> {
|
||||
let args: MkdirArgs = serde_json::from_value(args)?;
|
||||
let path = Path::new(&args.path).to_path_buf();
|
||||
let mode = args.mode.unwrap_or(0o777) & 0o777;
|
||||
|
||||
|
@ -529,17 +518,16 @@ async fn op_mkdir_async(
|
|||
|
||||
#[derive(Deserialize)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
struct ChmodArgs {
|
||||
pub struct ChmodArgs {
|
||||
path: String,
|
||||
mode: u32,
|
||||
}
|
||||
|
||||
fn op_chmod_sync(
|
||||
state: &mut OpState,
|
||||
args: Value,
|
||||
args: ChmodArgs,
|
||||
_zero_copy: &mut [ZeroCopyBuf],
|
||||
) -> Result<Value, AnyError> {
|
||||
let args: ChmodArgs = serde_json::from_value(args)?;
|
||||
let path = Path::new(&args.path).to_path_buf();
|
||||
let mode = args.mode & 0o777;
|
||||
|
||||
|
@ -563,10 +551,9 @@ fn op_chmod_sync(
|
|||
|
||||
async fn op_chmod_async(
|
||||
state: Rc<RefCell<OpState>>,
|
||||
args: Value,
|
||||
args: ChmodArgs,
|
||||
_zero_copy: BufVec,
|
||||
) -> Result<Value, AnyError> {
|
||||
let args: ChmodArgs = serde_json::from_value(args)?;
|
||||
let path = Path::new(&args.path).to_path_buf();
|
||||
let mode = args.mode & 0o777;
|
||||
|
||||
|
@ -598,7 +585,7 @@ async fn op_chmod_async(
|
|||
|
||||
#[derive(Deserialize)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
struct ChownArgs {
|
||||
pub struct ChownArgs {
|
||||
path: String,
|
||||
uid: Option<u32>,
|
||||
gid: Option<u32>,
|
||||
|
@ -606,10 +593,9 @@ struct ChownArgs {
|
|||
|
||||
fn op_chown_sync(
|
||||
state: &mut OpState,
|
||||
args: Value,
|
||||
args: ChownArgs,
|
||||
_zero_copy: &mut [ZeroCopyBuf],
|
||||
) -> Result<Value, AnyError> {
|
||||
let args: ChownArgs = serde_json::from_value(args)?;
|
||||
let path = Path::new(&args.path).to_path_buf();
|
||||
state.borrow::<Permissions>().write.check(&path)?;
|
||||
debug!(
|
||||
|
@ -635,10 +621,9 @@ fn op_chown_sync(
|
|||
|
||||
async fn op_chown_async(
|
||||
state: Rc<RefCell<OpState>>,
|
||||
args: Value,
|
||||
args: ChownArgs,
|
||||
_zero_copy: BufVec,
|
||||
) -> Result<Value, AnyError> {
|
||||
let args: ChownArgs = serde_json::from_value(args)?;
|
||||
let path = Path::new(&args.path).to_path_buf();
|
||||
|
||||
{
|
||||
|
@ -671,17 +656,16 @@ async fn op_chown_async(
|
|||
|
||||
#[derive(Deserialize)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
struct RemoveArgs {
|
||||
pub struct RemoveArgs {
|
||||
path: String,
|
||||
recursive: bool,
|
||||
}
|
||||
|
||||
fn op_remove_sync(
|
||||
state: &mut OpState,
|
||||
args: Value,
|
||||
args: RemoveArgs,
|
||||
_zero_copy: &mut [ZeroCopyBuf],
|
||||
) -> Result<Value, AnyError> {
|
||||
let args: RemoveArgs = serde_json::from_value(args)?;
|
||||
let path = PathBuf::from(&args.path);
|
||||
let recursive = args.recursive;
|
||||
|
||||
|
@ -721,10 +705,9 @@ fn op_remove_sync(
|
|||
|
||||
async fn op_remove_async(
|
||||
state: Rc<RefCell<OpState>>,
|
||||
args: Value,
|
||||
args: RemoveArgs,
|
||||
_zero_copy: BufVec,
|
||||
) -> Result<Value, AnyError> {
|
||||
let args: RemoveArgs = serde_json::from_value(args)?;
|
||||
let path = PathBuf::from(&args.path);
|
||||
let recursive = args.recursive;
|
||||
|
||||
|
@ -771,17 +754,16 @@ async fn op_remove_async(
|
|||
|
||||
#[derive(Deserialize)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
struct CopyFileArgs {
|
||||
pub struct CopyFileArgs {
|
||||
from: String,
|
||||
to: String,
|
||||
}
|
||||
|
||||
fn op_copy_file_sync(
|
||||
state: &mut OpState,
|
||||
args: Value,
|
||||
args: CopyFileArgs,
|
||||
_zero_copy: &mut [ZeroCopyBuf],
|
||||
) -> Result<Value, AnyError> {
|
||||
let args: CopyFileArgs = serde_json::from_value(args)?;
|
||||
let from = PathBuf::from(&args.from);
|
||||
let to = PathBuf::from(&args.to);
|
||||
|
||||
|
@ -804,10 +786,9 @@ fn op_copy_file_sync(
|
|||
|
||||
async fn op_copy_file_async(
|
||||
state: Rc<RefCell<OpState>>,
|
||||
args: Value,
|
||||
args: CopyFileArgs,
|
||||
_zero_copy: BufVec,
|
||||
) -> Result<Value, AnyError> {
|
||||
let args: CopyFileArgs = serde_json::from_value(args)?;
|
||||
let from = PathBuf::from(&args.from);
|
||||
let to = PathBuf::from(&args.to);
|
||||
|
||||
|
@ -895,17 +876,16 @@ fn get_stat_json(metadata: std::fs::Metadata) -> Value {
|
|||
|
||||
#[derive(Deserialize)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
struct StatArgs {
|
||||
pub struct StatArgs {
|
||||
path: String,
|
||||
lstat: bool,
|
||||
}
|
||||
|
||||
fn op_stat_sync(
|
||||
state: &mut OpState,
|
||||
args: Value,
|
||||
args: StatArgs,
|
||||
_zero_copy: &mut [ZeroCopyBuf],
|
||||
) -> Result<Value, AnyError> {
|
||||
let args: StatArgs = serde_json::from_value(args)?;
|
||||
let path = PathBuf::from(&args.path);
|
||||
let lstat = args.lstat;
|
||||
state.borrow::<Permissions>().read.check(&path)?;
|
||||
|
@ -920,10 +900,9 @@ fn op_stat_sync(
|
|||
|
||||
async fn op_stat_async(
|
||||
state: Rc<RefCell<OpState>>,
|
||||
args: Value,
|
||||
args: StatArgs,
|
||||
_zero_copy: BufVec,
|
||||
) -> Result<Value, AnyError> {
|
||||
let args: StatArgs = serde_json::from_value(args)?;
|
||||
let path = PathBuf::from(&args.path);
|
||||
let lstat = args.lstat;
|
||||
|
||||
|
@ -947,16 +926,15 @@ async fn op_stat_async(
|
|||
|
||||
#[derive(Deserialize)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
struct RealpathArgs {
|
||||
pub struct RealpathArgs {
|
||||
path: String,
|
||||
}
|
||||
|
||||
fn op_realpath_sync(
|
||||
state: &mut OpState,
|
||||
args: Value,
|
||||
args: RealpathArgs,
|
||||
_zero_copy: &mut [ZeroCopyBuf],
|
||||
) -> Result<Value, AnyError> {
|
||||
let args: RealpathArgs = serde_json::from_value(args)?;
|
||||
let path = PathBuf::from(&args.path);
|
||||
|
||||
let permissions = state.borrow::<Permissions>();
|
||||
|
@ -975,10 +953,9 @@ fn op_realpath_sync(
|
|||
|
||||
async fn op_realpath_async(
|
||||
state: Rc<RefCell<OpState>>,
|
||||
args: Value,
|
||||
args: RealpathArgs,
|
||||
_zero_copy: BufVec,
|
||||
) -> Result<Value, AnyError> {
|
||||
let args: RealpathArgs = serde_json::from_value(args)?;
|
||||
let path = PathBuf::from(&args.path);
|
||||
|
||||
{
|
||||
|
@ -1004,16 +981,15 @@ async fn op_realpath_async(
|
|||
|
||||
#[derive(Deserialize)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
struct ReadDirArgs {
|
||||
pub struct ReadDirArgs {
|
||||
path: String,
|
||||
}
|
||||
|
||||
fn op_read_dir_sync(
|
||||
state: &mut OpState,
|
||||
args: Value,
|
||||
args: ReadDirArgs,
|
||||
_zero_copy: &mut [ZeroCopyBuf],
|
||||
) -> Result<Value, AnyError> {
|
||||
let args: ReadDirArgs = serde_json::from_value(args)?;
|
||||
let path = PathBuf::from(&args.path);
|
||||
|
||||
state.borrow::<Permissions>().read.check(&path)?;
|
||||
|
@ -1041,10 +1017,9 @@ fn op_read_dir_sync(
|
|||
|
||||
async fn op_read_dir_async(
|
||||
state: Rc<RefCell<OpState>>,
|
||||
args: Value,
|
||||
args: ReadDirArgs,
|
||||
_zero_copy: BufVec,
|
||||
) -> Result<Value, AnyError> {
|
||||
let args: ReadDirArgs = serde_json::from_value(args)?;
|
||||
let path = PathBuf::from(&args.path);
|
||||
{
|
||||
let state = state.borrow();
|
||||
|
@ -1077,17 +1052,16 @@ async fn op_read_dir_async(
|
|||
|
||||
#[derive(Deserialize)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
struct RenameArgs {
|
||||
pub struct RenameArgs {
|
||||
oldpath: String,
|
||||
newpath: String,
|
||||
}
|
||||
|
||||
fn op_rename_sync(
|
||||
state: &mut OpState,
|
||||
args: Value,
|
||||
args: RenameArgs,
|
||||
_zero_copy: &mut [ZeroCopyBuf],
|
||||
) -> Result<Value, AnyError> {
|
||||
let args: RenameArgs = serde_json::from_value(args)?;
|
||||
let oldpath = PathBuf::from(&args.oldpath);
|
||||
let newpath = PathBuf::from(&args.newpath);
|
||||
|
||||
|
@ -1102,10 +1076,9 @@ fn op_rename_sync(
|
|||
|
||||
async fn op_rename_async(
|
||||
state: Rc<RefCell<OpState>>,
|
||||
args: Value,
|
||||
args: RenameArgs,
|
||||
_zero_copy: BufVec,
|
||||
) -> Result<Value, AnyError> {
|
||||
let args: RenameArgs = serde_json::from_value(args)?;
|
||||
let oldpath = PathBuf::from(&args.oldpath);
|
||||
let newpath = PathBuf::from(&args.newpath);
|
||||
{
|
||||
|
@ -1130,17 +1103,16 @@ async fn op_rename_async(
|
|||
|
||||
#[derive(Deserialize)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
struct LinkArgs {
|
||||
pub struct LinkArgs {
|
||||
oldpath: String,
|
||||
newpath: String,
|
||||
}
|
||||
|
||||
fn op_link_sync(
|
||||
state: &mut OpState,
|
||||
args: Value,
|
||||
args: LinkArgs,
|
||||
_zero_copy: &mut [ZeroCopyBuf],
|
||||
) -> Result<Value, AnyError> {
|
||||
let args: LinkArgs = serde_json::from_value(args)?;
|
||||
let oldpath = PathBuf::from(&args.oldpath);
|
||||
let newpath = PathBuf::from(&args.newpath);
|
||||
|
||||
|
@ -1157,10 +1129,9 @@ fn op_link_sync(
|
|||
|
||||
async fn op_link_async(
|
||||
state: Rc<RefCell<OpState>>,
|
||||
args: Value,
|
||||
args: LinkArgs,
|
||||
_zero_copy: BufVec,
|
||||
) -> Result<Value, AnyError> {
|
||||
let args: LinkArgs = serde_json::from_value(args)?;
|
||||
let oldpath = PathBuf::from(&args.oldpath);
|
||||
let newpath = PathBuf::from(&args.newpath);
|
||||
|
||||
|
@ -1184,7 +1155,7 @@ async fn op_link_async(
|
|||
|
||||
#[derive(Deserialize)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
struct SymlinkArgs {
|
||||
pub struct SymlinkArgs {
|
||||
oldpath: String,
|
||||
newpath: String,
|
||||
#[cfg(not(unix))]
|
||||
|
@ -1194,16 +1165,15 @@ struct SymlinkArgs {
|
|||
#[cfg(not(unix))]
|
||||
#[derive(Deserialize)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
struct SymlinkOptions {
|
||||
pub struct SymlinkOptions {
|
||||
_type: String,
|
||||
}
|
||||
|
||||
fn op_symlink_sync(
|
||||
state: &mut OpState,
|
||||
args: Value,
|
||||
args: SymlinkArgs,
|
||||
_zero_copy: &mut [ZeroCopyBuf],
|
||||
) -> Result<Value, AnyError> {
|
||||
let args: SymlinkArgs = serde_json::from_value(args)?;
|
||||
let oldpath = PathBuf::from(&args.oldpath);
|
||||
let newpath = PathBuf::from(&args.newpath);
|
||||
|
||||
|
@ -1250,10 +1220,9 @@ fn op_symlink_sync(
|
|||
|
||||
async fn op_symlink_async(
|
||||
state: Rc<RefCell<OpState>>,
|
||||
args: Value,
|
||||
args: SymlinkArgs,
|
||||
_zero_copy: BufVec,
|
||||
) -> Result<Value, AnyError> {
|
||||
let args: SymlinkArgs = serde_json::from_value(args)?;
|
||||
let oldpath = PathBuf::from(&args.oldpath);
|
||||
let newpath = PathBuf::from(&args.newpath);
|
||||
|
||||
|
@ -1303,16 +1272,15 @@ async fn op_symlink_async(
|
|||
|
||||
#[derive(Deserialize)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
struct ReadLinkArgs {
|
||||
pub struct ReadLinkArgs {
|
||||
path: String,
|
||||
}
|
||||
|
||||
fn op_read_link_sync(
|
||||
state: &mut OpState,
|
||||
args: Value,
|
||||
args: ReadLinkArgs,
|
||||
_zero_copy: &mut [ZeroCopyBuf],
|
||||
) -> Result<Value, AnyError> {
|
||||
let args: ReadLinkArgs = serde_json::from_value(args)?;
|
||||
let path = PathBuf::from(&args.path);
|
||||
|
||||
state.borrow::<Permissions>().read.check(&path)?;
|
||||
|
@ -1325,10 +1293,9 @@ fn op_read_link_sync(
|
|||
|
||||
async fn op_read_link_async(
|
||||
state: Rc<RefCell<OpState>>,
|
||||
args: Value,
|
||||
args: ReadLinkArgs,
|
||||
_zero_copy: BufVec,
|
||||
) -> Result<Value, AnyError> {
|
||||
let args: ReadLinkArgs = serde_json::from_value(args)?;
|
||||
let path = PathBuf::from(&args.path);
|
||||
{
|
||||
let state = state.borrow();
|
||||
|
@ -1346,18 +1313,17 @@ async fn op_read_link_async(
|
|||
|
||||
#[derive(Deserialize)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
struct FtruncateArgs {
|
||||
pub struct FtruncateArgs {
|
||||
rid: i32,
|
||||
len: i32,
|
||||
}
|
||||
|
||||
fn op_ftruncate_sync(
|
||||
state: &mut OpState,
|
||||
args: Value,
|
||||
args: FtruncateArgs,
|
||||
_zero_copy: &mut [ZeroCopyBuf],
|
||||
) -> Result<Value, AnyError> {
|
||||
super::check_unstable(state, "Deno.ftruncate");
|
||||
let args: FtruncateArgs = serde_json::from_value(args)?;
|
||||
let rid = args.rid as u32;
|
||||
let len = args.len as u64;
|
||||
StdFileResource::with(state, rid, |r| match r {
|
||||
|
@ -1369,11 +1335,10 @@ fn op_ftruncate_sync(
|
|||
|
||||
async fn op_ftruncate_async(
|
||||
state: Rc<RefCell<OpState>>,
|
||||
args: Value,
|
||||
args: FtruncateArgs,
|
||||
_zero_copy: BufVec,
|
||||
) -> Result<Value, AnyError> {
|
||||
super::check_unstable2(&state, "Deno.ftruncate");
|
||||
let args: FtruncateArgs = serde_json::from_value(args)?;
|
||||
let rid = args.rid as u32;
|
||||
let len = args.len as u64;
|
||||
|
||||
|
@ -1397,17 +1362,16 @@ async fn op_ftruncate_async(
|
|||
|
||||
#[derive(Deserialize)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
struct TruncateArgs {
|
||||
pub struct TruncateArgs {
|
||||
path: String,
|
||||
len: u64,
|
||||
}
|
||||
|
||||
fn op_truncate_sync(
|
||||
state: &mut OpState,
|
||||
args: Value,
|
||||
args: TruncateArgs,
|
||||
_zero_copy: &mut [ZeroCopyBuf],
|
||||
) -> Result<Value, AnyError> {
|
||||
let args: TruncateArgs = serde_json::from_value(args)?;
|
||||
let path = PathBuf::from(&args.path);
|
||||
let len = args.len;
|
||||
|
||||
|
@ -1421,10 +1385,9 @@ fn op_truncate_sync(
|
|||
|
||||
async fn op_truncate_async(
|
||||
state: Rc<RefCell<OpState>>,
|
||||
args: Value,
|
||||
args: TruncateArgs,
|
||||
_zero_copy: BufVec,
|
||||
) -> Result<Value, AnyError> {
|
||||
let args: TruncateArgs = serde_json::from_value(args)?;
|
||||
let path = PathBuf::from(&args.path);
|
||||
let len = args.len;
|
||||
{
|
||||
|
@ -1488,7 +1451,7 @@ fn make_temp(
|
|||
|
||||
#[derive(Deserialize)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
struct MakeTempArgs {
|
||||
pub struct MakeTempArgs {
|
||||
dir: Option<String>,
|
||||
prefix: Option<String>,
|
||||
suffix: Option<String>,
|
||||
|
@ -1496,11 +1459,9 @@ struct MakeTempArgs {
|
|||
|
||||
fn op_make_temp_dir_sync(
|
||||
state: &mut OpState,
|
||||
args: Value,
|
||||
args: MakeTempArgs,
|
||||
_zero_copy: &mut [ZeroCopyBuf],
|
||||
) -> Result<Value, AnyError> {
|
||||
let args: MakeTempArgs = serde_json::from_value(args)?;
|
||||
|
||||
let dir = args.dir.map(|s| PathBuf::from(&s));
|
||||
let prefix = args.prefix.map(String::from);
|
||||
let suffix = args.suffix.map(String::from);
|
||||
|
@ -1527,11 +1488,9 @@ fn op_make_temp_dir_sync(
|
|||
|
||||
async fn op_make_temp_dir_async(
|
||||
state: Rc<RefCell<OpState>>,
|
||||
args: Value,
|
||||
args: MakeTempArgs,
|
||||
_zero_copy: BufVec,
|
||||
) -> Result<Value, AnyError> {
|
||||
let args: MakeTempArgs = serde_json::from_value(args)?;
|
||||
|
||||
let dir = args.dir.map(|s| PathBuf::from(&s));
|
||||
let prefix = args.prefix.map(String::from);
|
||||
let suffix = args.suffix.map(String::from);
|
||||
|
@ -1563,11 +1522,9 @@ async fn op_make_temp_dir_async(
|
|||
|
||||
fn op_make_temp_file_sync(
|
||||
state: &mut OpState,
|
||||
args: Value,
|
||||
args: MakeTempArgs,
|
||||
_zero_copy: &mut [ZeroCopyBuf],
|
||||
) -> Result<Value, AnyError> {
|
||||
let args: MakeTempArgs = serde_json::from_value(args)?;
|
||||
|
||||
let dir = args.dir.map(|s| PathBuf::from(&s));
|
||||
let prefix = args.prefix.map(String::from);
|
||||
let suffix = args.suffix.map(String::from);
|
||||
|
@ -1594,11 +1551,9 @@ fn op_make_temp_file_sync(
|
|||
|
||||
async fn op_make_temp_file_async(
|
||||
state: Rc<RefCell<OpState>>,
|
||||
args: Value,
|
||||
args: MakeTempArgs,
|
||||
_zero_copy: BufVec,
|
||||
) -> Result<Value, AnyError> {
|
||||
let args: MakeTempArgs = serde_json::from_value(args)?;
|
||||
|
||||
let dir = args.dir.map(|s| PathBuf::from(&s));
|
||||
let prefix = args.prefix.map(String::from);
|
||||
let suffix = args.suffix.map(String::from);
|
||||
|
@ -1630,7 +1585,7 @@ async fn op_make_temp_file_async(
|
|||
|
||||
#[derive(Deserialize)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
struct FutimeArgs {
|
||||
pub struct FutimeArgs {
|
||||
rid: i32,
|
||||
atime: (i64, u32),
|
||||
mtime: (i64, u32),
|
||||
|
@ -1638,11 +1593,10 @@ struct FutimeArgs {
|
|||
|
||||
fn op_futime_sync(
|
||||
state: &mut OpState,
|
||||
args: Value,
|
||||
args: FutimeArgs,
|
||||
_zero_copy: &mut [ZeroCopyBuf],
|
||||
) -> Result<Value, AnyError> {
|
||||
super::check_unstable(state, "Deno.futimeSync");
|
||||
let args: FutimeArgs = serde_json::from_value(args)?;
|
||||
let rid = args.rid as u32;
|
||||
let atime = filetime::FileTime::from_unix_time(args.atime.0, args.atime.1);
|
||||
let mtime = filetime::FileTime::from_unix_time(args.mtime.0, args.mtime.1);
|
||||
|
@ -1662,11 +1616,10 @@ fn op_futime_sync(
|
|||
|
||||
async fn op_futime_async(
|
||||
state: Rc<RefCell<OpState>>,
|
||||
args: Value,
|
||||
args: FutimeArgs,
|
||||
_zero_copy: BufVec,
|
||||
) -> Result<Value, AnyError> {
|
||||
super::check_unstable2(&state, "Deno.futime");
|
||||
let args: FutimeArgs = serde_json::from_value(args)?;
|
||||
let rid = args.rid as u32;
|
||||
let atime = filetime::FileTime::from_unix_time(args.atime.0, args.atime.1);
|
||||
let mtime = filetime::FileTime::from_unix_time(args.mtime.0, args.mtime.1);
|
||||
|
@ -1704,7 +1657,7 @@ async fn op_futime_async(
|
|||
|
||||
#[derive(Deserialize)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
struct UtimeArgs {
|
||||
pub struct UtimeArgs {
|
||||
path: String,
|
||||
atime: (i64, u32),
|
||||
mtime: (i64, u32),
|
||||
|
@ -1712,12 +1665,11 @@ struct UtimeArgs {
|
|||
|
||||
fn op_utime_sync(
|
||||
state: &mut OpState,
|
||||
args: Value,
|
||||
args: UtimeArgs,
|
||||
_zero_copy: &mut [ZeroCopyBuf],
|
||||
) -> Result<Value, AnyError> {
|
||||
super::check_unstable(state, "Deno.utime");
|
||||
|
||||
let args: UtimeArgs = serde_json::from_value(args)?;
|
||||
let path = PathBuf::from(&args.path);
|
||||
let atime = filetime::FileTime::from_unix_time(args.atime.0, args.atime.1);
|
||||
let mtime = filetime::FileTime::from_unix_time(args.mtime.0, args.mtime.1);
|
||||
|
@ -1729,12 +1681,11 @@ fn op_utime_sync(
|
|||
|
||||
async fn op_utime_async(
|
||||
state: Rc<RefCell<OpState>>,
|
||||
args: Value,
|
||||
args: UtimeArgs,
|
||||
_zero_copy: BufVec,
|
||||
) -> Result<Value, AnyError> {
|
||||
super::check_unstable(&state.borrow(), "Deno.utime");
|
||||
|
||||
let args: UtimeArgs = serde_json::from_value(args)?;
|
||||
let path = PathBuf::from(&args.path);
|
||||
let atime = filetime::FileTime::from_unix_time(args.atime.0, args.atime.1);
|
||||
let mtime = filetime::FileTime::from_unix_time(args.mtime.0, args.mtime.1);
|
||||
|
|
|
@ -3,7 +3,6 @@
|
|||
use crate::permissions::Permissions;
|
||||
use deno_core::error::bad_resource_id;
|
||||
use deno_core::error::AnyError;
|
||||
use deno_core::serde_json;
|
||||
use deno_core::serde_json::json;
|
||||
use deno_core::serde_json::Value;
|
||||
use deno_core::AsyncRefCell;
|
||||
|
@ -83,17 +82,17 @@ impl From<NotifyEvent> for FsEvent {
|
|||
}
|
||||
}
|
||||
|
||||
#[derive(Deserialize)]
|
||||
pub struct OpenArgs {
|
||||
recursive: bool,
|
||||
paths: Vec<String>,
|
||||
}
|
||||
|
||||
fn op_fs_events_open(
|
||||
state: &mut OpState,
|
||||
args: Value,
|
||||
args: OpenArgs,
|
||||
_zero_copy: &mut [ZeroCopyBuf],
|
||||
) -> Result<Value, AnyError> {
|
||||
#[derive(Deserialize)]
|
||||
struct OpenArgs {
|
||||
recursive: bool,
|
||||
paths: Vec<String>,
|
||||
}
|
||||
let args: OpenArgs = serde_json::from_value(args)?;
|
||||
let (sender, receiver) = mpsc::channel::<Result<FsEvent, AnyError>>(16);
|
||||
let sender = std::sync::Mutex::new(sender);
|
||||
let mut watcher: RecommendedWatcher =
|
||||
|
@ -125,21 +124,20 @@ fn op_fs_events_open(
|
|||
Ok(json!(rid))
|
||||
}
|
||||
|
||||
#[derive(Deserialize)]
|
||||
pub struct PollArgs {
|
||||
rid: u32,
|
||||
}
|
||||
|
||||
async fn op_fs_events_poll(
|
||||
state: Rc<RefCell<OpState>>,
|
||||
args: Value,
|
||||
args: PollArgs,
|
||||
_zero_copy: BufVec,
|
||||
) -> Result<Value, AnyError> {
|
||||
#[derive(Deserialize)]
|
||||
struct PollArgs {
|
||||
rid: u32,
|
||||
}
|
||||
let PollArgs { rid } = serde_json::from_value(args)?;
|
||||
|
||||
let resource = state
|
||||
.borrow()
|
||||
.resource_table
|
||||
.get::<FsEventsResource>(rid)
|
||||
.get::<FsEventsResource>(args.rid)
|
||||
.ok_or_else(bad_resource_id)?;
|
||||
let mut receiver = RcRef::map(&resource, |r| &r.receiver).borrow_mut().await;
|
||||
let cancel = RcRef::map(resource, |r| &r.cancel);
|
||||
|
|
|
@ -3,7 +3,6 @@
|
|||
use deno_core::error::resource_unavailable;
|
||||
use deno_core::error::AnyError;
|
||||
use deno_core::error::{bad_resource_id, not_supported};
|
||||
use deno_core::serde_json;
|
||||
use deno_core::serde_json::json;
|
||||
use deno_core::serde_json::Value;
|
||||
use deno_core::AsyncMutFuture;
|
||||
|
@ -615,14 +614,13 @@ struct ShutdownArgs {
|
|||
|
||||
async fn op_shutdown(
|
||||
state: Rc<RefCell<OpState>>,
|
||||
args: Value,
|
||||
args: ShutdownArgs,
|
||||
_zero_copy: BufVec,
|
||||
) -> Result<Value, AnyError> {
|
||||
let rid = serde_json::from_value::<ShutdownArgs>(args)?.rid;
|
||||
let resource = state
|
||||
.borrow()
|
||||
.resource_table
|
||||
.get_any(rid)
|
||||
.get_any(args.rid)
|
||||
.ok_or_else(bad_resource_id)?;
|
||||
if let Some(s) = resource.downcast_rc::<ChildStdinResource>() {
|
||||
s.shutdown().await?;
|
||||
|
|
|
@ -520,42 +520,42 @@ enum DnsReturnRecord {
|
|||
TXT(Vec<String>),
|
||||
}
|
||||
|
||||
#[derive(Deserialize)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub struct ResolveAddrArgs {
|
||||
query: String,
|
||||
record_type: RecordType,
|
||||
options: Option<ResolveDnsOption>,
|
||||
}
|
||||
|
||||
#[derive(Deserialize)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub struct ResolveDnsOption {
|
||||
name_server: Option<NameServer>,
|
||||
}
|
||||
|
||||
fn default_port() -> u16 {
|
||||
53
|
||||
}
|
||||
|
||||
#[derive(Deserialize)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub struct NameServer {
|
||||
ip_addr: String,
|
||||
#[serde(default = "default_port")]
|
||||
port: u16,
|
||||
}
|
||||
|
||||
async fn op_dns_resolve(
|
||||
state: Rc<RefCell<OpState>>,
|
||||
args: Value,
|
||||
args: ResolveAddrArgs,
|
||||
_zero_copy: BufVec,
|
||||
) -> Result<Value, AnyError> {
|
||||
fn default_port() -> u16 {
|
||||
53
|
||||
}
|
||||
|
||||
#[derive(Deserialize)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
struct ResolveAddrArgs {
|
||||
query: String,
|
||||
record_type: RecordType,
|
||||
options: Option<ResolveDnsOption>,
|
||||
}
|
||||
|
||||
#[derive(Deserialize)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
struct ResolveDnsOption {
|
||||
name_server: Option<NameServer>,
|
||||
}
|
||||
|
||||
#[derive(Deserialize)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
struct NameServer {
|
||||
ip_addr: String,
|
||||
#[serde(default = "default_port")]
|
||||
port: u16,
|
||||
}
|
||||
|
||||
let ResolveAddrArgs {
|
||||
query,
|
||||
record_type,
|
||||
options,
|
||||
} = serde_json::from_value(args)?;
|
||||
} = args;
|
||||
|
||||
let (config, opts) = if let Some(name_server) =
|
||||
options.as_ref().and_then(|o| o.name_server.as_ref())
|
||||
|
|
|
@ -2,7 +2,6 @@
|
|||
|
||||
use crate::permissions::Permissions;
|
||||
use deno_core::error::{type_error, AnyError};
|
||||
use deno_core::serde_json;
|
||||
use deno_core::serde_json::json;
|
||||
use deno_core::serde_json::Value;
|
||||
use deno_core::url::Url;
|
||||
|
@ -44,17 +43,16 @@ fn op_exec_path(
|
|||
}
|
||||
|
||||
#[derive(Deserialize)]
|
||||
struct SetEnv {
|
||||
pub struct SetEnv {
|
||||
key: String,
|
||||
value: String,
|
||||
}
|
||||
|
||||
fn op_set_env(
|
||||
state: &mut OpState,
|
||||
args: Value,
|
||||
args: SetEnv,
|
||||
_zero_copy: &mut [ZeroCopyBuf],
|
||||
) -> Result<Value, AnyError> {
|
||||
let args: SetEnv = serde_json::from_value(args)?;
|
||||
state.borrow::<Permissions>().env.check()?;
|
||||
let invalid_key =
|
||||
args.key.is_empty() || args.key.contains(&['=', '\0'] as &[char]);
|
||||
|
@ -77,16 +75,15 @@ fn op_env(
|
|||
}
|
||||
|
||||
#[derive(Deserialize)]
|
||||
struct GetEnv {
|
||||
pub struct GetEnv {
|
||||
key: String,
|
||||
}
|
||||
|
||||
fn op_get_env(
|
||||
state: &mut OpState,
|
||||
args: Value,
|
||||
args: GetEnv,
|
||||
_zero_copy: &mut [ZeroCopyBuf],
|
||||
) -> Result<Value, AnyError> {
|
||||
let args: GetEnv = serde_json::from_value(args)?;
|
||||
state.borrow::<Permissions>().env.check()?;
|
||||
if args.key.is_empty() || args.key.contains(&['=', '\0'] as &[char]) {
|
||||
return Err(type_error("Key contains invalid characters."));
|
||||
|
@ -99,16 +96,15 @@ fn op_get_env(
|
|||
}
|
||||
|
||||
#[derive(Deserialize)]
|
||||
struct DeleteEnv {
|
||||
pub struct DeleteEnv {
|
||||
key: String,
|
||||
}
|
||||
|
||||
fn op_delete_env(
|
||||
state: &mut OpState,
|
||||
args: Value,
|
||||
args: DeleteEnv,
|
||||
_zero_copy: &mut [ZeroCopyBuf],
|
||||
) -> Result<Value, AnyError> {
|
||||
let args: DeleteEnv = serde_json::from_value(args)?;
|
||||
state.borrow::<Permissions>().env.check()?;
|
||||
if args.key.is_empty() || args.key.contains(&['=', '\0'] as &[char]) {
|
||||
return Err(type_error("Key contains invalid characters."));
|
||||
|
@ -118,16 +114,15 @@ fn op_delete_env(
|
|||
}
|
||||
|
||||
#[derive(Deserialize)]
|
||||
struct Exit {
|
||||
pub struct Exit {
|
||||
code: i32,
|
||||
}
|
||||
|
||||
fn op_exit(
|
||||
_state: &mut OpState,
|
||||
args: Value,
|
||||
args: Exit,
|
||||
_zero_copy: &mut [ZeroCopyBuf],
|
||||
) -> Result<Value, AnyError> {
|
||||
let args: Exit = serde_json::from_value(args)?;
|
||||
std::process::exit(args.code)
|
||||
}
|
||||
|
||||
|
|
|
@ -4,7 +4,6 @@ use crate::permissions::Permissions;
|
|||
use deno_core::error::custom_error;
|
||||
use deno_core::error::uri_error;
|
||||
use deno_core::error::AnyError;
|
||||
use deno_core::serde_json;
|
||||
use deno_core::serde_json::json;
|
||||
use deno_core::serde_json::Value;
|
||||
use deno_core::url;
|
||||
|
@ -20,7 +19,7 @@ pub fn init(rt: &mut deno_core::JsRuntime) {
|
|||
}
|
||||
|
||||
#[derive(Deserialize)]
|
||||
struct PermissionArgs {
|
||||
pub struct PermissionArgs {
|
||||
name: String,
|
||||
path: Option<String>,
|
||||
host: Option<String>,
|
||||
|
@ -28,10 +27,9 @@ struct PermissionArgs {
|
|||
|
||||
pub fn op_query_permission(
|
||||
state: &mut OpState,
|
||||
args: Value,
|
||||
args: PermissionArgs,
|
||||
_zero_copy: &mut [ZeroCopyBuf],
|
||||
) -> Result<Value, AnyError> {
|
||||
let args: PermissionArgs = serde_json::from_value(args)?;
|
||||
let permissions = state.borrow::<Permissions>();
|
||||
let path = args.path.as_deref();
|
||||
let perm = match args.name.as_ref() {
|
||||
|
@ -60,10 +58,9 @@ pub fn op_query_permission(
|
|||
|
||||
pub fn op_revoke_permission(
|
||||
state: &mut OpState,
|
||||
args: Value,
|
||||
args: PermissionArgs,
|
||||
_zero_copy: &mut [ZeroCopyBuf],
|
||||
) -> Result<Value, AnyError> {
|
||||
let args: PermissionArgs = serde_json::from_value(args)?;
|
||||
let permissions = state.borrow_mut::<Permissions>();
|
||||
let path = args.path.as_deref();
|
||||
let perm = match args.name.as_ref() {
|
||||
|
@ -92,10 +89,9 @@ pub fn op_revoke_permission(
|
|||
|
||||
pub fn op_request_permission(
|
||||
state: &mut OpState,
|
||||
args: Value,
|
||||
args: PermissionArgs,
|
||||
_zero_copy: &mut [ZeroCopyBuf],
|
||||
) -> Result<Value, AnyError> {
|
||||
let args: PermissionArgs = serde_json::from_value(args)?;
|
||||
let permissions = state.borrow_mut::<Permissions>();
|
||||
let path = args.path.as_deref();
|
||||
let perm = match args.name.as_ref() {
|
||||
|
|
|
@ -5,7 +5,6 @@ use crate::permissions::Permissions;
|
|||
use deno_core::error::AnyError;
|
||||
use deno_core::futures::prelude::*;
|
||||
use deno_core::plugin_api;
|
||||
use deno_core::serde_json;
|
||||
use deno_core::serde_json::json;
|
||||
use deno_core::serde_json::Value;
|
||||
use deno_core::BufVec;
|
||||
|
@ -32,16 +31,15 @@ pub fn init(rt: &mut JsRuntime) {
|
|||
|
||||
#[derive(Deserialize)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
struct OpenPluginArgs {
|
||||
pub struct OpenPluginArgs {
|
||||
filename: String,
|
||||
}
|
||||
|
||||
pub fn op_open_plugin(
|
||||
state: &mut OpState,
|
||||
args: Value,
|
||||
args: OpenPluginArgs,
|
||||
_zero_copy: &mut [ZeroCopyBuf],
|
||||
) -> Result<Value, AnyError> {
|
||||
let args: OpenPluginArgs = serde_json::from_value(args)?;
|
||||
let filename = PathBuf::from(&args.filename);
|
||||
|
||||
super::check_unstable(state, "Deno.openPlugin");
|
||||
|
|
|
@ -8,7 +8,6 @@ use crate::permissions::Permissions;
|
|||
use deno_core::error::bad_resource_id;
|
||||
use deno_core::error::type_error;
|
||||
use deno_core::error::AnyError;
|
||||
use deno_core::serde_json;
|
||||
use deno_core::serde_json::json;
|
||||
use deno_core::serde_json::Value;
|
||||
use deno_core::AsyncMutFuture;
|
||||
|
@ -54,7 +53,7 @@ fn subprocess_stdio_map(s: &str) -> Result<std::process::Stdio, AnyError> {
|
|||
|
||||
#[derive(Deserialize)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
struct RunArgs {
|
||||
pub struct RunArgs {
|
||||
cmd: Vec<String>,
|
||||
cwd: Option<String>,
|
||||
env: Vec<(String, String)>,
|
||||
|
@ -84,10 +83,9 @@ impl ChildResource {
|
|||
|
||||
fn op_run(
|
||||
state: &mut OpState,
|
||||
args: Value,
|
||||
run_args: RunArgs,
|
||||
_zero_copy: &mut [ZeroCopyBuf],
|
||||
) -> Result<Value, AnyError> {
|
||||
let run_args: RunArgs = serde_json::from_value(args)?;
|
||||
state.borrow::<Permissions>().run.check()?;
|
||||
|
||||
let args = run_args.cmd;
|
||||
|
@ -179,16 +177,15 @@ fn op_run(
|
|||
|
||||
#[derive(Deserialize)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
struct RunStatusArgs {
|
||||
pub struct RunStatusArgs {
|
||||
rid: i32,
|
||||
}
|
||||
|
||||
async fn op_run_status(
|
||||
state: Rc<RefCell<OpState>>,
|
||||
args: Value,
|
||||
args: RunStatusArgs,
|
||||
_zero_copy: BufVec,
|
||||
) -> Result<Value, AnyError> {
|
||||
let args: RunStatusArgs = serde_json::from_value(args)?;
|
||||
let rid = args.rid as u32;
|
||||
|
||||
{
|
||||
|
@ -281,13 +278,12 @@ struct KillArgs {
|
|||
|
||||
fn op_kill(
|
||||
state: &mut OpState,
|
||||
args: Value,
|
||||
args: KillArgs,
|
||||
_zero_copy: &mut [ZeroCopyBuf],
|
||||
) -> Result<Value, AnyError> {
|
||||
super::check_unstable(state, "Deno.kill");
|
||||
state.borrow::<Permissions>().run.check()?;
|
||||
|
||||
let args: KillArgs = serde_json::from_value(args)?;
|
||||
kill(args.pid, args.signo)?;
|
||||
Ok(json!({}))
|
||||
}
|
||||
|
|
|
@ -11,8 +11,6 @@ use std::rc::Rc;
|
|||
#[cfg(unix)]
|
||||
use deno_core::error::bad_resource_id;
|
||||
#[cfg(unix)]
|
||||
use deno_core::serde_json;
|
||||
#[cfg(unix)]
|
||||
use deno_core::serde_json::json;
|
||||
#[cfg(unix)]
|
||||
use deno_core::AsyncRefCell;
|
||||
|
@ -58,24 +56,24 @@ impl Resource for SignalStreamResource {
|
|||
|
||||
#[cfg(unix)]
|
||||
#[derive(Deserialize)]
|
||||
struct BindSignalArgs {
|
||||
pub struct BindSignalArgs {
|
||||
signo: i32,
|
||||
}
|
||||
|
||||
#[cfg(unix)]
|
||||
#[derive(Deserialize)]
|
||||
struct SignalArgs {
|
||||
pub struct SignalArgs {
|
||||
rid: i32,
|
||||
}
|
||||
|
||||
#[cfg(unix)]
|
||||
#[allow(clippy::unnecessary_wraps)]
|
||||
fn op_signal_bind(
|
||||
state: &mut OpState,
|
||||
args: Value,
|
||||
args: BindSignalArgs,
|
||||
_zero_copy: &mut [ZeroCopyBuf],
|
||||
) -> Result<Value, AnyError> {
|
||||
super::check_unstable(state, "Deno.signal");
|
||||
let args: BindSignalArgs = serde_json::from_value(args)?;
|
||||
let resource = SignalStreamResource {
|
||||
signal: AsyncRefCell::new(
|
||||
signal(SignalKind::from_raw(args.signo)).expect(""),
|
||||
|
@ -91,11 +89,10 @@ fn op_signal_bind(
|
|||
#[cfg(unix)]
|
||||
async fn op_signal_poll(
|
||||
state: Rc<RefCell<OpState>>,
|
||||
args: Value,
|
||||
args: SignalArgs,
|
||||
_zero_copy: BufVec,
|
||||
) -> Result<Value, AnyError> {
|
||||
super::check_unstable2(&state, "Deno.signal");
|
||||
let args: SignalArgs = serde_json::from_value(args)?;
|
||||
let rid = args.rid as u32;
|
||||
|
||||
let resource = state
|
||||
|
@ -115,11 +112,10 @@ async fn op_signal_poll(
|
|||
#[cfg(unix)]
|
||||
pub fn op_signal_unbind(
|
||||
state: &mut OpState,
|
||||
args: Value,
|
||||
args: SignalArgs,
|
||||
_zero_copy: &mut [ZeroCopyBuf],
|
||||
) -> Result<Value, AnyError> {
|
||||
super::check_unstable(state, "Deno.signal");
|
||||
let args: SignalArgs = serde_json::from_value(args)?;
|
||||
let rid = args.rid as u32;
|
||||
state
|
||||
.resource_table
|
||||
|
|
|
@ -15,7 +15,6 @@ use deno_core::futures;
|
|||
use deno_core::futures::channel::oneshot;
|
||||
use deno_core::futures::FutureExt;
|
||||
use deno_core::futures::TryFutureExt;
|
||||
use deno_core::serde_json;
|
||||
use deno_core::serde_json::json;
|
||||
use deno_core::serde_json::Value;
|
||||
use deno_core::BufVec;
|
||||
|
@ -94,7 +93,7 @@ fn op_global_timer_stop(
|
|||
}
|
||||
|
||||
#[derive(Deserialize)]
|
||||
struct GlobalTimerArgs {
|
||||
pub struct GlobalTimerArgs {
|
||||
timeout: u64,
|
||||
}
|
||||
|
||||
|
@ -105,12 +104,12 @@ struct GlobalTimerArgs {
|
|||
//
|
||||
// See https://github.com/denoland/deno/issues/7599 for more
|
||||
// details.
|
||||
#[allow(clippy::unnecessary_wraps)]
|
||||
fn op_global_timer_start(
|
||||
state: &mut OpState,
|
||||
args: Value,
|
||||
args: GlobalTimerArgs,
|
||||
_zero_copy: &mut [ZeroCopyBuf],
|
||||
) -> Result<Value, AnyError> {
|
||||
let args: GlobalTimerArgs = serde_json::from_value(args)?;
|
||||
let val = args.timeout;
|
||||
|
||||
let deadline = Instant::now() + Duration::from_millis(val);
|
||||
|
@ -170,17 +169,17 @@ fn op_now(
|
|||
}
|
||||
|
||||
#[derive(Deserialize)]
|
||||
struct SleepArgs {
|
||||
pub struct SleepArgs {
|
||||
millis: u64,
|
||||
}
|
||||
|
||||
#[allow(clippy::unnecessary_wraps)]
|
||||
fn op_sleep_sync(
|
||||
state: &mut OpState,
|
||||
args: Value,
|
||||
args: SleepArgs,
|
||||
_zero_copy: &mut [ZeroCopyBuf],
|
||||
) -> Result<Value, AnyError> {
|
||||
super::check_unstable(state, "Deno.sleepSync");
|
||||
let args: SleepArgs = serde_json::from_value(args)?;
|
||||
sleep(Duration::from_millis(args.millis));
|
||||
Ok(json!({}))
|
||||
}
|
||||
|
|
|
@ -11,7 +11,6 @@ use deno_core::error::bad_resource_id;
|
|||
use deno_core::error::custom_error;
|
||||
use deno_core::error::generic_error;
|
||||
use deno_core::error::AnyError;
|
||||
use deno_core::serde_json;
|
||||
use deno_core::serde_json::json;
|
||||
use deno_core::serde_json::Value;
|
||||
use deno_core::AsyncRefCell;
|
||||
|
@ -79,7 +78,7 @@ pub fn init(rt: &mut deno_core::JsRuntime) {
|
|||
|
||||
#[derive(Deserialize)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
struct ConnectTLSArgs {
|
||||
pub struct ConnectTLSArgs {
|
||||
transport: String,
|
||||
hostname: String,
|
||||
port: u16,
|
||||
|
@ -96,10 +95,9 @@ struct StartTLSArgs {
|
|||
|
||||
async fn op_start_tls(
|
||||
state: Rc<RefCell<OpState>>,
|
||||
args: Value,
|
||||
args: StartTLSArgs,
|
||||
_zero_copy: BufVec,
|
||||
) -> Result<Value, AnyError> {
|
||||
let args: StartTLSArgs = serde_json::from_value(args)?;
|
||||
let rid = args.rid as u32;
|
||||
|
||||
let mut domain = args.hostname.as_str();
|
||||
|
@ -167,10 +165,9 @@ async fn op_start_tls(
|
|||
|
||||
async fn op_connect_tls(
|
||||
state: Rc<RefCell<OpState>>,
|
||||
args: Value,
|
||||
args: ConnectTLSArgs,
|
||||
_zero_copy: BufVec,
|
||||
) -> Result<Value, AnyError> {
|
||||
let args: ConnectTLSArgs = serde_json::from_value(args)?;
|
||||
{
|
||||
let s = state.borrow();
|
||||
let permissions = s.borrow::<Permissions>();
|
||||
|
@ -298,7 +295,7 @@ impl Resource for TlsListenerResource {
|
|||
|
||||
#[derive(Deserialize)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
struct ListenTlsArgs {
|
||||
pub struct ListenTlsArgs {
|
||||
transport: String,
|
||||
hostname: String,
|
||||
port: u16,
|
||||
|
@ -308,10 +305,9 @@ struct ListenTlsArgs {
|
|||
|
||||
fn op_listen_tls(
|
||||
state: &mut OpState,
|
||||
args: Value,
|
||||
args: ListenTlsArgs,
|
||||
_zero_copy: &mut [ZeroCopyBuf],
|
||||
) -> Result<Value, AnyError> {
|
||||
let args: ListenTlsArgs = serde_json::from_value(args)?;
|
||||
assert_eq!(args.transport, "tcp");
|
||||
|
||||
let cert_file = args.cert_file;
|
||||
|
@ -353,16 +349,15 @@ fn op_listen_tls(
|
|||
}
|
||||
|
||||
#[derive(Deserialize)]
|
||||
struct AcceptTlsArgs {
|
||||
pub struct AcceptTlsArgs {
|
||||
rid: i32,
|
||||
}
|
||||
|
||||
async fn op_accept_tls(
|
||||
state: Rc<RefCell<OpState>>,
|
||||
args: Value,
|
||||
args: AcceptTlsArgs,
|
||||
_zero_copy: BufVec,
|
||||
) -> Result<Value, AnyError> {
|
||||
let args: AcceptTlsArgs = serde_json::from_value(args)?;
|
||||
let rid = args.rid as u32;
|
||||
|
||||
let resource = state
|
||||
|
|
|
@ -5,7 +5,6 @@ use deno_core::error::bad_resource_id;
|
|||
use deno_core::error::not_supported;
|
||||
use deno_core::error::resource_unavailable;
|
||||
use deno_core::error::AnyError;
|
||||
use deno_core::serde_json;
|
||||
use deno_core::serde_json::json;
|
||||
use deno_core::serde_json::Value;
|
||||
use deno_core::OpState;
|
||||
|
@ -53,12 +52,12 @@ pub fn init(rt: &mut deno_core::JsRuntime) {
|
|||
|
||||
#[derive(Deserialize)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
struct SetRawOptions {
|
||||
pub struct SetRawOptions {
|
||||
cbreak: bool,
|
||||
}
|
||||
|
||||
#[derive(Deserialize)]
|
||||
struct SetRawArgs {
|
||||
pub struct SetRawArgs {
|
||||
rid: u32,
|
||||
mode: bool,
|
||||
options: SetRawOptions,
|
||||
|
@ -66,12 +65,11 @@ struct SetRawArgs {
|
|||
|
||||
fn op_set_raw(
|
||||
state: &mut OpState,
|
||||
args: Value,
|
||||
args: SetRawArgs,
|
||||
_zero_copy: &mut [ZeroCopyBuf],
|
||||
) -> Result<Value, AnyError> {
|
||||
super::check_unstable(state, "Deno.setRaw");
|
||||
|
||||
let args: SetRawArgs = serde_json::from_value(args)?;
|
||||
let rid = args.rid;
|
||||
let is_raw = args.mode;
|
||||
let cbreak = args.options.cbreak;
|
||||
|
@ -216,16 +214,15 @@ fn op_set_raw(
|
|||
}
|
||||
|
||||
#[derive(Deserialize)]
|
||||
struct IsattyArgs {
|
||||
pub struct IsattyArgs {
|
||||
rid: u32,
|
||||
}
|
||||
|
||||
fn op_isatty(
|
||||
state: &mut OpState,
|
||||
args: Value,
|
||||
args: IsattyArgs,
|
||||
_zero_copy: &mut [ZeroCopyBuf],
|
||||
) -> Result<Value, AnyError> {
|
||||
let args: IsattyArgs = serde_json::from_value(args)?;
|
||||
let rid = args.rid;
|
||||
|
||||
let isatty: bool =
|
||||
|
@ -253,7 +250,7 @@ fn op_isatty(
|
|||
}
|
||||
|
||||
#[derive(Deserialize)]
|
||||
struct ConsoleSizeArgs {
|
||||
pub struct ConsoleSizeArgs {
|
||||
rid: u32,
|
||||
}
|
||||
|
||||
|
@ -265,12 +262,11 @@ struct ConsoleSize {
|
|||
|
||||
fn op_console_size(
|
||||
state: &mut OpState,
|
||||
args: Value,
|
||||
args: ConsoleSizeArgs,
|
||||
_zero_copy: &mut [ZeroCopyBuf],
|
||||
) -> Result<Value, AnyError> {
|
||||
) -> Result<ConsoleSize, AnyError> {
|
||||
super::check_unstable(state, "Deno.consoleSize");
|
||||
|
||||
let args: ConsoleSizeArgs = serde_json::from_value(args)?;
|
||||
let rid = args.rid;
|
||||
|
||||
let size = StdFileResource::with(state, rid as u32, move |r| match r {
|
||||
|
@ -321,5 +317,5 @@ fn op_console_size(
|
|||
Err(_) => Err(bad_resource_id()),
|
||||
})?;
|
||||
|
||||
Ok(json!(size))
|
||||
Ok(size)
|
||||
}
|
||||
|
|
|
@ -22,7 +22,6 @@ use deno_core::serde::de;
|
|||
use deno_core::serde::de::SeqAccess;
|
||||
use deno_core::serde::Deserialize;
|
||||
use deno_core::serde::Deserializer;
|
||||
use deno_core::serde_json;
|
||||
use deno_core::serde_json::json;
|
||||
use deno_core::serde_json::Value;
|
||||
use deno_core::BufVec;
|
||||
|
@ -96,9 +95,8 @@ pub fn init(
|
|||
super::reg_json_sync(
|
||||
rt,
|
||||
"op_host_unhandled_error",
|
||||
move |_state, args, _zero_copy| {
|
||||
move |_state, args: HostUnhandledErrorArgs, _zero_copy| {
|
||||
if let Some(mut sender) = sender.clone() {
|
||||
let args: HostUnhandledErrorArgs = serde_json::from_value(args)?;
|
||||
sender
|
||||
.try_send(WorkerEvent::Error(generic_error(args.message)))
|
||||
.expect("Failed to propagate error event to parent worker");
|
||||
|
@ -532,7 +530,7 @@ where
|
|||
|
||||
#[derive(Deserialize)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
struct CreateWorkerArgs {
|
||||
pub struct CreateWorkerArgs {
|
||||
has_source_code: bool,
|
||||
name: Option<String>,
|
||||
permissions: Option<PermissionsArg>,
|
||||
|
@ -544,11 +542,9 @@ struct CreateWorkerArgs {
|
|||
/// Create worker as the host
|
||||
fn op_create_worker(
|
||||
state: &mut OpState,
|
||||
args: Value,
|
||||
args: CreateWorkerArgs,
|
||||
_data: &mut [ZeroCopyBuf],
|
||||
) -> Result<Value, AnyError> {
|
||||
let args: CreateWorkerArgs = serde_json::from_value(args)?;
|
||||
|
||||
let specifier = args.specifier.clone();
|
||||
let maybe_source_code = if args.has_source_code {
|
||||
Some(args.source_code.clone())
|
||||
|
@ -627,16 +623,16 @@ fn op_create_worker(
|
|||
}
|
||||
|
||||
#[derive(Deserialize)]
|
||||
struct WorkerArgs {
|
||||
pub struct WorkerArgs {
|
||||
id: i32,
|
||||
}
|
||||
|
||||
#[allow(clippy::unnecessary_wraps)]
|
||||
fn op_host_terminate_worker(
|
||||
state: &mut OpState,
|
||||
args: Value,
|
||||
args: WorkerArgs,
|
||||
_data: &mut [ZeroCopyBuf],
|
||||
) -> Result<Value, AnyError> {
|
||||
let args: WorkerArgs = serde_json::from_value(args)?;
|
||||
let id = args.id as u32;
|
||||
let worker_thread = state
|
||||
.borrow_mut::<WorkersTable>()
|
||||
|
@ -710,10 +706,9 @@ fn try_remove_and_close(state: Rc<RefCell<OpState>>, id: u32) {
|
|||
/// Get message from guest worker as host
|
||||
async fn op_host_get_message(
|
||||
state: Rc<RefCell<OpState>>,
|
||||
args: Value,
|
||||
args: WorkerArgs,
|
||||
_zero_copy: BufVec,
|
||||
) -> Result<Value, AnyError> {
|
||||
let args: WorkerArgs = serde_json::from_value(args)?;
|
||||
let id = args.id as u32;
|
||||
|
||||
let worker_handle = {
|
||||
|
@ -745,11 +740,10 @@ async fn op_host_get_message(
|
|||
/// Post message to guest worker as host
|
||||
fn op_host_post_message(
|
||||
state: &mut OpState,
|
||||
args: Value,
|
||||
args: WorkerArgs,
|
||||
data: &mut [ZeroCopyBuf],
|
||||
) -> Result<Value, AnyError> {
|
||||
assert_eq!(data.len(), 1, "Invalid number of arguments");
|
||||
let args: WorkerArgs = serde_json::from_value(args)?;
|
||||
let id = args.id as u32;
|
||||
let msg = Vec::from(&*data[0]).into_boxed_slice();
|
||||
|
||||
|
|
Loading…
Reference in a new issue