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