Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(runtime): use Extensions #10461

Merged
merged 4 commits into from
May 2, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
131 changes: 57 additions & 74 deletions runtime/ops/fs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ 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::Extension;
use deno_core::OpState;
use deno_core::RcRef;
use deno_core::ResourceId;
Expand All @@ -33,80 +36,60 @@ use deno_core::error::generic_error;
#[cfg(not(unix))]
use deno_core::error::not_supported;

pub fn init(rt: &mut deno_core::JsRuntime) {
super::reg_sync(rt, "op_open_sync", op_open_sync);
super::reg_async(rt, "op_open_async", op_open_async);

super::reg_sync(rt, "op_seek_sync", op_seek_sync);
super::reg_async(rt, "op_seek_async", op_seek_async);

super::reg_sync(rt, "op_fdatasync_sync", op_fdatasync_sync);
super::reg_async(rt, "op_fdatasync_async", op_fdatasync_async);

super::reg_sync(rt, "op_fsync_sync", op_fsync_sync);
super::reg_async(rt, "op_fsync_async", op_fsync_async);

super::reg_sync(rt, "op_fstat_sync", op_fstat_sync);
super::reg_async(rt, "op_fstat_async", op_fstat_async);

super::reg_sync(rt, "op_umask", op_umask);
super::reg_sync(rt, "op_chdir", op_chdir);

super::reg_sync(rt, "op_mkdir_sync", op_mkdir_sync);
super::reg_async(rt, "op_mkdir_async", op_mkdir_async);

super::reg_sync(rt, "op_chmod_sync", op_chmod_sync);
super::reg_async(rt, "op_chmod_async", op_chmod_async);

super::reg_sync(rt, "op_chown_sync", op_chown_sync);
super::reg_async(rt, "op_chown_async", op_chown_async);

super::reg_sync(rt, "op_remove_sync", op_remove_sync);
super::reg_async(rt, "op_remove_async", op_remove_async);

super::reg_sync(rt, "op_copy_file_sync", op_copy_file_sync);
super::reg_async(rt, "op_copy_file_async", op_copy_file_async);

super::reg_sync(rt, "op_stat_sync", op_stat_sync);
super::reg_async(rt, "op_stat_async", op_stat_async);

super::reg_sync(rt, "op_realpath_sync", op_realpath_sync);
super::reg_async(rt, "op_realpath_async", op_realpath_async);

super::reg_sync(rt, "op_read_dir_sync", op_read_dir_sync);
super::reg_async(rt, "op_read_dir_async", op_read_dir_async);

super::reg_sync(rt, "op_rename_sync", op_rename_sync);
super::reg_async(rt, "op_rename_async", op_rename_async);

super::reg_sync(rt, "op_link_sync", op_link_sync);
super::reg_async(rt, "op_link_async", op_link_async);

super::reg_sync(rt, "op_symlink_sync", op_symlink_sync);
super::reg_async(rt, "op_symlink_async", op_symlink_async);

super::reg_sync(rt, "op_read_link_sync", op_read_link_sync);
super::reg_async(rt, "op_read_link_async", op_read_link_async);

super::reg_sync(rt, "op_ftruncate_sync", op_ftruncate_sync);
super::reg_async(rt, "op_ftruncate_async", op_ftruncate_async);

super::reg_sync(rt, "op_truncate_sync", op_truncate_sync);
super::reg_async(rt, "op_truncate_async", op_truncate_async);

super::reg_sync(rt, "op_make_temp_dir_sync", op_make_temp_dir_sync);
super::reg_async(rt, "op_make_temp_dir_async", op_make_temp_dir_async);

super::reg_sync(rt, "op_make_temp_file_sync", op_make_temp_file_sync);
super::reg_async(rt, "op_make_temp_file_async", op_make_temp_file_async);

super::reg_sync(rt, "op_cwd", op_cwd);

super::reg_sync(rt, "op_futime_sync", op_futime_sync);
super::reg_async(rt, "op_futime_async", op_futime_async);

super::reg_sync(rt, "op_utime_sync", op_utime_sync);
super::reg_async(rt, "op_utime_async", op_utime_async);
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_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)),
])
.build()
}

