summaryrefslogtreecommitdiff
path: root/runtime
diff options
context:
space:
mode:
authorDivy Srivastava <dj.srivastava23@gmail.com>2022-03-14 23:14:15 +0530
committerGitHub <noreply@github.com>2022-03-14 18:44:15 +0100
commitb4e42953e1d243f2eda20e5be6b845d60b7bf688 (patch)
tree10b3bfff165f9c04f9174c7c399d44b9b724c3b3 /runtime
parent4e3ed37037a2aa1edeac260dc3463a81d9cf9b88 (diff)
feat(core): codegen ops (#13861)
Co-authored-by: Aaron O'Mullan <aaron.omullan@gmail.com>
Diffstat (limited to 'runtime')
-rw-r--r--runtime/ops/fs.rs163
-rw-r--r--runtime/ops/fs_events.rs11
-rw-r--r--runtime/ops/http.rs5
-rw-r--r--runtime/ops/io.rs9
-rw-r--r--runtime/ops/os.rs42
-rw-r--r--runtime/ops/permissions.rs11
-rw-r--r--runtime/ops/process.rs13
-rw-r--r--runtime/ops/runtime.rs5
-rw-r--r--runtime/ops/signal.rs16
-rw-r--r--runtime/ops/tty.rs11
-rw-r--r--runtime/ops/web_worker.rs18
-rw-r--r--runtime/ops/web_worker/sync_fetch.rs2
-rw-r--r--runtime/ops/worker_host.rs22
13 files changed, 207 insertions, 121 deletions
diff --git a/runtime/ops/fs.rs b/runtime/ops/fs.rs
index bc84cffb1..f7f0ad33c 100644
--- a/runtime/ops/fs.rs
+++ b/runtime/ops/fs.rs
@@ -8,8 +8,8 @@ use deno_core::error::bad_resource_id;
use deno_core::error::custom_error;
use deno_core::error::type_error;
use deno_core::error::AnyError;
-use deno_core::op_async;
-use deno_core::op_sync;
+use deno_core::op;
+
use deno_core::Extension;
use deno_core::OpState;
use deno_core::RcRef;
@@ -38,59 +38,59 @@ use deno_core::error::not_supported;
pub fn init() -> Extension {
Extension::builder()
.ops(vec![
- ("op_open_sync", op_sync(op_open_sync)),
- ("op_open_async", op_async(op_open_async)),
- ("op_seek_sync", op_sync(op_seek_sync)),
- ("op_seek_async", op_async(op_seek_async)),
- ("op_fdatasync_sync", op_sync(op_fdatasync_sync)),
- ("op_fdatasync_async", op_async(op_fdatasync_async)),
- ("op_fsync_sync", op_sync(op_fsync_sync)),
- ("op_fsync_async", op_async(op_fsync_async)),
- ("op_fstat_sync", op_sync(op_fstat_sync)),
- ("op_fstat_async", op_async(op_fstat_async)),
- ("op_flock_sync", op_sync(op_flock_sync)),
- ("op_flock_async", op_async(op_flock_async)),
- ("op_funlock_sync", op_sync(op_funlock_sync)),
- ("op_funlock_async", op_async(op_funlock_async)),
- ("op_umask", op_sync(op_umask)),
- ("op_chdir", op_sync(op_chdir)),
- ("op_mkdir_sync", op_sync(op_mkdir_sync)),
- ("op_mkdir_async", op_async(op_mkdir_async)),
- ("op_chmod_sync", op_sync(op_chmod_sync)),
- ("op_chmod_async", op_async(op_chmod_async)),
- ("op_chown_sync", op_sync(op_chown_sync)),
- ("op_chown_async", op_async(op_chown_async)),
- ("op_remove_sync", op_sync(op_remove_sync)),
- ("op_remove_async", op_async(op_remove_async)),
- ("op_copy_file_sync", op_sync(op_copy_file_sync)),
- ("op_copy_file_async", op_async(op_copy_file_async)),
- ("op_stat_sync", op_sync(op_stat_sync)),
- ("op_stat_async", op_async(op_stat_async)),
- ("op_realpath_sync", op_sync(op_realpath_sync)),
- ("op_realpath_async", op_async(op_realpath_async)),
- ("op_read_dir_sync", op_sync(op_read_dir_sync)),
- ("op_read_dir_async", op_async(op_read_dir_async)),
- ("op_rename_sync", op_sync(op_rename_sync)),
- ("op_rename_async", op_async(op_rename_async)),
- ("op_link_sync", op_sync(op_link_sync)),
- ("op_link_async", op_async(op_link_async)),
- ("op_symlink_sync", op_sync(op_symlink_sync)),
- ("op_symlink_async", op_async(op_symlink_async)),
- ("op_read_link_sync", op_sync(op_read_link_sync)),
- ("op_read_link_async", op_async(op_read_link_async)),
- ("op_ftruncate_sync", op_sync(op_ftruncate_sync)),
- ("op_ftruncate_async", op_async(op_ftruncate_async)),
- ("op_truncate_sync", op_sync(op_truncate_sync)),
- ("op_truncate_async", op_async(op_truncate_async)),
- ("op_make_temp_dir_sync", op_sync(op_make_temp_dir_sync)),
- ("op_make_temp_dir_async", op_async(op_make_temp_dir_async)),
- ("op_make_temp_file_sync", op_sync(op_make_temp_file_sync)),
- ("op_make_temp_file_async", op_async(op_make_temp_file_async)),
- ("op_cwd", op_sync(op_cwd)),
- ("op_futime_sync", op_sync(op_futime_sync)),
- ("op_futime_async", op_async(op_futime_async)),
- ("op_utime_sync", op_sync(op_utime_sync)),
- ("op_utime_async", op_async(op_utime_async)),
+ op_open_sync::decl(),
+ op_open_async::decl(),
+ op_seek_sync::decl(),
+ op_seek_async::decl(),
+ op_fdatasync_sync::decl(),
+ op_fdatasync_async::decl(),
+ op_fsync_sync::decl(),
+ op_fsync_async::decl(),
+ op_fstat_sync::decl(),
+ op_fstat_async::decl(),
+ op_flock_sync::decl(),
+ op_flock_async::decl(),
+ op_funlock_sync::decl(),
+ op_funlock_async::decl(),
+ op_umask::decl(),
+ op_chdir::decl(),
+ op_mkdir_sync::decl(),
+ op_mkdir_async::decl(),
+ op_chmod_sync::decl(),
+ op_chmod_async::decl(),
+ op_chown_sync::decl(),
+ op_chown_async::decl(),
+ op_remove_sync::decl(),
+ op_remove_async::decl(),
+ op_copy_file_sync::decl(),
+ op_copy_file_async::decl(),
+ op_stat_sync::decl(),
+ op_stat_async::decl(),
+ op_realpath_sync::decl(),
+ op_realpath_async::decl(),
+ op_read_dir_sync::decl(),
+ op_read_dir_async::decl(),
+ op_rename_sync::decl(),
+ op_rename_async::decl(),
+ op_link_sync::decl(),
+ op_link_async::decl(),
+ op_symlink_sync::decl(),
+ op_symlink_async::decl(),
+ op_read_link_sync::decl(),
+ op_read_link_async::decl(),
+ op_ftruncate_sync::decl(),
+ op_ftruncate_async::decl(),
+ op_truncate_sync::decl(),
+ op_truncate_async::decl(),
+ op_make_temp_dir_sync::decl(),
+ op_make_temp_dir_async::decl(),
+ op_make_temp_file_sync::decl(),
+ op_make_temp_file_async::decl(),
+ op_cwd::decl(),
+ op_futime_sync::decl(),
+ op_futime_async::decl(),
+ op_utime_sync::decl(),
+ op_utime_async::decl(),
])
.build()
}
@@ -157,6 +157,7 @@ fn open_helper(
Ok((path, open_options))
}
+#[op]
fn op_open_sync(
state: &mut OpState,
args: OpenArgs,
@@ -172,6 +173,7 @@ fn op_open_sync(
Ok(rid)
}
+#[op]
async fn op_open_async(
state: Rc<RefCell<OpState>>,
args: OpenArgs,
@@ -214,6 +216,7 @@ fn seek_helper(args: SeekArgs) -> Result<(u32, SeekFrom), AnyError> {
Ok((rid, seek_from))
}
+#[op]
fn op_seek_sync(
state: &mut OpState,
args: SeekArgs,
@@ -229,6 +232,7 @@ fn op_seek_sync(
Ok(pos)
}
+#[op]
async fn op_seek_async(
state: Rc<RefCell<OpState>>,
args: SeekArgs,
@@ -253,6 +257,7 @@ async fn op_seek_async(
Ok(pos)
}
+#[op]
fn op_fdatasync_sync(
state: &mut OpState,
rid: ResourceId,
@@ -265,6 +270,7 @@ fn op_fdatasync_sync(
Ok(())
}
+#[op]
async fn op_fdatasync_async(
state: Rc<RefCell<OpState>>,
rid: ResourceId,
@@ -287,6 +293,7 @@ async fn op_fdatasync_async(
Ok(())
}
+#[op]
fn op_fsync_sync(
state: &mut OpState,
rid: ResourceId,
@@ -299,6 +306,7 @@ fn op_fsync_sync(
Ok(())
}
+#[op]
async fn op_fsync_async(
state: Rc<RefCell<OpState>>,
rid: ResourceId,
@@ -321,6 +329,7 @@ async fn op_fsync_async(
Ok(())
}
+#[op]
fn op_fstat_sync(
state: &mut OpState,
rid: ResourceId,
@@ -333,6 +342,7 @@ fn op_fstat_sync(
Ok(get_stat(metadata))
}
+#[op]
async fn op_fstat_async(
state: Rc<RefCell<OpState>>,
rid: ResourceId,
@@ -355,6 +365,7 @@ async fn op_fstat_async(
Ok(get_stat(metadata))
}
+#[op]
fn op_flock_sync(
state: &mut OpState,
rid: ResourceId,
@@ -376,6 +387,7 @@ fn op_flock_sync(
})
}
+#[op]
async fn op_flock_async(
state: Rc<RefCell<OpState>>,
rid: ResourceId,
@@ -416,6 +428,7 @@ async fn op_flock_async(
.await?
}
+#[op]
fn op_funlock_sync(
state: &mut OpState,
rid: ResourceId,
@@ -433,6 +446,7 @@ fn op_funlock_sync(
})
}
+#[op]
async fn op_funlock_async(
state: Rc<RefCell<OpState>>,
rid: ResourceId,
@@ -469,6 +483,7 @@ async fn op_funlock_async(
.await?
}
+#[op]
fn op_umask(
state: &mut OpState,
mask: Option<u32>,
@@ -501,6 +516,7 @@ fn op_umask(
}
}
+#[op]
fn op_chdir(
state: &mut OpState,
directory: String,
@@ -522,6 +538,7 @@ pub struct MkdirArgs {
mode: Option<u32>,
}
+#[op]
fn op_mkdir_sync(
state: &mut OpState,
args: MkdirArgs,
@@ -544,6 +561,7 @@ fn op_mkdir_sync(
Ok(())
}
+#[op]
async fn op_mkdir_async(
state: Rc<RefCell<OpState>>,
args: MkdirArgs,
@@ -582,6 +600,7 @@ pub struct ChmodArgs {
mode: u32,
}
+#[op]
fn op_chmod_sync(
state: &mut OpState,
args: ChmodArgs,
@@ -611,6 +630,7 @@ fn op_chmod_sync(
}
}
+#[op]
async fn op_chmod_async(
state: Rc<RefCell<OpState>>,
args: ChmodArgs,
@@ -656,6 +676,7 @@ pub struct ChownArgs {
gid: Option<u32>,
}
+#[op]
fn op_chown_sync(
state: &mut OpState,
args: ChownArgs,
@@ -690,6 +711,7 @@ fn op_chown_sync(
}
}
+#[op]
async fn op_chown_async(
state: Rc<RefCell<OpState>>,
args: ChownArgs,
@@ -738,6 +760,7 @@ pub struct RemoveArgs {
recursive: bool,
}
+#[op]
fn op_remove_sync(
state: &mut OpState,
args: RemoveArgs,
@@ -783,6 +806,7 @@ fn op_remove_sync(
Ok(())
}
+#[op]
async fn op_remove_async(
state: Rc<RefCell<OpState>>,
args: RemoveArgs,
@@ -841,6 +865,7 @@ pub struct CopyFileArgs {
to: String,
}
+#[op]
fn op_copy_file_sync(
state: &mut OpState,
args: CopyFileArgs,
@@ -879,6 +904,7 @@ fn op_copy_file_sync(
Ok(())
}
+#[op]
async fn op_copy_file_async(
state: Rc<RefCell<OpState>>,
args: CopyFileArgs,
@@ -1007,6 +1033,7 @@ pub struct StatArgs {
lstat: bool,
}
+#[op]
fn op_stat_sync(
state: &mut OpState,
args: StatArgs,
@@ -1027,6 +1054,7 @@ fn op_stat_sync(
Ok(get_stat(metadata))
}
+#[op]
async fn op_stat_async(
state: Rc<RefCell<OpState>>,
args: StatArgs,
@@ -1056,6 +1084,7 @@ async fn op_stat_async(
.unwrap()
}
+#[op]
fn op_realpath_sync(
state: &mut OpState,
path: String,
@@ -1077,6 +1106,7 @@ fn op_realpath_sync(
Ok(realpath_str)
}
+#[op]
async fn op_realpath_async(
state: Rc<RefCell<OpState>>,
path: String,
@@ -1114,6 +1144,7 @@ pub struct DirEntry {
is_symlink: bool,
}
+#[op]
fn op_read_dir_sync(
state: &mut OpState,
path: String,
@@ -1154,6 +1185,7 @@ fn op_read_dir_sync(
Ok(entries)
}
+#[op]
async fn op_read_dir_async(
state: Rc<RefCell<OpState>>,
path: String,
@@ -1206,6 +1238,7 @@ pub struct RenameArgs {
newpath: String,
}
+#[op]
fn op_rename_sync(
state: &mut OpState,
args: RenameArgs,
@@ -1234,6 +1267,7 @@ fn op_rename_sync(
Ok(())
}
+#[op]
async fn op_rename_async(
state: Rc<RefCell<OpState>>,
args: RenameArgs,
@@ -1279,6 +1313,7 @@ pub struct LinkArgs {
newpath: String,
}
+#[op]
fn op_link_sync(
state: &mut OpState,
args: LinkArgs,
@@ -1309,6 +1344,7 @@ fn op_link_sync(
Ok(())
}
+#[op]
async fn op_link_async(
state: Rc<RefCell<OpState>>,
args: LinkArgs,
@@ -1362,6 +1398,7 @@ pub struct SymlinkOptions {
_type: String,
}
+#[op]
fn op_symlink_sync(
state: &mut OpState,
args: SymlinkArgs,
@@ -1423,6 +1460,7 @@ fn op_symlink_sync(
}
}
+#[op]
async fn op_symlink_async(
state: Rc<RefCell<OpState>>,
args: SymlinkArgs,
@@ -1487,6 +1525,7 @@ async fn op_symlink_async(
.unwrap()
}
+#[op]
fn op_read_link_sync(
state: &mut OpState,
path: String,
@@ -1510,6 +1549,7 @@ fn op_read_link_sync(
Ok(targetstr)
}
+#[op]
async fn op_read_link_async(
state: Rc<RefCell<OpState>>,
path: String,
@@ -1545,6 +1585,7 @@ pub struct FtruncateArgs {
len: i32,
}
+#[op]
fn op_ftruncate_sync(
state: &mut OpState,
args: FtruncateArgs,
@@ -1559,6 +1600,7 @@ fn op_ftruncate_sync(
Ok(())
}
+#[op]
async fn op_ftruncate_async(
state: Rc<RefCell<OpState>>,
args: FtruncateArgs,
@@ -1591,6 +1633,7 @@ pub struct TruncateArgs {
len: u64,
}
+#[op]
fn op_truncate_sync(
state: &mut OpState,
args: TruncateArgs,
@@ -1616,6 +1659,7 @@ fn op_truncate_sync(
Ok(())
}
+#[op]
async fn op_truncate_async(
state: Rc<RefCell<OpState>>,
args: TruncateArgs,
@@ -1699,6 +1743,7 @@ pub struct MakeTempArgs {
suffix: Option<String>,
}
+#[op]
fn op_make_temp_dir_sync(
state: &mut OpState,
args: MakeTempArgs,
@@ -1728,6 +1773,7 @@ fn op_make_temp_dir_sync(
Ok(path_str)
}
+#[op]
async fn op_make_temp_dir_async(
state: Rc<RefCell<OpState>>,
args: MakeTempArgs,
@@ -1762,6 +1808,7 @@ async fn op_make_temp_dir_async(
.unwrap()
}
+#[op]
fn op_make_temp_file_sync(
state: &mut OpState,
args: MakeTempArgs,
@@ -1791,6 +1838,7 @@ fn op_make_temp_file_sync(
Ok(path_str)
}
+#[op]
async fn op_make_temp_file_async(
state: Rc<RefCell<OpState>>,
args: MakeTempArgs,
@@ -1833,6 +1881,7 @@ pub struct FutimeArgs {
mtime: (i64, u32),
}
+#[op]
fn op_futime_sync(
state: &mut OpState,
args: FutimeArgs,
@@ -1856,6 +1905,7 @@ fn op_futime_sync(
Ok(())
}
+#[op]
async fn op_futime_async(
state: Rc<RefCell<OpState>>,
args: FutimeArgs,
@@ -1904,6 +1954,7 @@ pub struct UtimeArgs {
mtime: (i64, u32),
}
+#[op]
fn op_utime_sync(
state: &mut OpState,
args: UtimeArgs,
@@ -1922,6 +1973,7 @@ fn op_utime_sync(
Ok(())
}
+#[op]
async fn op_utime_async(
state: Rc<RefCell<OpState>>,
args: UtimeArgs,
@@ -1949,6 +2001,7 @@ async fn op_utime_async(
.unwrap()
}
+#[op]
fn op_cwd(state: &mut OpState, _: (), _: ()) -> Result<String, AnyError> {
let path = current_dir()?;
state
diff --git a/runtime/ops/fs_events.rs b/runtime/ops/fs_events.rs
index 89ded2731..8909b2636 100644
--- a/runtime/ops/fs_events.rs
+++ b/runtime/ops/fs_events.rs
@@ -11,8 +11,8 @@ use deno_core::RcRef;
use deno_core::Resource;
use deno_core::ResourceId;
-use deno_core::op_async;
-use deno_core::op_sync;
+use deno_core::op;
+
use deno_core::Extension;
use notify::event::Event as NotifyEvent;
use notify::Error as NotifyError;
@@ -31,10 +31,7 @@ use tokio::sync::mpsc;
pub fn init() -> Extension {
Extension::builder()
- .ops(vec![
- ("op_fs_events_open", op_sync(op_fs_events_open)),
- ("op_fs_events_poll", op_async(op_fs_events_poll)),
- ])
+ .ops(vec![op_fs_events_open::decl(), op_fs_events_poll::decl()])
.build()
}
@@ -97,6 +94,7 @@ pub struct OpenArgs {
paths: Vec<String>,
}
+#[op]
fn op_fs_events_open(
state: &mut OpState,
args: OpenArgs,
@@ -131,6 +129,7 @@ fn op_fs_events_open(
Ok(rid)
}
+#[op]
async fn op_fs_events_poll(
state: Rc<RefCell<OpState>>,
rid: ResourceId,
diff --git a/runtime/ops/http.rs b/runtime/ops/http.rs
index 5b8acb881..25f123b32 100644
--- a/runtime/ops/http.rs
+++ b/runtime/ops/http.rs
@@ -2,7 +2,7 @@ use std::rc::Rc;
use deno_core::error::bad_resource_id;
use deno_core::error::AnyError;
-use deno_core::op_sync;
+use deno_core::op;
use deno_core::Extension;
use deno_core::OpState;
use deno_core::ResourceId;
@@ -12,10 +12,11 @@ use deno_net::ops_tls::TlsStreamResource;
pub fn init() -> Extension {
Extension::builder()
- .ops(vec![("op_http_start", op_sync(op_http_start))])
+ .ops(vec![op_http_start::decl()])
.build()
}
+#[op]
fn op_http_start(
state: &mut OpState,
tcp_stream_rid: ResourceId,
diff --git a/runtime/ops/io.rs b/runtime/ops/io.rs
index 61f1a2578..35dddaac2 100644
--- a/runtime/ops/io.rs
+++ b/runtime/ops/io.rs
@@ -3,7 +3,7 @@
use deno_core::error::not_supported;
use deno_core::error::resource_unavailable;
use deno_core::error::AnyError;
-use deno_core::op_sync;
+use deno_core::op;
use deno_core::AsyncMutFuture;
use deno_core::AsyncRefCell;
use deno_core::AsyncResult;
@@ -69,10 +69,7 @@ static STDERR_HANDLE: Lazy<StdFile> = Lazy::new(|| unsafe {
pub fn init() -> Extension {
Extension::builder()
- .ops(vec![
- ("op_read_sync", op_sync(op_read_sync)),
- ("op_write_sync", op_sync(op_write_sync)),
- ])
+ .ops(vec![op_read_sync::decl(), op_write_sync::decl()])
.build()
}
@@ -354,6 +351,7 @@ impl Resource for StdFileResource {
}
}
+#[op]
fn op_read_sync(
state: &mut OpState,
rid: ResourceId,
@@ -368,6 +366,7 @@ fn op_read_sync(
})
}
+#[op]
fn op_write_sync(
state: &mut OpState,
rid: ResourceId,
diff --git a/runtime/ops/os.rs b/runtime/ops/os.rs
index 405faf45a..d9abbb221 100644
--- a/runtime/ops/os.rs
+++ b/runtime/ops/os.rs
@@ -3,7 +3,7 @@
use super::utils::into_string;
use crate::permissions::Permissions;
use deno_core::error::{type_error, AnyError};
-use deno_core::op_sync;
+use deno_core::op;
use deno_core::url::Url;
use deno_core::Extension;
use deno_core::OpState;
@@ -17,19 +17,19 @@ use std::sync::Arc;
pub fn init(maybe_exit_code: Option<Arc<AtomicI32>>) -> Extension {
Extension::builder()
.ops(vec![
- ("op_env", op_sync(op_env)),
- ("op_exec_path", op_sync(op_exec_path)),
- ("op_exit", op_sync(op_exit)),
- ("op_delete_env", op_sync(op_delete_env)),
- ("op_get_env", op_sync(op_get_env)),
- ("op_getuid", op_sync(op_getuid)),
- ("op_hostname", op_sync(op_hostname)),
- ("op_loadavg", op_sync(op_loadavg)),
- ("op_network_interfaces", op_sync(op_network_interfaces)),
- ("op_os_release", op_sync(op_os_release)),
- ("op_set_env", op_sync(op_set_env)),
- ("op_set_exit_code", op_sync(op_set_exit_code)),
- ("op_system_memory_info", op_sync(op_system_memory_info)),
+ op_env::decl(),
+ op_exec_path::decl(),
+ op_exit::decl(),
+ op_delete_env::decl(),
+ op_get_env::decl(),
+ op_getuid::decl(),
+ op_hostname::decl(),
+ op_loadavg::decl(),
+ op_network_interfaces::decl(),
+ op_os_release::decl(),
+ op_set_env::decl(),
+ op_set_exit_code::decl(),
+ op_system_memory_info::decl(),
])
.state(move |state| {
let exit_code = maybe_exit_code.clone().unwrap_or_default();
@@ -39,6 +39,7 @@ pub fn init(maybe_exit_code: Option<Arc<AtomicI32>>) -> Extension {
.build()
}
+#[op]
fn op_exec_path(state: &mut OpState, _: (), _: ()) -> Result<String, AnyError> {
let current_exe = env::current_exe().unwrap();
state
@@ -53,6 +54,7 @@ fn op_exec_path(state: &mut OpState, _: (), _: ()) -> Result<String, AnyError> {
into_string(path.into_os_string())
}
+#[op]
fn op_set_env(
state: &mut OpState,
key: String,
@@ -68,6 +70,7 @@ fn op_set_env(
Ok(())
}
+#[op]
fn op_env(
state: &mut OpState,
_: (),
@@ -77,6 +80,7 @@ fn op_env(
Ok(env::vars().collect())
}
+#[op]
fn op_get_env(
state: &mut OpState,
key: String,
@@ -93,6 +97,7 @@ fn op_get_env(
Ok(r)
}
+#[op]
fn op_delete_env(
state: &mut OpState,
key: String,
@@ -106,6 +111,7 @@ fn op_delete_env(
Ok(())
}
+#[op]
fn op_set_exit_code(
state: &mut OpState,
code: i32,
@@ -115,11 +121,13 @@ fn op_set_exit_code(
Ok(())
}
+#[op]
fn op_exit(state: &mut OpState, _: (), _: ()) -> Result<(), AnyError> {
let code = state.borrow::<Arc<AtomicI32>>().load(Relaxed);
std::process::exit(code)
}
+#[op]
fn op_loadavg(
state: &mut OpState,
_: (),
@@ -133,6 +141,7 @@ fn op_loadavg(
}
}
+#[op]
fn op_hostname(state: &mut OpState, _: (), _: ()) -> Result<String, AnyError> {
super::check_unstable(state, "Deno.hostname");
state.borrow_mut::<Permissions>().env.check_all()?;
@@ -140,6 +149,7 @@ fn op_hostname(state: &mut OpState, _: (), _: ()) -> Result<String, AnyError> {
Ok(hostname)
}
+#[op]
fn op_os_release(
state: &mut OpState,
_: (),
@@ -151,6 +161,7 @@ fn op_os_release(
Ok(release)
}
+#[op]
fn op_network_interfaces(
state: &mut OpState,
_: (),
@@ -218,6 +229,7 @@ struct MemInfo {
pub swap_free: u64,
}
+#[op]
fn op_system_memory_info(
state: &mut OpState,
_: (),
@@ -240,6 +252,7 @@ fn op_system_memory_info(
}
#[cfg(not(windows))]
+#[op]
fn op_getuid(
state: &mut OpState,
_: (),
@@ -251,6 +264,7 @@ fn op_getuid(
}
#[cfg(windows)]
+#[op]
fn op_getuid(
state: &mut OpState,
_: (),
diff --git a/runtime/ops/permissions.rs b/runtime/ops/permissions.rs
index da82f1fd0..401562439 100644
--- a/runtime/ops/permissions.rs
+++ b/runtime/ops/permissions.rs
@@ -4,7 +4,7 @@ use crate::permissions::Permissions;
use deno_core::error::custom_error;
use deno_core::error::uri_error;
use deno_core::error::AnyError;
-use deno_core::op_sync;
+use deno_core::op;
use deno_core::url;
use deno_core::Extension;
use deno_core::OpState;
@@ -14,9 +14,9 @@ use std::path::Path;
pub fn init() -> Extension {
Extension::builder()
.ops(vec![
- ("op_query_permission", op_sync(op_query_permission)),
- ("op_revoke_permission", op_sync(op_revoke_permission)),
- ("op_request_permission", op_sync(op_request_permission)),
+ op_query_permission::decl(),
+ op_revoke_permission::decl(),
+ op_request_permission::decl(),
])
.build()
}
@@ -30,6 +30,7 @@ pub struct PermissionArgs {
command: Option<String>,
}
+#[op]
pub fn op_query_permission(
state: &mut OpState,
args: PermissionArgs,
@@ -61,6 +62,7 @@ pub fn op_query_permission(
Ok(perm.to_string())
}
+#[op]
pub fn op_revoke_permission(
state: &mut OpState,
args: PermissionArgs,
@@ -92,6 +94,7 @@ pub fn op_revoke_permission(
Ok(perm.to_string())
}
+#[op]
pub fn op_request_permission(
state: &mut OpState,
args: PermissionArgs,
diff --git a/runtime/ops/process.rs b/runtime/ops/process.rs
index eee266986..7c45c47fc 100644
--- a/runtime/ops/process.rs
+++ b/runtime/ops/process.rs
@@ -8,8 +8,8 @@ use crate::permissions::Permissions;
use deno_core::error::bad_resource_id;
use deno_core::error::type_error;
use deno_core::error::AnyError;
-use deno_core::op_async;
-use deno_core::op_sync;
+use deno_core::op;
+
use deno_core::AsyncMutFuture;
use deno_core::AsyncRefCell;
use deno_core::Extension;
@@ -29,11 +29,7 @@ use std::os::unix::process::ExitStatusExt;
pub fn init() -> Extension {
Extension::builder()
- .ops(vec![
- ("op_run", op_sync(op_run)),
- ("op_run_status", op_async(op_run_status)),
- ("op_kill", op_sync(op_kill)),
- ])
+ .ops(vec![op_run::decl(), op_run_status::decl(), op_kill::decl()])
.build()
}
@@ -102,6 +98,7 @@ struct RunInfo {
stderr_rid: Option<ResourceId>,
}
+#[op]
fn op_run(
state: &mut OpState,
run_args: RunArgs,
@@ -226,6 +223,7 @@ struct ProcessStatus {
exit_signal: i32,
}
+#[op]
async fn op_run_status(
state: Rc<RefCell<OpState>>,
rid: ResourceId,
@@ -303,6 +301,7 @@ pub fn kill(pid: i32, signal: &str) -> Result<(), AnyError> {
}
}
+#[op]
fn op_kill(
state: &mut OpState,
pid: i32,
diff --git a/runtime/ops/runtime.rs b/runtime/ops/runtime.rs
index 19228af78..4f951383e 100644
--- a/runtime/ops/runtime.rs
+++ b/runtime/ops/runtime.rs
@@ -3,14 +3,14 @@
use crate::permissions::Permissions;
use deno_core::anyhow::Context;
use deno_core::error::AnyError;
-use deno_core::op_sync;
+use deno_core::op;
use deno_core::Extension;
use deno_core::ModuleSpecifier;
use deno_core::OpState;
pub fn init(main_module: ModuleSpecifier) -> Extension {
Extension::builder()
- .ops(vec![("op_main_module", op_sync(op_main_module))])
+ .ops(vec![op_main_module::decl()])
.state(move |state| {
state.put::<ModuleSpecifier>(main_module.clone());
Ok(())
@@ -18,6 +18,7 @@ pub fn init(main_module: ModuleSpecifier) -> Extension {
.build()
}
+#[op]
fn op_main_module(
state: &mut OpState,
_: (),
diff --git a/runtime/ops/signal.rs b/runtime/ops/signal.rs
index 9511b83e2..d9f05a777 100644
--- a/runtime/ops/signal.rs
+++ b/runtime/ops/signal.rs
@@ -4,8 +4,8 @@ use deno_core::error::generic_error;
#[cfg(not(target_os = "windows"))]
use deno_core::error::type_error;
use deno_core::error::AnyError;
-use deno_core::op_async;
-use deno_core::op_sync;
+use deno_core::op;
+
use deno_core::Extension;
use deno_core::OpState;
use std::cell::RefCell;
@@ -31,9 +31,9 @@ use tokio::signal::unix::{signal, Signal, SignalKind};
pub fn init() -> Extension {
Extension::builder()
.ops(vec![
- ("op_signal_bind", op_sync(op_signal_bind)),
- ("op_signal_unbind", op_sync(op_signal_unbind)),
- ("op_signal_poll", op_async(op_signal_poll)),
+ op_signal_bind::decl(),
+ op_signal_unbind::decl(),
+ op_signal_poll::decl(),
])
.build()
}
@@ -174,6 +174,7 @@ pub fn signal_str_to_int(s: &str) -> Result<libc::c_int, AnyError> {
}
#[cfg(unix)]
+#[op]
fn op_signal_bind(
state: &mut OpState,
sig: String,
@@ -195,6 +196,7 @@ fn op_signal_bind(
}
#[cfg(unix)]
+#[op]
async fn op_signal_poll(
state: Rc<RefCell<OpState>>,
rid: ResourceId,
@@ -214,6 +216,7 @@ async fn op_signal_poll(
}
#[cfg(unix)]
+#[op]
pub fn op_signal_unbind(
state: &mut OpState,
rid: ResourceId,
@@ -224,6 +227,7 @@ pub fn op_signal_unbind(
}
#[cfg(not(unix))]
+#[op]
pub fn op_signal_bind(
_state: &mut OpState,
_: (),
@@ -233,6 +237,7 @@ pub fn op_signal_bind(
}
#[cfg(not(unix))]
+#[op]
fn op_signal_unbind(
_state: &mut OpState,
_: (),
@@ -242,6 +247,7 @@ fn op_signal_unbind(
}
#[cfg(not(unix))]
+#[op]
async fn op_signal_poll(
_state: Rc<RefCell<OpState>>,
_: (),
diff --git a/runtime/ops/tty.rs b/runtime/ops/tty.rs
index ee6b112bc..bbf6bd412 100644
--- a/runtime/ops/tty.rs
+++ b/runtime/ops/tty.rs
@@ -5,7 +5,7 @@ use deno_core::error::bad_resource_id;
use deno_core::error::not_supported;
use deno_core::error::resource_unavailable;
use deno_core::error::AnyError;
-use deno_core::op_sync;
+use deno_core::op;
use deno_core::Extension;
use deno_core::OpState;
use deno_core::RcRef;
@@ -47,9 +47,9 @@ fn get_windows_handle(
pub fn init() -> Extension {
Extension::builder()
.ops(vec![
- ("op_set_raw", op_sync(op_set_raw)),
- ("op_isatty", op_sync(op_isatty)),
- ("op_console_size", op_sync(op_console_size)),
+ op_set_raw::decl(),
+ op_isatty::decl(),
+ op_console_size::decl(),
])
.build()
}
@@ -67,6 +67,7 @@ pub struct SetRawArgs {
options: SetRawOptions,
}
+#[op]
fn op_set_raw(
state: &mut OpState,
args: SetRawArgs,
@@ -211,6 +212,7 @@ fn op_set_raw(
}
}
+#[op]
fn op_isatty(
state: &mut OpState,
rid: ResourceId,
@@ -245,6 +247,7 @@ struct ConsoleSize {
rows: u32,
}
+#[op]
fn op_console_size(
state: &mut OpState,
rid: ResourceId,
diff --git a/runtime/ops/web_worker.rs b/runtime/ops/web_worker.rs
index e32f2371d..3c64cf1f6 100644
--- a/runtime/ops/web_worker.rs
+++ b/runtime/ops/web_worker.rs
@@ -5,8 +5,8 @@ mod sync_fetch;
use crate::web_worker::WebWorkerInternalHandle;
use crate::web_worker::WebWorkerType;
use deno_core::error::AnyError;
-use deno_core::op_async;
-use deno_core::op_sync;
+use deno_core::op;
+
use deno_core::CancelFuture;
use deno_core::Extension;
use deno_core::OpState;
@@ -19,16 +19,17 @@ use self::sync_fetch::op_worker_sync_fetch;
pub fn init() -> Extension {
Extension::builder()
.ops(vec![
- ("op_worker_post_message", op_sync(op_worker_post_message)),
- ("op_worker_recv_message", op_async(op_worker_recv_message)),
+ op_worker_post_message::decl(),
+ op_worker_recv_message::decl(),
// Notify host that guest worker closes.
- ("op_worker_close", op_sync(op_worker_close)),
- ("op_worker_get_type", op_sync(op_worker_get_type)),
- ("op_worker_sync_fetch", op_sync(op_worker_sync_fetch)),
+ op_worker_close::decl(),
+ op_worker_get_type::decl(),
+ op_worker_sync_fetch::decl(),
])
.build()
}
+#[op]
fn op_worker_post_message(
state: &mut OpState,
data: JsMessageData,
@@ -39,6 +40,7 @@ fn op_worker_post_message(
Ok(())
}
+#[op]
async fn op_worker_recv_message(
state: Rc<RefCell<OpState>>,
_: (),
@@ -55,6 +57,7 @@ async fn op_worker_recv_message(
.await?
}
+#[op]
fn op_worker_close(state: &mut OpState, _: (), _: ()) -> Result<(), AnyError> {
// Notify parent that we're finished
let mut handle = state.borrow_mut::<WebWorkerInternalHandle>().clone();
@@ -63,6 +66,7 @@ fn op_worker_close(state: &mut OpState, _: (), _: ()) -> Result<(), AnyError> {
Ok(())
}
+#[op]
fn op_worker_get_type(
state: &mut OpState,
_: (),
diff --git a/runtime/ops/web_worker/sync_fetch.rs b/runtime/ops/web_worker/sync_fetch.rs
index 76791ded5..464697f94 100644
--- a/runtime/ops/web_worker/sync_fetch.rs
+++ b/runtime/ops/web_worker/sync_fetch.rs
@@ -4,6 +4,7 @@ use crate::web_worker::WebWorkerInternalHandle;
use crate::web_worker::WebWorkerType;
use deno_core::error::type_error;
use deno_core::error::AnyError;
+use deno_core::op;
use deno_core::url::Url;
use deno_core::OpState;
use deno_fetch::data_url::DataUrl;
@@ -30,6 +31,7 @@ pub struct SyncFetchScript {
script: String,
}
+#[op]
pub fn op_worker_sync_fetch(
state: &mut OpState,
scripts: Vec<String>,
diff --git a/runtime/ops/worker_host.rs b/runtime/ops/worker_host.rs
index 1213da6d2..cebce81a4 100644
--- a/runtime/ops/worker_host.rs
+++ b/runtime/ops/worker_host.rs
@@ -13,8 +13,8 @@ use crate::web_worker::WorkerControlEvent;
use crate::web_worker::WorkerId;
use deno_core::error::AnyError;
use deno_core::futures::future::LocalFutureObj;
-use deno_core::op_async;
-use deno_core::op_sync;
+use deno_core::op;
+
use deno_core::serde::Deserialize;
use deno_core::Extension;
use deno_core::ModuleSpecifier;
@@ -122,14 +122,11 @@ pub fn init(
Ok(())
})
.ops(vec![
- ("op_create_worker", op_sync(op_create_worker)),
- (
- "op_host_terminate_worker",
- op_sync(op_host_terminate_worker),
- ),
- ("op_host_post_message", op_sync(op_host_post_message)),
- ("op_host_recv_ctrl", op_async(op_host_recv_ctrl)),
- ("op_host_recv_message", op_async(op_host_recv_message)),
+ op_create_worker::decl(),
+ op_host_terminate_worker::decl(),
+ op_host_post_message::decl(),
+ op_host_recv_ctrl::decl(),
+ op_host_recv_message::decl(),
])
.build()
}
@@ -147,6 +144,7 @@ pub struct CreateWorkerArgs {
}
/// Create worker as the host
+#[op]
fn op_create_worker(
state: &mut OpState,
args: CreateWorkerArgs,
@@ -263,6 +261,7 @@ fn op_create_worker(
Ok(worker_id)
}
+#[op]
fn op_host_terminate_worker(
state: &mut OpState,
id: WorkerId,
@@ -317,6 +316,7 @@ fn close_channel(
}
/// Get control event from guest worker as host
+#[op]
async fn op_host_recv_ctrl(
state: Rc<RefCell<OpState>>,
id: WorkerId,
@@ -348,6 +348,7 @@ async fn op_host_recv_ctrl(
Ok(WorkerControlEvent::Close)
}
+#[op]
async fn op_host_recv_message(
state: Rc<RefCell<OpState>>,
id: WorkerId,
@@ -373,6 +374,7 @@ async fn op_host_recv_message(
}
/// Post message to guest worker as host
+#[op]
fn op_host_post_message(
state: &mut OpState,
id: WorkerId,