Skip to content

Commit

Permalink
Add init methods for each op module (#3087)
Browse files Browse the repository at this point in the history
  • Loading branch information
ry authored Oct 11, 2019
1 parent 04ed8d0 commit 97d8498
Show file tree
Hide file tree
Showing 20 changed files with 292 additions and 361 deletions.
19 changes: 16 additions & 3 deletions cli/ops/compiler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,22 @@
use super::dispatch_json::{Deserialize, JsonOp, Value};
use crate::futures::future::join_all;
use crate::futures::Future;
use crate::ops::json_op;
use crate::state::ThreadSafeState;
use deno::*;

pub fn init(i: &mut Isolate, s: &ThreadSafeState) {
i.register_op("cache", s.core_op(json_op(s.stateful_op(op_cache))));
i.register_op(
"fetch_source_files",
s.core_op(json_op(s.stateful_op(op_fetch_source_files))),
);
i.register_op(
"fetch_asset",
s.core_op(json_op(s.stateful_op(op_fetch_asset))),
);
}

#[derive(Deserialize)]
#[serde(rename_all = "camelCase")]
struct CacheArgs {
Expand All @@ -13,7 +26,7 @@ struct CacheArgs {
extension: String,
}

pub fn op_cache(
fn op_cache(
state: &ThreadSafeState,
args: Value,
_zero_copy: Option<PinnedBuf>,
Expand All @@ -38,7 +51,7 @@ struct FetchSourceFilesArgs {
referrer: String,
}

pub fn op_fetch_source_files(
fn op_fetch_source_files(
state: &ThreadSafeState,
args: Value,
_data: Option<PinnedBuf>,
Expand Down Expand Up @@ -85,7 +98,7 @@ struct FetchAssetArgs {
name: String,
}

pub fn op_fetch_asset(
fn op_fetch_asset(
_state: &ThreadSafeState,
args: Value,
_zero_copy: Option<PinnedBuf>,
Expand Down
16 changes: 14 additions & 2 deletions cli/ops/errors.rs
Original file line number Diff line number Diff line change
@@ -1,18 +1,30 @@
// Copyright 2018-2019 the Deno authors. All rights reserved. MIT license.
use super::dispatch_json::{Deserialize, JsonOp, Value};
use crate::fmt_errors::JSError;
use crate::ops::json_op;
use crate::source_maps::get_orig_position;
use crate::source_maps::CachedMaps;
use crate::state::ThreadSafeState;
use deno::*;
use std::collections::HashMap;

pub fn init(i: &mut Isolate, s: &ThreadSafeState) {
i.register_op(
"apply_source_map",
s.core_op(json_op(s.stateful_op(op_apply_source_map))),
);
i.register_op(
"format_error",
s.core_op(json_op(s.stateful_op(op_format_error))),
);
}

#[derive(Deserialize)]
struct FormatErrorArgs {
error: String,
}

pub fn op_format_error(
fn op_format_error(
state: &ThreadSafeState,
args: Value,
_zero_copy: Option<PinnedBuf>,
Expand All @@ -32,7 +44,7 @@ struct ApplySourceMap {
column: i32,
}

pub fn op_apply_source_map(
fn op_apply_source_map(
state: &ThreadSafeState,
args: Value,
_zero_copy: Option<PinnedBuf>,
Expand Down
5 changes: 5 additions & 0 deletions cli/ops/fetch.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// Copyright 2018-2019 the Deno authors. All rights reserved. MIT license.
use super::dispatch_json::{Deserialize, JsonOp, Value};
use crate::http_util::get_client;
use crate::ops::json_op;
use crate::resources;
use crate::state::ThreadSafeState;
use deno::*;
Expand All @@ -12,6 +13,10 @@ use hyper::rt::Future;
use std;
use std::convert::From;

pub fn init(i: &mut Isolate, s: &ThreadSafeState) {
i.register_op("fetch", s.core_op(json_op(s.stateful_op(op_fetch))));
}

#[derive(Deserialize)]
struct FetchArgs {
method: Option<String>,
Expand Down
13 changes: 10 additions & 3 deletions cli/ops/files.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// Copyright 2018-2019 the Deno authors. All rights reserved. MIT license.
use super::dispatch_json::{Deserialize, JsonOp, Value};
use crate::fs as deno_fs;
use crate::ops::json_op;
use crate::resources;
use crate::state::ThreadSafeState;
use deno::*;
Expand All @@ -9,6 +10,12 @@ use std;
use std::convert::From;
use tokio;

pub fn init(i: &mut Isolate, s: &ThreadSafeState) {
i.register_op("open", s.core_op(json_op(s.stateful_op(op_open))));
i.register_op("close", s.core_op(json_op(s.stateful_op(op_close))));
i.register_op("seek", s.core_op(json_op(s.stateful_op(op_seek))));
}

#[derive(Deserialize)]
#[serde(rename_all = "camelCase")]
struct OpenArgs {
Expand All @@ -17,7 +24,7 @@ struct OpenArgs {
mode: String,
}

pub fn op_open(
fn op_open(
state: &ThreadSafeState,
args: Value,
_zero_copy: Option<PinnedBuf>,
Expand Down Expand Up @@ -96,7 +103,7 @@ struct CloseArgs {
rid: i32,
}

pub fn op_close(
fn op_close(
_state: &ThreadSafeState,
args: Value,
_zero_copy: Option<PinnedBuf>,
Expand All @@ -117,7 +124,7 @@ struct SeekArgs {
whence: i32,
}

pub fn op_seek(
fn op_seek(
_state: &ThreadSafeState,
args: Value,
_zero_copy: Option<PinnedBuf>,
Expand Down
56 changes: 39 additions & 17 deletions cli/ops/fs.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
// Copyright 2018-2019 the Deno authors. All rights reserved. MIT license.
// Some deserializer fields are only used on Unix and Windows build fails without it
#![allow(dead_code)]
use super::dispatch_json::{blocking_json, Deserialize, JsonOp, Value};
use crate::deno_error::DenoError;
use crate::deno_error::ErrorKind;
use crate::fs as deno_fs;
use crate::ops::json_op;
use crate::state::ThreadSafeState;
use deno::*;
use remove_dir_all::remove_dir_all;
Expand All @@ -16,12 +16,34 @@ use std::time::UNIX_EPOCH;
#[cfg(unix)]
use std::os::unix::fs::PermissionsExt;

pub fn init(i: &mut Isolate, s: &ThreadSafeState) {
i.register_op("chdir", s.core_op(json_op(s.stateful_op(op_chdir))));
i.register_op("mkdir", s.core_op(json_op(s.stateful_op(op_mkdir))));
i.register_op("chmod", s.core_op(json_op(s.stateful_op(op_chmod))));
i.register_op("chown", s.core_op(json_op(s.stateful_op(op_chown))));
i.register_op("remove", s.core_op(json_op(s.stateful_op(op_remove))));
i.register_op("copy_file", s.core_op(json_op(s.stateful_op(op_copy_file))));
i.register_op("stat", s.core_op(json_op(s.stateful_op(op_stat))));
i.register_op("read_dir", s.core_op(json_op(s.stateful_op(op_read_dir))));
i.register_op("rename", s.core_op(json_op(s.stateful_op(op_rename))));
i.register_op("link", s.core_op(json_op(s.stateful_op(op_link))));
i.register_op("symlink", s.core_op(json_op(s.stateful_op(op_symlink))));
i.register_op("read_link", s.core_op(json_op(s.stateful_op(op_read_link))));
i.register_op("truncate", s.core_op(json_op(s.stateful_op(op_truncate))));
i.register_op(
"make_temp_dir",
s.core_op(json_op(s.stateful_op(op_make_temp_dir))),
);
i.register_op("cwd", s.core_op(json_op(s.stateful_op(op_cwd))));
i.register_op("utime", s.core_op(json_op(s.stateful_op(op_utime))));
}

#[derive(Deserialize)]
struct ChdirArgs {
directory: String,
}

pub fn op_chdir(
fn op_chdir(
_state: &ThreadSafeState,
args: Value,
_zero_copy: Option<PinnedBuf>,
Expand All @@ -40,7 +62,7 @@ struct MkdirArgs {
mode: u32,
}

pub fn op_mkdir(
fn op_mkdir(
state: &ThreadSafeState,
args: Value,
_zero_copy: Option<PinnedBuf>,
Expand All @@ -66,7 +88,7 @@ struct ChmodArgs {
mode: u32,
}

pub fn op_chmod(
fn op_chmod(
state: &ThreadSafeState,
args: Value,
_zero_copy: Option<PinnedBuf>,
Expand Down Expand Up @@ -100,7 +122,7 @@ struct ChownArgs {
gid: u32,
}

pub fn op_chown(
fn op_chown(
state: &ThreadSafeState,
args: Value,
_zero_copy: Option<PinnedBuf>,
Expand All @@ -127,7 +149,7 @@ struct RemoveArgs {
recursive: bool,
}

pub fn op_remove(
fn op_remove(
state: &ThreadSafeState,
args: Value,
_zero_copy: Option<PinnedBuf>,
Expand Down Expand Up @@ -161,7 +183,7 @@ struct CopyFileArgs {
to: String,
}

pub fn op_copy_file(
fn op_copy_file(
state: &ThreadSafeState,
args: Value,
_zero_copy: Option<PinnedBuf>,
Expand Down Expand Up @@ -220,7 +242,7 @@ struct StatArgs {
lstat: bool,
}

pub fn op_stat(
fn op_stat(
state: &ThreadSafeState,
args: Value,
_zero_copy: Option<PinnedBuf>,
Expand Down Expand Up @@ -262,7 +284,7 @@ struct ReadDirArgs {
path: String,
}

pub fn op_read_dir(
fn op_read_dir(
state: &ThreadSafeState,
args: Value,
_zero_copy: Option<PinnedBuf>,
Expand Down Expand Up @@ -308,7 +330,7 @@ struct RenameArgs {
newpath: String,
}

pub fn op_rename(
fn op_rename(
state: &ThreadSafeState,
args: Value,
_zero_copy: Option<PinnedBuf>,
Expand Down Expand Up @@ -338,7 +360,7 @@ struct LinkArgs {
newname: String,
}

pub fn op_link(
fn op_link(
state: &ThreadSafeState,
args: Value,
_zero_copy: Option<PinnedBuf>,
Expand Down Expand Up @@ -367,7 +389,7 @@ struct SymlinkArgs {
newname: String,
}

pub fn op_symlink(
fn op_symlink(
state: &ThreadSafeState,
args: Value,
_zero_copy: Option<PinnedBuf>,
Expand Down Expand Up @@ -400,7 +422,7 @@ struct ReadLinkArgs {
name: String,
}

pub fn op_read_link(
fn op_read_link(
state: &ThreadSafeState,
args: Value,
_zero_copy: Option<PinnedBuf>,
Expand Down Expand Up @@ -429,7 +451,7 @@ struct TruncateArgs {
len: u64,
}

pub fn op_truncate(
fn op_truncate(
state: &ThreadSafeState,
args: Value,
_zero_copy: Option<PinnedBuf>,
Expand Down Expand Up @@ -459,7 +481,7 @@ struct MakeTempDirArgs {
suffix: Option<String>,
}

pub fn op_make_temp_dir(
fn op_make_temp_dir(
state: &ThreadSafeState,
args: Value,
_zero_copy: Option<PinnedBuf>,
Expand Down Expand Up @@ -499,7 +521,7 @@ struct Utime {
mtime: u64,
}

pub fn op_utime(
fn op_utime(
state: &ThreadSafeState,
args: Value,
_zero_copy: Option<PinnedBuf>,
Expand All @@ -514,7 +536,7 @@ pub fn op_utime(
})
}

pub fn op_cwd(
fn op_cwd(
_state: &ThreadSafeState,
_args: Value,
_zero_copy: Option<PinnedBuf>,
Expand Down
10 changes: 8 additions & 2 deletions cli/ops/io.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,18 @@
use super::dispatch_minimal::MinimalOp;
use crate::deno_error;
use crate::ops::minimal_op;
use crate::resources;
use crate::state::ThreadSafeState;
use crate::tokio_read;
use crate::tokio_write;
use deno::ErrBox;
use deno::PinnedBuf;
use deno::*;
use futures::Future;

pub fn init(i: &mut Isolate, s: &ThreadSafeState) {
i.register_op("read", s.core_op(minimal_op(op_read)));
i.register_op("write", s.core_op(minimal_op(op_write)));
}

pub fn op_read(rid: i32, zero_copy: Option<PinnedBuf>) -> Box<MinimalOp> {
debug!("read rid={}", rid);
let zero_copy = match zero_copy {
Expand Down
21 changes: 0 additions & 21 deletions cli/ops/metrics.rs

This file was deleted.

2 changes: 0 additions & 2 deletions cli/ops/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,8 @@ pub mod fetch;
pub mod files;
pub mod fs;
pub mod io;
pub mod metrics;
pub mod net;
pub mod os;
pub mod performance;
pub mod permissions;
pub mod process;
pub mod random;
Expand Down
Loading

0 comments on commit 97d8498

Please sign in to comment.