#[derive(Deserialize)]
Expand Down
13 changes: 10 additions & 3 deletions runtime/ops/fs_events.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ use deno_core::Resource;
use deno_core::ResourceId;
use deno_core::ZeroCopyBuf;

use deno_core::op_async;
use deno_core::op_sync;
use deno_core::Extension;
use notify::event::Event as NotifyEvent;
use notify::Error as NotifyError;
use notify::EventKind;
Expand All @@ -27,9 +30,13 @@ use std::path::PathBuf;
use std::rc::Rc;
use tokio::sync::mpsc;

pub fn init(rt: &mut deno_core::JsRuntime) {
super::reg_sync(rt, "op_fs_events_open", op_fs_events_open);
super::reg_async(rt, "op_fs_events_poll", op_fs_events_poll);
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)),
])
.build()
}

struct FsEventsResource {
Expand Down
23 changes: 14 additions & 9 deletions runtime/ops/http.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,13 @@ use deno_core::futures::future::poll_fn;
use deno_core::futures::FutureExt;
use deno_core::futures::Stream;
use deno_core::futures::StreamExt;
use deno_core::op_async;
use deno_core::op_sync;
use deno_core::AsyncRefCell;
use deno_core::CancelFuture;
use deno_core::CancelHandle;
use deno_core::CancelTryFuture;
use deno_core::Extension;
use deno_core::OpState;
use deno_core::RcRef;
use deno_core::Resource;
Expand Down Expand Up @@ -43,15 +46,17 @@ use tokio::sync::oneshot;
use tokio_rustls::server::TlsStream;
use tokio_util::io::StreamReader;

pub fn init(rt: &mut deno_core::JsRuntime) {
super::reg_sync(rt, "op_http_start", op_http_start);

super::reg_async(rt, "op_http_request_next", op_http_request_next);
super::reg_async(rt, "op_http_request_read", op_http_request_read);

super::reg_async(rt, "op_http_response", op_http_response);
super::reg_async(rt, "op_http_response_write", op_http_response_write);
super::reg_async(rt, "op_http_response_close", op_http_response_close);
pub fn init() -> Extension {
Extension::builder()
.ops(vec![
("op_http_start", op_sync(op_http_start)),
("op_http_request_next", op_async(op_http_request_next)),
("op_http_request_read", op_async(op_http_request_read)),
("op_http_response", op_async(op_http_response)),
("op_http_response_write", op_async(op_http_response_write)),
("op_http_response_close", op_async(op_http_response_close)),
])
.build()
}

struct ServiceInner {
Expand Down
39 changes: 31 additions & 8 deletions runtime/ops/io.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,13 @@ use deno_core::error::null_opbuf;
use deno_core::error::resource_unavailable;
use deno_core::error::AnyError;
use deno_core::error::{bad_resource_id, not_supported};
use deno_core::op_async;
use deno_core::op_sync;
use deno_core::AsyncMutFuture;
use deno_core::AsyncRefCell;
use deno_core::CancelHandle;
use deno_core::CancelTryFuture;
use deno_core::JsRuntime;
use deno_core::Extension;
use deno_core::OpState;
use deno_core::RcRef;
use deno_core::Resource;
Expand Down Expand Up @@ -95,14 +97,35 @@ lazy_static::lazy_static! {
};
}

pub fn init(rt: &mut JsRuntime) {
super::reg_async(rt, "op_read_async", op_read_async);
super::reg_async(rt, "op_write_async", op_write_async);

super::reg_sync(rt, "op_read_sync", op_read_sync);
super::reg_sync(rt, "op_write_sync", op_write_sync);
pub fn init() -> Extension {
Extension::builder()
.ops(vec![
("op_read_async", op_async(op_read_async)),
("op_write_async", op_async(op_write_async)),
("op_read_sync", op_sync(op_read_sync)),
("op_write_sync", op_sync(op_write_sync)),
("op_shutdown", op_async(op_shutdown)),
])
.build()
}

super::reg_async(rt, "op_shutdown", op_shutdown);
pub fn init_stdio() -> Extension {
Extension::builder()
.state(|state| {
let t = &mut state.resource_table;
let (stdin, stdout, stderr) = get_stdio();
if let Some(stream) = stdin {
t.add(stream);
}
if let Some(stream) = stdout {
t.add(stream);
}
if let Some(stream) = stderr {
t.add(stream);
}
Ok(())
})
.build()
}

pub fn get_stdio() -> (
Expand Down
21 changes: 14 additions & 7 deletions runtime/ops/net.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,12 @@ use deno_core::error::generic_error;
use deno_core::error::null_opbuf;
use deno_core::error::type_error;
use deno_core::error::AnyError;
use deno_core::op_async;
use deno_core::op_sync;
use deno_core::AsyncRefCell;
use deno_core::CancelHandle;
use deno_core::CancelTryFuture;
use deno_core::Extension;
use deno_core::OpState;
use deno_core::RcRef;
use deno_core::Resource;
Expand Down Expand Up @@ -42,13 +45,17 @@ use crate::ops::io::UnixStreamResource;
#[cfg(unix)]
use std::path::Path;

pub fn init(rt: &mut deno_core::JsRuntime) {
super::reg_async(rt, "op_accept", op_accept);
super::reg_async(rt, "op_connect", op_connect);
super::reg_sync(rt, "op_listen", op_listen);
super::reg_async(rt, "op_datagram_receive", op_datagram_receive);
super::reg_async(rt, "op_datagram_send", op_datagram_send);
super::reg_async(rt, "op_dns_resolve", op_dns_resolve);
pub fn init() -> Extension {
Extension::builder()
.ops(vec![
("op_accept", op_async(op_accept)),
("op_connect", op_async(op_connect)),
("op_listen", op_sync(op_listen)),
("op_datagram_receive", op_async(op_datagram_receive)),
("op_datagram_send", op_async(op_datagram_send)),
("op_dns_resolve", op_async(op_dns_resolve)),
])
.build()
}

#[derive(Serialize)]
Expand Down
30 changes: 18 additions & 12 deletions runtime/ops/os.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,26 +3,32 @@
use super::utils::into_string;
use crate::permissions::Permissions;
use deno_core::error::{type_error, AnyError};
use deno_core::op_sync;
use deno_core::url::Url;
use deno_core::Extension;
use deno_core::OpState;
use deno_core::ZeroCopyBuf;
use serde::Deserialize;
use serde::Serialize;
use std::collections::HashMap;
use std::env;

pub fn init(rt: &mut deno_core::JsRuntime) {
super::reg_sync(rt, "op_exit", op_exit);
super::reg_sync(rt, "op_env", op_env);
super::reg_sync(rt, "op_exec_path", op_exec_path);
super::reg_sync(rt, "op_set_env", op_set_env);
super::reg_sync(rt, "op_get_env", op_get_env);
super::reg_sync(rt, "op_delete_env", op_delete_env);
super::reg_sync(rt, "op_hostname", op_hostname);
super::reg_sync(rt, "op_loadavg", op_loadavg);
super::reg_sync(rt, "op_os_release", op_os_release);
super::reg_sync(rt, "op_system_memory_info", op_system_memory_info);
super::reg_sync(rt, "op_system_cpu_info", op_system_cpu_info);
pub fn init() -> Extension {
Extension::builder()
.ops(vec![
("op_exit", op_sync(op_exit)),
("op_env", op_sync(op_env)),
("op_exec_path", op_sync(op_exec_path)),
("op_set_env", op_sync(op_set_env)),
("op_get_env", op_sync(op_get_env)),
("op_delete_env", op_sync(op_delete_env)),
("op_hostname", op_sync(op_hostname)),
("op_loadavg", op_sync(op_loadavg)),
("op_os_release", op_sync(op_os_release)),
("op_system_memory_info", op_sync(op_system_memory_info)),
("op_system_cpu_info", op_sync(op_system_cpu_info)),
])
.build()
}

fn op_exec_path(
Expand Down
14 changes: 10 additions & 4 deletions runtime/ops/permissions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,22 @@ 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::url;
use deno_core::Extension;
use deno_core::OpState;
use deno_core::ZeroCopyBuf;
use serde::Deserialize;
use std::path::Path;

pub fn init(rt: &mut deno_core::JsRuntime) {
super::reg_sync(rt, "op_query_permission", op_query_permission);
super::reg_sync(rt, "op_revoke_permission", op_revoke_permission);
super::reg_sync(rt, "op_request_permission", op_request_permission);
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)),
])
.build()
}

#[derive(Deserialize)]
Expand Down
Loading