mirror of
https://github.com/denoland/deno.git
synced 2025-01-03 04:48:52 -05:00
refactor: factor out check_unstable op helper (#7695)
This commit is contained in:
parent
f64a44810e
commit
e1beebc71a
11 changed files with 51 additions and 74 deletions
|
@ -282,10 +282,7 @@ fn op_fdatasync_sync(
|
||||||
args: Value,
|
args: Value,
|
||||||
_zero_copy: &mut [ZeroCopyBuf],
|
_zero_copy: &mut [ZeroCopyBuf],
|
||||||
) -> Result<Value, AnyError> {
|
) -> Result<Value, AnyError> {
|
||||||
{
|
super::check_unstable(state, "Deno.fdatasync");
|
||||||
let cli_state = super::global_state(state);
|
|
||||||
cli_state.check_unstable("Deno.fdatasync");
|
|
||||||
}
|
|
||||||
let args: FdatasyncArgs = serde_json::from_value(args)?;
|
let args: FdatasyncArgs = serde_json::from_value(args)?;
|
||||||
let rid = args.rid as u32;
|
let rid = args.rid as u32;
|
||||||
std_file_resource(state, rid, |r| match r {
|
std_file_resource(state, rid, |r| match r {
|
||||||
|
@ -300,7 +297,7 @@ async fn op_fdatasync_async(
|
||||||
args: Value,
|
args: Value,
|
||||||
_zero_copy: BufVec,
|
_zero_copy: BufVec,
|
||||||
) -> Result<Value, AnyError> {
|
) -> Result<Value, AnyError> {
|
||||||
super::global_state2(&state).check_unstable("Deno.fdatasync");
|
super::check_unstable2(&state, "Deno.fdatasync");
|
||||||
|
|
||||||
let args: FdatasyncArgs = serde_json::from_value(args)?;
|
let args: FdatasyncArgs = serde_json::from_value(args)?;
|
||||||
let rid = args.rid as u32;
|
let rid = args.rid as u32;
|
||||||
|
@ -322,10 +319,7 @@ fn op_fsync_sync(
|
||||||
args: Value,
|
args: Value,
|
||||||
_zero_copy: &mut [ZeroCopyBuf],
|
_zero_copy: &mut [ZeroCopyBuf],
|
||||||
) -> Result<Value, AnyError> {
|
) -> Result<Value, AnyError> {
|
||||||
{
|
super::check_unstable(state, "Deno.fsync");
|
||||||
let cli_state = super::global_state(state);
|
|
||||||
cli_state.check_unstable("Deno.fsync");
|
|
||||||
}
|
|
||||||
let args: FsyncArgs = serde_json::from_value(args)?;
|
let args: FsyncArgs = serde_json::from_value(args)?;
|
||||||
let rid = args.rid as u32;
|
let rid = args.rid as u32;
|
||||||
std_file_resource(state, rid, |r| match r {
|
std_file_resource(state, rid, |r| match r {
|
||||||
|
@ -340,7 +334,7 @@ async fn op_fsync_async(
|
||||||
args: Value,
|
args: Value,
|
||||||
_zero_copy: BufVec,
|
_zero_copy: BufVec,
|
||||||
) -> Result<Value, AnyError> {
|
) -> Result<Value, AnyError> {
|
||||||
super::global_state2(&state).check_unstable("Deno.fsync");
|
super::check_unstable2(&state, "Deno.fsync");
|
||||||
|
|
||||||
let args: FsyncArgs = serde_json::from_value(args)?;
|
let args: FsyncArgs = serde_json::from_value(args)?;
|
||||||
let rid = args.rid as u32;
|
let rid = args.rid as u32;
|
||||||
|
@ -362,10 +356,7 @@ fn op_fstat_sync(
|
||||||
args: Value,
|
args: Value,
|
||||||
_zero_copy: &mut [ZeroCopyBuf],
|
_zero_copy: &mut [ZeroCopyBuf],
|
||||||
) -> Result<Value, AnyError> {
|
) -> Result<Value, AnyError> {
|
||||||
{
|
super::check_unstable(state, "Deno.fstat");
|
||||||
let cli_state = super::global_state(state);
|
|
||||||
cli_state.check_unstable("Deno.fstat");
|
|
||||||
}
|
|
||||||
let args: FstatArgs = serde_json::from_value(args)?;
|
let args: FstatArgs = serde_json::from_value(args)?;
|
||||||
let rid = args.rid as u32;
|
let rid = args.rid as u32;
|
||||||
let metadata = std_file_resource(state, rid, |r| match r {
|
let metadata = std_file_resource(state, rid, |r| match r {
|
||||||
|
@ -380,7 +371,7 @@ async fn op_fstat_async(
|
||||||
args: Value,
|
args: Value,
|
||||||
_zero_copy: BufVec,
|
_zero_copy: BufVec,
|
||||||
) -> Result<Value, AnyError> {
|
) -> Result<Value, AnyError> {
|
||||||
super::global_state2(&state).check_unstable("Deno.fstat");
|
super::check_unstable2(&state, "Deno.fstat");
|
||||||
|
|
||||||
let args: FstatArgs = serde_json::from_value(args)?;
|
let args: FstatArgs = serde_json::from_value(args)?;
|
||||||
let rid = args.rid as u32;
|
let rid = args.rid as u32;
|
||||||
|
@ -404,10 +395,7 @@ fn op_umask(
|
||||||
args: Value,
|
args: Value,
|
||||||
_zero_copy: &mut [ZeroCopyBuf],
|
_zero_copy: &mut [ZeroCopyBuf],
|
||||||
) -> Result<Value, AnyError> {
|
) -> Result<Value, AnyError> {
|
||||||
{
|
super::check_unstable(state, "Deno.umask");
|
||||||
let cli_state = super::global_state(state);
|
|
||||||
cli_state.check_unstable("Deno.umask");
|
|
||||||
}
|
|
||||||
let args: UmaskArgs = serde_json::from_value(args)?;
|
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
|
||||||
|
@ -1134,8 +1122,7 @@ fn op_link_sync(
|
||||||
args: Value,
|
args: Value,
|
||||||
_zero_copy: &mut [ZeroCopyBuf],
|
_zero_copy: &mut [ZeroCopyBuf],
|
||||||
) -> Result<Value, AnyError> {
|
) -> Result<Value, AnyError> {
|
||||||
let cli_state = super::global_state(state);
|
super::check_unstable(state, "Deno.link");
|
||||||
cli_state.check_unstable("Deno.link");
|
|
||||||
let args: LinkArgs = serde_json::from_value(args)?;
|
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);
|
||||||
|
@ -1154,8 +1141,7 @@ async fn op_link_async(
|
||||||
args: Value,
|
args: Value,
|
||||||
_zero_copy: BufVec,
|
_zero_copy: BufVec,
|
||||||
) -> Result<Value, AnyError> {
|
) -> Result<Value, AnyError> {
|
||||||
let cli_state = super::global_state2(&state);
|
super::check_unstable2(&state, "Deno.link");
|
||||||
cli_state.check_unstable("Deno.link");
|
|
||||||
|
|
||||||
let args: LinkArgs = serde_json::from_value(args)?;
|
let args: LinkArgs = serde_json::from_value(args)?;
|
||||||
let oldpath = PathBuf::from(&args.oldpath);
|
let oldpath = PathBuf::from(&args.oldpath);
|
||||||
|
@ -1198,8 +1184,7 @@ fn op_symlink_sync(
|
||||||
args: Value,
|
args: Value,
|
||||||
_zero_copy: &mut [ZeroCopyBuf],
|
_zero_copy: &mut [ZeroCopyBuf],
|
||||||
) -> Result<Value, AnyError> {
|
) -> Result<Value, AnyError> {
|
||||||
let cli_state = super::global_state(state);
|
super::check_unstable(state, "Deno.symlink");
|
||||||
cli_state.check_unstable("Deno.symlink");
|
|
||||||
let args: SymlinkArgs = serde_json::from_value(args)?;
|
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,8 +1235,7 @@ async fn op_symlink_async(
|
||||||
args: Value,
|
args: Value,
|
||||||
_zero_copy: BufVec,
|
_zero_copy: BufVec,
|
||||||
) -> Result<Value, AnyError> {
|
) -> Result<Value, AnyError> {
|
||||||
let cli_state = super::global_state2(&state);
|
super::check_unstable2(&state, "Deno.symlink");
|
||||||
cli_state.check_unstable("Deno.symlink");
|
|
||||||
|
|
||||||
let args: SymlinkArgs = serde_json::from_value(args)?;
|
let args: SymlinkArgs = serde_json::from_value(args)?;
|
||||||
let oldpath = PathBuf::from(&args.oldpath);
|
let oldpath = PathBuf::from(&args.oldpath);
|
||||||
|
@ -1356,10 +1340,7 @@ fn op_ftruncate_sync(
|
||||||
args: Value,
|
args: Value,
|
||||||
_zero_copy: &mut [ZeroCopyBuf],
|
_zero_copy: &mut [ZeroCopyBuf],
|
||||||
) -> Result<Value, AnyError> {
|
) -> Result<Value, AnyError> {
|
||||||
{
|
super::check_unstable(state, "Deno.ftruncate");
|
||||||
let cli_state = super::global_state(state);
|
|
||||||
cli_state.check_unstable("Deno.ftruncate");
|
|
||||||
}
|
|
||||||
let args: FtruncateArgs = serde_json::from_value(args)?;
|
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;
|
||||||
|
@ -1375,7 +1356,7 @@ async fn op_ftruncate_async(
|
||||||
args: Value,
|
args: Value,
|
||||||
_zero_copy: BufVec,
|
_zero_copy: BufVec,
|
||||||
) -> Result<Value, AnyError> {
|
) -> Result<Value, AnyError> {
|
||||||
super::global_state2(&state).check_unstable("Deno.ftruncate");
|
super::check_unstable2(&state, "Deno.ftruncate");
|
||||||
let args: FtruncateArgs = serde_json::from_value(args)?;
|
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;
|
||||||
|
@ -1628,10 +1609,7 @@ fn op_futime_sync(
|
||||||
args: Value,
|
args: Value,
|
||||||
_zero_copy: &mut [ZeroCopyBuf],
|
_zero_copy: &mut [ZeroCopyBuf],
|
||||||
) -> Result<Value, AnyError> {
|
) -> Result<Value, AnyError> {
|
||||||
{
|
super::check_unstable(state, "Deno.futimeSync");
|
||||||
let cli_state = super::global_state(state);
|
|
||||||
cli_state.check_unstable("Deno.futimeSync");
|
|
||||||
}
|
|
||||||
let args: FutimeArgs = serde_json::from_value(args)?;
|
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);
|
||||||
|
@ -1656,8 +1634,7 @@ async fn op_futime_async(
|
||||||
_zero_copy: BufVec,
|
_zero_copy: BufVec,
|
||||||
) -> Result<Value, AnyError> {
|
) -> Result<Value, AnyError> {
|
||||||
let mut state = state.borrow_mut();
|
let mut state = state.borrow_mut();
|
||||||
let cli_state = super::global_state(&state);
|
super::check_unstable(&state, "Deno.futime");
|
||||||
cli_state.check_unstable("Deno.futime");
|
|
||||||
let args: FutimeArgs = serde_json::from_value(args)?;
|
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);
|
||||||
|
@ -1689,8 +1666,7 @@ fn op_utime_sync(
|
||||||
args: Value,
|
args: Value,
|
||||||
_zero_copy: &mut [ZeroCopyBuf],
|
_zero_copy: &mut [ZeroCopyBuf],
|
||||||
) -> Result<Value, AnyError> {
|
) -> Result<Value, AnyError> {
|
||||||
let cli_state = super::global_state(state);
|
super::check_unstable(state, "Deno.utime");
|
||||||
cli_state.check_unstable("Deno.utime");
|
|
||||||
|
|
||||||
let args: UtimeArgs = serde_json::from_value(args)?;
|
let args: UtimeArgs = serde_json::from_value(args)?;
|
||||||
let path = PathBuf::from(&args.path);
|
let path = PathBuf::from(&args.path);
|
||||||
|
@ -1708,8 +1684,7 @@ async fn op_utime_async(
|
||||||
_zero_copy: BufVec,
|
_zero_copy: BufVec,
|
||||||
) -> Result<Value, AnyError> {
|
) -> Result<Value, AnyError> {
|
||||||
let state = state.borrow();
|
let state = state.borrow();
|
||||||
let cli_state = super::global_state(&state);
|
super::check_unstable(&state, "Deno.utime");
|
||||||
cli_state.check_unstable("Deno.utime");
|
|
||||||
|
|
||||||
let args: UtimeArgs = serde_json::from_value(args)?;
|
let args: UtimeArgs = serde_json::from_value(args)?;
|
||||||
let path = PathBuf::from(&args.path);
|
let path = PathBuf::from(&args.path);
|
||||||
|
|
|
@ -58,6 +58,17 @@ where
|
||||||
rt.register_op(name, metrics_op(json_op_sync(op_fn)));
|
rt.register_op(name, metrics_op(json_op_sync(op_fn)));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Helper for checking unstable features. Used for sync ops.
|
||||||
|
pub fn check_unstable(state: &OpState, api_name: &str) {
|
||||||
|
state.borrow::<Arc<GlobalState>>().check_unstable(api_name)
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Helper for checking unstable features. Used for async ops.
|
||||||
|
pub fn check_unstable2(state: &Rc<RefCell<OpState>>, api_name: &str) {
|
||||||
|
let state = state.borrow();
|
||||||
|
state.borrow::<Arc<GlobalState>>().check_unstable(api_name)
|
||||||
|
}
|
||||||
|
|
||||||
/// Helper for extracting the commonly used state. Used for sync ops.
|
/// Helper for extracting the commonly used state. Used for sync ops.
|
||||||
pub fn global_state(state: &OpState) -> Arc<GlobalState> {
|
pub fn global_state(state: &OpState) -> Arc<GlobalState> {
|
||||||
state.borrow::<Arc<GlobalState>>().clone()
|
state.borrow::<Arc<GlobalState>>().clone()
|
||||||
|
|
|
@ -304,8 +304,7 @@ async fn op_connect(
|
||||||
transport_args: ArgsEnum::Unix(args),
|
transport_args: ArgsEnum::Unix(args),
|
||||||
} if transport == "unix" => {
|
} if transport == "unix" => {
|
||||||
let address_path = Path::new(&args.path);
|
let address_path = Path::new(&args.path);
|
||||||
let cli_state = super::global_state2(&state);
|
super::check_unstable2(&state, "Deno.connect");
|
||||||
cli_state.check_unstable("Deno.connect");
|
|
||||||
{
|
{
|
||||||
let state_ = state.borrow();
|
let state_ = state.borrow();
|
||||||
state_.borrow::<Permissions>().check_read(&address_path)?;
|
state_.borrow::<Permissions>().check_read(&address_path)?;
|
||||||
|
@ -349,7 +348,7 @@ fn op_shutdown(
|
||||||
args: Value,
|
args: Value,
|
||||||
_zero_copy: &mut [ZeroCopyBuf],
|
_zero_copy: &mut [ZeroCopyBuf],
|
||||||
) -> Result<Value, AnyError> {
|
) -> Result<Value, AnyError> {
|
||||||
super::global_state(state).check_unstable("Deno.shutdown");
|
super::check_unstable(state, "Deno.shutdown");
|
||||||
|
|
||||||
let args: ShutdownArgs = serde_json::from_value(args)?;
|
let args: ShutdownArgs = serde_json::from_value(args)?;
|
||||||
|
|
||||||
|
@ -493,7 +492,6 @@ fn op_listen(
|
||||||
args: Value,
|
args: Value,
|
||||||
_zero_copy: &mut [ZeroCopyBuf],
|
_zero_copy: &mut [ZeroCopyBuf],
|
||||||
) -> Result<Value, AnyError> {
|
) -> Result<Value, AnyError> {
|
||||||
let cli_state = super::global_state(state);
|
|
||||||
let permissions = state.borrow::<Permissions>();
|
let permissions = state.borrow::<Permissions>();
|
||||||
match serde_json::from_value(args)? {
|
match serde_json::from_value(args)? {
|
||||||
ListenArgs {
|
ListenArgs {
|
||||||
|
@ -502,7 +500,7 @@ fn op_listen(
|
||||||
} => {
|
} => {
|
||||||
{
|
{
|
||||||
if transport == "udp" {
|
if transport == "udp" {
|
||||||
cli_state.check_unstable("Deno.listenDatagram");
|
super::check_unstable(state, "Deno.listenDatagram");
|
||||||
}
|
}
|
||||||
permissions.check_net(&args.hostname, args.port)?;
|
permissions.check_net(&args.hostname, args.port)?;
|
||||||
}
|
}
|
||||||
|
@ -535,10 +533,10 @@ fn op_listen(
|
||||||
let address_path = Path::new(&args.path);
|
let address_path = Path::new(&args.path);
|
||||||
{
|
{
|
||||||
if transport == "unix" {
|
if transport == "unix" {
|
||||||
cli_state.check_unstable("Deno.listen");
|
super::check_unstable(state, "Deno.listen");
|
||||||
}
|
}
|
||||||
if transport == "unixpacket" {
|
if transport == "unixpacket" {
|
||||||
cli_state.check_unstable("Deno.listenDatagram");
|
super::check_unstable(state, "Deno.listenDatagram");
|
||||||
}
|
}
|
||||||
permissions.check_read(&address_path)?;
|
permissions.check_read(&address_path)?;
|
||||||
permissions.check_write(&address_path)?;
|
permissions.check_write(&address_path)?;
|
||||||
|
|
|
@ -122,8 +122,7 @@ fn op_loadavg(
|
||||||
_args: Value,
|
_args: Value,
|
||||||
_zero_copy: &mut [ZeroCopyBuf],
|
_zero_copy: &mut [ZeroCopyBuf],
|
||||||
) -> Result<Value, AnyError> {
|
) -> Result<Value, AnyError> {
|
||||||
let cli_state = super::global_state(state);
|
super::check_unstable(state, "Deno.loadavg");
|
||||||
cli_state.check_unstable("Deno.loadavg");
|
|
||||||
state.borrow::<Permissions>().check_env()?;
|
state.borrow::<Permissions>().check_env()?;
|
||||||
match sys_info::loadavg() {
|
match sys_info::loadavg() {
|
||||||
Ok(loadavg) => Ok(json!([loadavg.one, loadavg.five, loadavg.fifteen])),
|
Ok(loadavg) => Ok(json!([loadavg.one, loadavg.five, loadavg.fifteen])),
|
||||||
|
@ -136,8 +135,7 @@ fn op_hostname(
|
||||||
_args: Value,
|
_args: Value,
|
||||||
_zero_copy: &mut [ZeroCopyBuf],
|
_zero_copy: &mut [ZeroCopyBuf],
|
||||||
) -> Result<Value, AnyError> {
|
) -> Result<Value, AnyError> {
|
||||||
let cli_state = super::global_state(state);
|
super::check_unstable(state, "Deno.hostname");
|
||||||
cli_state.check_unstable("Deno.hostname");
|
|
||||||
state.borrow::<Permissions>().check_env()?;
|
state.borrow::<Permissions>().check_env()?;
|
||||||
let hostname = sys_info::hostname().unwrap_or_else(|_| "".to_string());
|
let hostname = sys_info::hostname().unwrap_or_else(|_| "".to_string());
|
||||||
Ok(json!(hostname))
|
Ok(json!(hostname))
|
||||||
|
@ -148,8 +146,7 @@ fn op_os_release(
|
||||||
_args: Value,
|
_args: Value,
|
||||||
_zero_copy: &mut [ZeroCopyBuf],
|
_zero_copy: &mut [ZeroCopyBuf],
|
||||||
) -> Result<Value, AnyError> {
|
) -> Result<Value, AnyError> {
|
||||||
let cli_state = super::global_state(state);
|
super::check_unstable(state, "Deno.osRelease");
|
||||||
cli_state.check_unstable("Deno.osRelease");
|
|
||||||
state.borrow::<Permissions>().check_env()?;
|
state.borrow::<Permissions>().check_env()?;
|
||||||
let release = sys_info::os_release().unwrap_or_else(|_| "".to_string());
|
let release = sys_info::os_release().unwrap_or_else(|_| "".to_string());
|
||||||
Ok(json!(release))
|
Ok(json!(release))
|
||||||
|
@ -160,8 +157,7 @@ fn op_system_memory_info(
|
||||||
_args: Value,
|
_args: Value,
|
||||||
_zero_copy: &mut [ZeroCopyBuf],
|
_zero_copy: &mut [ZeroCopyBuf],
|
||||||
) -> Result<Value, AnyError> {
|
) -> Result<Value, AnyError> {
|
||||||
let cli_state = super::global_state(state);
|
super::check_unstable(state, "Deno.systemMemoryInfo");
|
||||||
cli_state.check_unstable("Deno.systemMemoryInfo");
|
|
||||||
state.borrow::<Permissions>().check_env()?;
|
state.borrow::<Permissions>().check_env()?;
|
||||||
match sys_info::mem_info() {
|
match sys_info::mem_info() {
|
||||||
Ok(info) => Ok(json!({
|
Ok(info) => Ok(json!({
|
||||||
|
|
|
@ -42,8 +42,7 @@ pub fn op_open_plugin(
|
||||||
let args: OpenPluginArgs = serde_json::from_value(args)?;
|
let args: OpenPluginArgs = serde_json::from_value(args)?;
|
||||||
let filename = PathBuf::from(&args.filename);
|
let filename = PathBuf::from(&args.filename);
|
||||||
|
|
||||||
let cli_state = super::global_state(state);
|
super::check_unstable(state, "Deno.openPlugin");
|
||||||
cli_state.check_unstable("Deno.openPlugin");
|
|
||||||
let permissions = state.borrow::<Permissions>();
|
let permissions = state.borrow::<Permissions>();
|
||||||
permissions.check_plugin(&filename)?;
|
permissions.check_plugin(&filename)?;
|
||||||
|
|
||||||
|
|
|
@ -227,8 +227,7 @@ fn op_kill(
|
||||||
args: Value,
|
args: Value,
|
||||||
_zero_copy: &mut [ZeroCopyBuf],
|
_zero_copy: &mut [ZeroCopyBuf],
|
||||||
) -> Result<Value, AnyError> {
|
) -> Result<Value, AnyError> {
|
||||||
let cli_state = super::global_state(state);
|
super::check_unstable(state, "Deno.kill");
|
||||||
cli_state.check_unstable("Deno.kill");
|
|
||||||
state.borrow::<Permissions>().check_run()?;
|
state.borrow::<Permissions>().check_run()?;
|
||||||
|
|
||||||
let args: KillArgs = serde_json::from_value(args)?;
|
let args: KillArgs = serde_json::from_value(args)?;
|
||||||
|
|
|
@ -34,9 +34,9 @@ async fn op_compile(
|
||||||
args: Value,
|
args: Value,
|
||||||
_data: BufVec,
|
_data: BufVec,
|
||||||
) -> Result<Value, AnyError> {
|
) -> Result<Value, AnyError> {
|
||||||
let cli_state = super::global_state2(&state);
|
super::check_unstable2(&state, "Deno.compile");
|
||||||
cli_state.check_unstable("Deno.compile");
|
|
||||||
let args: CompileArgs = serde_json::from_value(args)?;
|
let args: CompileArgs = serde_json::from_value(args)?;
|
||||||
|
let cli_state = super::global_state2(&state);
|
||||||
let global_state = cli_state.clone();
|
let global_state = cli_state.clone();
|
||||||
let permissions = {
|
let permissions = {
|
||||||
let state = state.borrow();
|
let state = state.borrow();
|
||||||
|
@ -76,9 +76,9 @@ async fn op_transpile(
|
||||||
args: Value,
|
args: Value,
|
||||||
_data: BufVec,
|
_data: BufVec,
|
||||||
) -> Result<Value, AnyError> {
|
) -> Result<Value, AnyError> {
|
||||||
let cli_state = super::global_state2(&state);
|
super::check_unstable2(&state, "Deno.transpile");
|
||||||
cli_state.check_unstable("Deno.transpile");
|
|
||||||
let args: TranspileArgs = serde_json::from_value(args)?;
|
let args: TranspileArgs = serde_json::from_value(args)?;
|
||||||
|
let cli_state = super::global_state2(&state);
|
||||||
let global_state = cli_state.clone();
|
let global_state = cli_state.clone();
|
||||||
let result =
|
let result =
|
||||||
runtime_transpile(global_state, &args.sources, &args.options).await?;
|
runtime_transpile(global_state, &args.sources, &args.options).await?;
|
||||||
|
|
|
@ -52,7 +52,7 @@ fn op_signal_bind(
|
||||||
args: Value,
|
args: Value,
|
||||||
_zero_copy: &mut [ZeroCopyBuf],
|
_zero_copy: &mut [ZeroCopyBuf],
|
||||||
) -> Result<Value, AnyError> {
|
) -> Result<Value, AnyError> {
|
||||||
super::global_state(state).check_unstable("Deno.signal");
|
super::check_unstable(state, "Deno.signal");
|
||||||
let args: BindSignalArgs = serde_json::from_value(args)?;
|
let args: BindSignalArgs = serde_json::from_value(args)?;
|
||||||
let rid = state.resource_table.add(
|
let rid = state.resource_table.add(
|
||||||
"signal",
|
"signal",
|
||||||
|
@ -72,7 +72,7 @@ async fn op_signal_poll(
|
||||||
args: Value,
|
args: Value,
|
||||||
_zero_copy: BufVec,
|
_zero_copy: BufVec,
|
||||||
) -> Result<Value, AnyError> {
|
) -> Result<Value, AnyError> {
|
||||||
super::global_state2(&state).check_unstable("Deno.signal");
|
super::check_unstable2(&state, "Deno.signal");
|
||||||
let args: SignalArgs = serde_json::from_value(args)?;
|
let args: SignalArgs = serde_json::from_value(args)?;
|
||||||
let rid = args.rid as u32;
|
let rid = args.rid as u32;
|
||||||
|
|
||||||
|
@ -96,7 +96,7 @@ pub fn op_signal_unbind(
|
||||||
args: Value,
|
args: Value,
|
||||||
_zero_copy: &mut [ZeroCopyBuf],
|
_zero_copy: &mut [ZeroCopyBuf],
|
||||||
) -> Result<Value, AnyError> {
|
) -> Result<Value, AnyError> {
|
||||||
super::global_state(state).check_unstable("Deno.signal");
|
super::check_unstable(state, "Deno.signal");
|
||||||
let args: SignalArgs = serde_json::from_value(args)?;
|
let args: SignalArgs = serde_json::from_value(args)?;
|
||||||
let rid = args.rid as u32;
|
let rid = args.rid as u32;
|
||||||
let resource = state.resource_table.get_mut::<SignalStreamResource>(rid);
|
let resource = state.resource_table.get_mut::<SignalStreamResource>(rid);
|
||||||
|
|
|
@ -76,8 +76,7 @@ async fn op_start_tls(
|
||||||
domain.push_str("localhost");
|
domain.push_str("localhost");
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
let cli_state = super::global_state2(&state);
|
super::check_unstable2(&state, "Deno.startTls");
|
||||||
cli_state.check_unstable("Deno.startTls");
|
|
||||||
let s = state.borrow();
|
let s = state.borrow();
|
||||||
let permissions = s.borrow::<Permissions>();
|
let permissions = s.borrow::<Permissions>();
|
||||||
permissions.check_net(&domain, 0)?;
|
permissions.check_net(&domain, 0)?;
|
||||||
|
|
|
@ -64,7 +64,7 @@ fn op_set_raw(
|
||||||
args: Value,
|
args: Value,
|
||||||
_zero_copy: &mut [ZeroCopyBuf],
|
_zero_copy: &mut [ZeroCopyBuf],
|
||||||
) -> Result<Value, AnyError> {
|
) -> Result<Value, AnyError> {
|
||||||
super::global_state(state).check_unstable("Deno.setRaw");
|
super::check_unstable(state, "Deno.setRaw");
|
||||||
|
|
||||||
let args: SetRawArgs = serde_json::from_value(args)?;
|
let args: SetRawArgs = serde_json::from_value(args)?;
|
||||||
let rid = args.rid;
|
let rid = args.rid;
|
||||||
|
@ -275,7 +275,7 @@ fn op_console_size(
|
||||||
args: Value,
|
args: Value,
|
||||||
_zero_copy: &mut [ZeroCopyBuf],
|
_zero_copy: &mut [ZeroCopyBuf],
|
||||||
) -> Result<Value, AnyError> {
|
) -> Result<Value, AnyError> {
|
||||||
super::global_state(state).check_unstable("Deno.consoleSize");
|
super::check_unstable(state, "Deno.consoleSize");
|
||||||
|
|
||||||
let args: ConsoleSizeArgs = serde_json::from_value(args)?;
|
let args: ConsoleSizeArgs = serde_json::from_value(args)?;
|
||||||
let rid = args.rid;
|
let rid = args.rid;
|
||||||
|
|
|
@ -184,7 +184,6 @@ fn op_create_worker(
|
||||||
args: Value,
|
args: Value,
|
||||||
_data: &mut [ZeroCopyBuf],
|
_data: &mut [ZeroCopyBuf],
|
||||||
) -> Result<Value, AnyError> {
|
) -> Result<Value, AnyError> {
|
||||||
let cli_state = super::global_state(state);
|
|
||||||
let args: CreateWorkerArgs = serde_json::from_value(args)?;
|
let args: CreateWorkerArgs = serde_json::from_value(args)?;
|
||||||
|
|
||||||
let specifier = args.specifier.clone();
|
let specifier = args.specifier.clone();
|
||||||
|
@ -196,7 +195,7 @@ fn op_create_worker(
|
||||||
let args_name = args.name;
|
let args_name = args.name;
|
||||||
let use_deno_namespace = args.use_deno_namespace;
|
let use_deno_namespace = args.use_deno_namespace;
|
||||||
if use_deno_namespace {
|
if use_deno_namespace {
|
||||||
cli_state.check_unstable("Worker.deno");
|
super::check_unstable(state, "Worker.deno");
|
||||||
}
|
}
|
||||||
let permissions = state.borrow::<Permissions>().clone();
|
let permissions = state.borrow::<Permissions>().clone();
|
||||||
let worker_id = state.take::<WorkerId>();
|
let worker_id = state.take::<WorkerId>();
|
||||||
|
@ -204,6 +203,7 @@ fn op_create_worker(
|
||||||
|
|
||||||
let module_specifier = ModuleSpecifier::resolve_url(&specifier)?;
|
let module_specifier = ModuleSpecifier::resolve_url(&specifier)?;
|
||||||
let worker_name = args_name.unwrap_or_else(|| "".to_string());
|
let worker_name = args_name.unwrap_or_else(|| "".to_string());
|
||||||
|
let cli_state = super::global_state(state);
|
||||||
|
|
||||||
let (join_handle, worker_handle) = run_worker_thread(
|
let (join_handle, worker_handle) = run_worker_thread(
|
||||||
worker_id,
|
worker_id,
|
||||||
|
|
Loading…
Reference in a new issue