mirror of
https://github.com/denoland/deno.git
synced 2024-12-24 16:19:12 -05:00
s/PinnedBuf/ZeroCopyBuf (#3782)
This commit is contained in:
parent
86726f88f1
commit
5e32c5ea44
32 changed files with 145 additions and 138 deletions
|
@ -2,16 +2,16 @@
|
|||
use deno_core::CoreOp;
|
||||
use deno_core::Isolate;
|
||||
use deno_core::Op;
|
||||
use deno_core::PinnedBuf;
|
||||
use deno_core::StartupData;
|
||||
use deno_core::ZeroCopyBuf;
|
||||
use std::collections::HashMap;
|
||||
use std::env;
|
||||
use std::path::PathBuf;
|
||||
|
||||
fn op_fetch_asset(
|
||||
custom_assets: HashMap<String, PathBuf>,
|
||||
) -> impl Fn(&[u8], Option<PinnedBuf>) -> CoreOp {
|
||||
move |control: &[u8], zero_copy_buf: Option<PinnedBuf>| -> CoreOp {
|
||||
) -> impl Fn(&[u8], Option<ZeroCopyBuf>) -> CoreOp {
|
||||
move |control: &[u8], zero_copy_buf: Option<ZeroCopyBuf>| -> CoreOp {
|
||||
assert!(zero_copy_buf.is_none()); // zero_copy_buf unused in this op.
|
||||
let custom_assets = custom_assets.clone();
|
||||
let name = std::str::from_utf8(control).unwrap();
|
||||
|
|
|
@ -30,7 +30,7 @@ struct CacheArgs {
|
|||
fn op_cache(
|
||||
state: &ThreadSafeState,
|
||||
args: Value,
|
||||
_zero_copy: Option<PinnedBuf>,
|
||||
_zero_copy: Option<ZeroCopyBuf>,
|
||||
) -> Result<JsonOp, ErrBox> {
|
||||
let args: CacheArgs = serde_json::from_value(args)?;
|
||||
|
||||
|
@ -55,7 +55,7 @@ struct SpecifiersReferrerArgs {
|
|||
fn op_resolve_modules(
|
||||
state: &ThreadSafeState,
|
||||
args: Value,
|
||||
_data: Option<PinnedBuf>,
|
||||
_data: Option<ZeroCopyBuf>,
|
||||
) -> Result<JsonOp, ErrBox> {
|
||||
let args: SpecifiersReferrerArgs = serde_json::from_value(args)?;
|
||||
|
||||
|
@ -86,7 +86,7 @@ fn op_resolve_modules(
|
|||
fn op_fetch_source_files(
|
||||
state: &ThreadSafeState,
|
||||
args: Value,
|
||||
_data: Option<PinnedBuf>,
|
||||
_data: Option<ZeroCopyBuf>,
|
||||
) -> Result<JsonOp, ErrBox> {
|
||||
let args: SpecifiersReferrerArgs = serde_json::from_value(args)?;
|
||||
|
||||
|
|
|
@ -48,11 +48,11 @@ struct AsyncArgs {
|
|||
promise_id: Option<u64>,
|
||||
}
|
||||
|
||||
pub fn json_op<D>(d: D) -> impl Fn(&[u8], Option<PinnedBuf>) -> CoreOp
|
||||
pub fn json_op<D>(d: D) -> impl Fn(&[u8], Option<ZeroCopyBuf>) -> CoreOp
|
||||
where
|
||||
D: Fn(Value, Option<PinnedBuf>) -> Result<JsonOp, ErrBox>,
|
||||
D: Fn(Value, Option<ZeroCopyBuf>) -> Result<JsonOp, ErrBox>,
|
||||
{
|
||||
move |control: &[u8], zero_copy: Option<PinnedBuf>| {
|
||||
move |control: &[u8], zero_copy: Option<ZeroCopyBuf>| {
|
||||
let async_args: AsyncArgs = match serde_json::from_slice(control) {
|
||||
Ok(args) => args,
|
||||
Err(e) => {
|
||||
|
|
|
@ -11,7 +11,7 @@ use deno_core::Buf;
|
|||
use deno_core::CoreOp;
|
||||
use deno_core::ErrBox;
|
||||
use deno_core::Op;
|
||||
use deno_core::PinnedBuf;
|
||||
use deno_core::ZeroCopyBuf;
|
||||
use futures::future::FutureExt;
|
||||
use std::future::Future;
|
||||
use std::pin::Pin;
|
||||
|
@ -113,11 +113,11 @@ fn test_parse_min_record() {
|
|||
assert_eq!(parse_min_record(&buf), None);
|
||||
}
|
||||
|
||||
pub fn minimal_op<D>(d: D) -> impl Fn(&[u8], Option<PinnedBuf>) -> CoreOp
|
||||
pub fn minimal_op<D>(d: D) -> impl Fn(&[u8], Option<ZeroCopyBuf>) -> CoreOp
|
||||
where
|
||||
D: Fn(i32, Option<PinnedBuf>) -> Pin<Box<MinimalOp>>,
|
||||
D: Fn(i32, Option<ZeroCopyBuf>) -> Pin<Box<MinimalOp>>,
|
||||
{
|
||||
move |control: &[u8], zero_copy: Option<PinnedBuf>| {
|
||||
move |control: &[u8], zero_copy: Option<ZeroCopyBuf>| {
|
||||
let mut record = match parse_min_record(control) {
|
||||
Some(r) => r,
|
||||
None => {
|
||||
|
|
|
@ -27,7 +27,7 @@ struct FormatErrorArgs {
|
|||
fn op_format_error(
|
||||
state: &ThreadSafeState,
|
||||
args: Value,
|
||||
_zero_copy: Option<PinnedBuf>,
|
||||
_zero_copy: Option<ZeroCopyBuf>,
|
||||
) -> Result<JsonOp, ErrBox> {
|
||||
let args: FormatErrorArgs = serde_json::from_value(args)?;
|
||||
let error = JSError::from_json(&args.error, &state.global_state.ts_compiler);
|
||||
|
@ -47,7 +47,7 @@ struct ApplySourceMap {
|
|||
fn op_apply_source_map(
|
||||
state: &ThreadSafeState,
|
||||
args: Value,
|
||||
_zero_copy: Option<PinnedBuf>,
|
||||
_zero_copy: Option<ZeroCopyBuf>,
|
||||
) -> Result<JsonOp, ErrBox> {
|
||||
let args: ApplySourceMap = serde_json::from_value(args)?;
|
||||
|
||||
|
|
|
@ -26,7 +26,7 @@ struct FetchArgs {
|
|||
pub fn op_fetch(
|
||||
state: &ThreadSafeState,
|
||||
args: Value,
|
||||
data: Option<PinnedBuf>,
|
||||
data: Option<ZeroCopyBuf>,
|
||||
) -> Result<JsonOp, ErrBox> {
|
||||
let args: FetchArgs = serde_json::from_value(args)?;
|
||||
let url = args.url;
|
||||
|
|
|
@ -45,7 +45,7 @@ struct OpenOptions {
|
|||
fn op_open(
|
||||
state: &ThreadSafeState,
|
||||
args: Value,
|
||||
_zero_copy: Option<PinnedBuf>,
|
||||
_zero_copy: Option<ZeroCopyBuf>,
|
||||
) -> Result<JsonOp, ErrBox> {
|
||||
let args: OpenArgs = serde_json::from_value(args)?;
|
||||
let filename = deno_fs::resolve_from_cwd(Path::new(&args.filename))?;
|
||||
|
@ -151,7 +151,7 @@ struct CloseArgs {
|
|||
fn op_close(
|
||||
state: &ThreadSafeState,
|
||||
args: Value,
|
||||
_zero_copy: Option<PinnedBuf>,
|
||||
_zero_copy: Option<ZeroCopyBuf>,
|
||||
) -> Result<JsonOp, ErrBox> {
|
||||
let args: CloseArgs = serde_json::from_value(args)?;
|
||||
|
||||
|
@ -172,7 +172,7 @@ struct SeekArgs {
|
|||
fn op_seek(
|
||||
state: &ThreadSafeState,
|
||||
args: Value,
|
||||
_zero_copy: Option<PinnedBuf>,
|
||||
_zero_copy: Option<ZeroCopyBuf>,
|
||||
) -> Result<JsonOp, ErrBox> {
|
||||
let args: SeekArgs = serde_json::from_value(args)?;
|
||||
let rid = args.rid as u32;
|
||||
|
|
|
@ -49,7 +49,7 @@ struct ChdirArgs {
|
|||
fn op_chdir(
|
||||
_state: &ThreadSafeState,
|
||||
args: Value,
|
||||
_zero_copy: Option<PinnedBuf>,
|
||||
_zero_copy: Option<ZeroCopyBuf>,
|
||||
) -> Result<JsonOp, ErrBox> {
|
||||
let args: ChdirArgs = serde_json::from_value(args)?;
|
||||
std::env::set_current_dir(&args.directory)?;
|
||||
|
@ -68,7 +68,7 @@ struct MkdirArgs {
|
|||
fn op_mkdir(
|
||||
state: &ThreadSafeState,
|
||||
args: Value,
|
||||
_zero_copy: Option<PinnedBuf>,
|
||||
_zero_copy: Option<ZeroCopyBuf>,
|
||||
) -> Result<JsonOp, ErrBox> {
|
||||
let args: MkdirArgs = serde_json::from_value(args)?;
|
||||
let path = deno_fs::resolve_from_cwd(Path::new(&args.path))?;
|
||||
|
@ -95,7 +95,7 @@ struct ChmodArgs {
|
|||
fn op_chmod(
|
||||
state: &ThreadSafeState,
|
||||
args: Value,
|
||||
_zero_copy: Option<PinnedBuf>,
|
||||
_zero_copy: Option<ZeroCopyBuf>,
|
||||
) -> Result<JsonOp, ErrBox> {
|
||||
let args: ChmodArgs = serde_json::from_value(args)?;
|
||||
let path = deno_fs::resolve_from_cwd(Path::new(&args.path))?;
|
||||
|
@ -129,7 +129,7 @@ struct ChownArgs {
|
|||
fn op_chown(
|
||||
state: &ThreadSafeState,
|
||||
args: Value,
|
||||
_zero_copy: Option<PinnedBuf>,
|
||||
_zero_copy: Option<ZeroCopyBuf>,
|
||||
) -> Result<JsonOp, ErrBox> {
|
||||
let args: ChownArgs = serde_json::from_value(args)?;
|
||||
let path = deno_fs::resolve_from_cwd(Path::new(&args.path))?;
|
||||
|
@ -157,7 +157,7 @@ struct RemoveArgs {
|
|||
fn op_remove(
|
||||
state: &ThreadSafeState,
|
||||
args: Value,
|
||||
_zero_copy: Option<PinnedBuf>,
|
||||
_zero_copy: Option<ZeroCopyBuf>,
|
||||
) -> Result<JsonOp, ErrBox> {
|
||||
let args: RemoveArgs = serde_json::from_value(args)?;
|
||||
let path = deno_fs::resolve_from_cwd(Path::new(&args.path))?;
|
||||
|
@ -191,7 +191,7 @@ struct CopyFileArgs {
|
|||
fn op_copy_file(
|
||||
state: &ThreadSafeState,
|
||||
args: Value,
|
||||
_zero_copy: Option<PinnedBuf>,
|
||||
_zero_copy: Option<ZeroCopyBuf>,
|
||||
) -> Result<JsonOp, ErrBox> {
|
||||
let args: CopyFileArgs = serde_json::from_value(args)?;
|
||||
let from = deno_fs::resolve_from_cwd(Path::new(&args.from))?;
|
||||
|
@ -290,7 +290,7 @@ struct StatArgs {
|
|||
fn op_stat(
|
||||
state: &ThreadSafeState,
|
||||
args: Value,
|
||||
_zero_copy: Option<PinnedBuf>,
|
||||
_zero_copy: Option<ZeroCopyBuf>,
|
||||
) -> Result<JsonOp, ErrBox> {
|
||||
let args: StatArgs = serde_json::from_value(args)?;
|
||||
let filename = deno_fs::resolve_from_cwd(Path::new(&args.filename))?;
|
||||
|
@ -320,7 +320,7 @@ struct RealpathArgs {
|
|||
fn op_realpath(
|
||||
state: &ThreadSafeState,
|
||||
args: Value,
|
||||
_zero_copy: Option<PinnedBuf>,
|
||||
_zero_copy: Option<ZeroCopyBuf>,
|
||||
) -> Result<JsonOp, ErrBox> {
|
||||
let args: RealpathArgs = serde_json::from_value(args)?;
|
||||
let path = deno_fs::resolve_from_cwd(Path::new(&args.path))?;
|
||||
|
@ -352,7 +352,7 @@ struct ReadDirArgs {
|
|||
fn op_read_dir(
|
||||
state: &ThreadSafeState,
|
||||
args: Value,
|
||||
_zero_copy: Option<PinnedBuf>,
|
||||
_zero_copy: Option<ZeroCopyBuf>,
|
||||
) -> Result<JsonOp, ErrBox> {
|
||||
let args: ReadDirArgs = serde_json::from_value(args)?;
|
||||
let path = deno_fs::resolve_from_cwd(Path::new(&args.path))?;
|
||||
|
@ -389,7 +389,7 @@ struct RenameArgs {
|
|||
fn op_rename(
|
||||
state: &ThreadSafeState,
|
||||
args: Value,
|
||||
_zero_copy: Option<PinnedBuf>,
|
||||
_zero_copy: Option<ZeroCopyBuf>,
|
||||
) -> Result<JsonOp, ErrBox> {
|
||||
let args: RenameArgs = serde_json::from_value(args)?;
|
||||
let oldpath = deno_fs::resolve_from_cwd(Path::new(&args.oldpath))?;
|
||||
|
@ -418,7 +418,7 @@ struct LinkArgs {
|
|||
fn op_link(
|
||||
state: &ThreadSafeState,
|
||||
args: Value,
|
||||
_zero_copy: Option<PinnedBuf>,
|
||||
_zero_copy: Option<ZeroCopyBuf>,
|
||||
) -> Result<JsonOp, ErrBox> {
|
||||
let args: LinkArgs = serde_json::from_value(args)?;
|
||||
let oldname = deno_fs::resolve_from_cwd(Path::new(&args.oldname))?;
|
||||
|
@ -446,7 +446,7 @@ struct SymlinkArgs {
|
|||
fn op_symlink(
|
||||
state: &ThreadSafeState,
|
||||
args: Value,
|
||||
_zero_copy: Option<PinnedBuf>,
|
||||
_zero_copy: Option<ZeroCopyBuf>,
|
||||
) -> Result<JsonOp, ErrBox> {
|
||||
let args: SymlinkArgs = serde_json::from_value(args)?;
|
||||
let oldname = deno_fs::resolve_from_cwd(Path::new(&args.oldname))?;
|
||||
|
@ -478,7 +478,7 @@ struct ReadLinkArgs {
|
|||
fn op_read_link(
|
||||
state: &ThreadSafeState,
|
||||
args: Value,
|
||||
_zero_copy: Option<PinnedBuf>,
|
||||
_zero_copy: Option<ZeroCopyBuf>,
|
||||
) -> Result<JsonOp, ErrBox> {
|
||||
let args: ReadLinkArgs = serde_json::from_value(args)?;
|
||||
let name = deno_fs::resolve_from_cwd(Path::new(&args.name))?;
|
||||
|
@ -506,7 +506,7 @@ struct TruncateArgs {
|
|||
fn op_truncate(
|
||||
state: &ThreadSafeState,
|
||||
args: Value,
|
||||
_zero_copy: Option<PinnedBuf>,
|
||||
_zero_copy: Option<ZeroCopyBuf>,
|
||||
) -> Result<JsonOp, ErrBox> {
|
||||
let args: TruncateArgs = serde_json::from_value(args)?;
|
||||
let filename = deno_fs::resolve_from_cwd(Path::new(&args.name))?;
|
||||
|
@ -535,7 +535,7 @@ struct MakeTempDirArgs {
|
|||
fn op_make_temp_dir(
|
||||
state: &ThreadSafeState,
|
||||
args: Value,
|
||||
_zero_copy: Option<PinnedBuf>,
|
||||
_zero_copy: Option<ZeroCopyBuf>,
|
||||
) -> Result<JsonOp, ErrBox> {
|
||||
let args: MakeTempDirArgs = serde_json::from_value(args)?;
|
||||
|
||||
|
@ -575,7 +575,7 @@ struct Utime {
|
|||
fn op_utime(
|
||||
state: &ThreadSafeState,
|
||||
args: Value,
|
||||
_zero_copy: Option<PinnedBuf>,
|
||||
_zero_copy: Option<ZeroCopyBuf>,
|
||||
) -> Result<JsonOp, ErrBox> {
|
||||
let args: Utime = serde_json::from_value(args)?;
|
||||
state.check_write(Path::new(&args.filename))?;
|
||||
|
@ -590,7 +590,7 @@ fn op_utime(
|
|||
fn op_cwd(
|
||||
_state: &ThreadSafeState,
|
||||
_args: Value,
|
||||
_zero_copy: Option<PinnedBuf>,
|
||||
_zero_copy: Option<ZeroCopyBuf>,
|
||||
) -> Result<JsonOp, ErrBox> {
|
||||
let path = std::env::current_dir()?;
|
||||
let path_str = path.into_os_string().into_string().unwrap();
|
||||
|
|
|
@ -182,7 +182,7 @@ where
|
|||
pub fn op_read(
|
||||
state: &ThreadSafeState,
|
||||
rid: i32,
|
||||
zero_copy: Option<PinnedBuf>,
|
||||
zero_copy: Option<ZeroCopyBuf>,
|
||||
) -> Pin<Box<MinimalOp>> {
|
||||
debug!("read rid={}", rid);
|
||||
let zero_copy = match zero_copy {
|
||||
|
@ -327,7 +327,7 @@ where
|
|||
pub fn op_write(
|
||||
state: &ThreadSafeState,
|
||||
rid: i32,
|
||||
zero_copy: Option<PinnedBuf>,
|
||||
zero_copy: Option<ZeroCopyBuf>,
|
||||
) -> Pin<Box<MinimalOp>> {
|
||||
debug!("write rid={}", rid);
|
||||
let zero_copy = match zero_copy {
|
||||
|
|
|
@ -98,7 +98,7 @@ struct AcceptArgs {
|
|||
fn op_accept(
|
||||
state: &ThreadSafeState,
|
||||
args: Value,
|
||||
_zero_copy: Option<PinnedBuf>,
|
||||
_zero_copy: Option<ZeroCopyBuf>,
|
||||
) -> Result<JsonOp, ErrBox> {
|
||||
let args: AcceptArgs = serde_json::from_value(args)?;
|
||||
let rid = args.rid as u32;
|
||||
|
@ -143,7 +143,7 @@ struct ConnectArgs {
|
|||
fn op_connect(
|
||||
state: &ThreadSafeState,
|
||||
args: Value,
|
||||
_zero_copy: Option<PinnedBuf>,
|
||||
_zero_copy: Option<ZeroCopyBuf>,
|
||||
) -> Result<JsonOp, ErrBox> {
|
||||
let args: ConnectArgs = serde_json::from_value(args)?;
|
||||
assert_eq!(args.transport, "tcp"); // TODO Support others.
|
||||
|
@ -185,7 +185,7 @@ struct ShutdownArgs {
|
|||
fn op_shutdown(
|
||||
state: &ThreadSafeState,
|
||||
args: Value,
|
||||
_zero_copy: Option<PinnedBuf>,
|
||||
_zero_copy: Option<ZeroCopyBuf>,
|
||||
) -> Result<JsonOp, ErrBox> {
|
||||
let args: ShutdownArgs = serde_json::from_value(args)?;
|
||||
|
||||
|
@ -277,7 +277,7 @@ impl TcpListenerResource {
|
|||
fn op_listen(
|
||||
state: &ThreadSafeState,
|
||||
args: Value,
|
||||
_zero_copy: Option<PinnedBuf>,
|
||||
_zero_copy: Option<ZeroCopyBuf>,
|
||||
) -> Result<JsonOp, ErrBox> {
|
||||
let args: ListenArgs = serde_json::from_value(args)?;
|
||||
assert_eq!(args.transport, "tcp");
|
||||
|
|
|
@ -38,7 +38,7 @@ pub fn init(i: &mut Isolate, s: &ThreadSafeState) {
|
|||
fn op_start(
|
||||
state: &ThreadSafeState,
|
||||
_args: Value,
|
||||
_zero_copy: Option<PinnedBuf>,
|
||||
_zero_copy: Option<ZeroCopyBuf>,
|
||||
) -> Result<JsonOp, ErrBox> {
|
||||
let gs = &state.global_state;
|
||||
let script_args = if gs.flags.argv.len() >= 2 {
|
||||
|
@ -70,7 +70,7 @@ struct GetDirArgs {
|
|||
fn op_get_dir(
|
||||
state: &ThreadSafeState,
|
||||
args: Value,
|
||||
_zero_copy: Option<PinnedBuf>,
|
||||
_zero_copy: Option<ZeroCopyBuf>,
|
||||
) -> Result<JsonOp, ErrBox> {
|
||||
state.check_env()?;
|
||||
let args: GetDirArgs = serde_json::from_value(args)?;
|
||||
|
@ -116,7 +116,7 @@ fn op_get_dir(
|
|||
fn op_exec_path(
|
||||
state: &ThreadSafeState,
|
||||
_args: Value,
|
||||
_zero_copy: Option<PinnedBuf>,
|
||||
_zero_copy: Option<ZeroCopyBuf>,
|
||||
) -> Result<JsonOp, ErrBox> {
|
||||
state.check_env()?;
|
||||
let current_exe = env::current_exe().unwrap();
|
||||
|
@ -136,7 +136,7 @@ struct SetEnv {
|
|||
fn op_set_env(
|
||||
state: &ThreadSafeState,
|
||||
args: Value,
|
||||
_zero_copy: Option<PinnedBuf>,
|
||||
_zero_copy: Option<ZeroCopyBuf>,
|
||||
) -> Result<JsonOp, ErrBox> {
|
||||
let args: SetEnv = serde_json::from_value(args)?;
|
||||
state.check_env()?;
|
||||
|
@ -147,7 +147,7 @@ fn op_set_env(
|
|||
fn op_env(
|
||||
state: &ThreadSafeState,
|
||||
_args: Value,
|
||||
_zero_copy: Option<PinnedBuf>,
|
||||
_zero_copy: Option<ZeroCopyBuf>,
|
||||
) -> Result<JsonOp, ErrBox> {
|
||||
state.check_env()?;
|
||||
let v = env::vars().collect::<HashMap<String, String>>();
|
||||
|
@ -162,7 +162,7 @@ struct GetEnv {
|
|||
fn op_get_env(
|
||||
state: &ThreadSafeState,
|
||||
args: Value,
|
||||
_zero_copy: Option<PinnedBuf>,
|
||||
_zero_copy: Option<ZeroCopyBuf>,
|
||||
) -> Result<JsonOp, ErrBox> {
|
||||
let args: GetEnv = serde_json::from_value(args)?;
|
||||
state.check_env()?;
|
||||
|
@ -181,7 +181,7 @@ struct Exit {
|
|||
fn op_exit(
|
||||
_s: &ThreadSafeState,
|
||||
args: Value,
|
||||
_zero_copy: Option<PinnedBuf>,
|
||||
_zero_copy: Option<ZeroCopyBuf>,
|
||||
) -> Result<JsonOp, ErrBox> {
|
||||
let args: Exit = serde_json::from_value(args)?;
|
||||
std::process::exit(args.code)
|
||||
|
@ -190,7 +190,7 @@ fn op_exit(
|
|||
fn op_is_tty(
|
||||
_s: &ThreadSafeState,
|
||||
_args: Value,
|
||||
_zero_copy: Option<PinnedBuf>,
|
||||
_zero_copy: Option<ZeroCopyBuf>,
|
||||
) -> Result<JsonOp, ErrBox> {
|
||||
Ok(JsonOp::Sync(json!({
|
||||
"stdin": atty::is(atty::Stream::Stdin),
|
||||
|
@ -202,7 +202,7 @@ fn op_is_tty(
|
|||
fn op_hostname(
|
||||
state: &ThreadSafeState,
|
||||
_args: Value,
|
||||
_zero_copy: Option<PinnedBuf>,
|
||||
_zero_copy: Option<ZeroCopyBuf>,
|
||||
) -> Result<JsonOp, ErrBox> {
|
||||
state.check_env()?;
|
||||
let hostname = sys_info::hostname().unwrap_or_else(|_| "".to_owned());
|
||||
|
|
|
@ -40,7 +40,7 @@ fn resolve_path(path: &str) -> String {
|
|||
pub fn op_query_permission(
|
||||
state: &ThreadSafeState,
|
||||
args: Value,
|
||||
_zero_copy: Option<PinnedBuf>,
|
||||
_zero_copy: Option<ZeroCopyBuf>,
|
||||
) -> Result<JsonOp, ErrBox> {
|
||||
let args: PermissionArgs = serde_json::from_value(args)?;
|
||||
let permissions = state.permissions.lock().unwrap();
|
||||
|
@ -56,7 +56,7 @@ pub fn op_query_permission(
|
|||
pub fn op_revoke_permission(
|
||||
state: &ThreadSafeState,
|
||||
args: Value,
|
||||
_zero_copy: Option<PinnedBuf>,
|
||||
_zero_copy: Option<ZeroCopyBuf>,
|
||||
) -> Result<JsonOp, ErrBox> {
|
||||
let args: PermissionArgs = serde_json::from_value(args)?;
|
||||
let mut permissions = state.permissions.lock().unwrap();
|
||||
|
@ -82,7 +82,7 @@ pub fn op_revoke_permission(
|
|||
pub fn op_request_permission(
|
||||
state: &ThreadSafeState,
|
||||
args: Value,
|
||||
_zero_copy: Option<PinnedBuf>,
|
||||
_zero_copy: Option<ZeroCopyBuf>,
|
||||
) -> Result<JsonOp, ErrBox> {
|
||||
let args: PermissionArgs = serde_json::from_value(args)?;
|
||||
let mut permissions = state.permissions.lock().unwrap();
|
||||
|
|
|
@ -60,7 +60,7 @@ pub fn op_open_plugin(
|
|||
registry: &Arc<deno_core::OpRegistry>,
|
||||
state: &ThreadSafeState,
|
||||
args: Value,
|
||||
_zero_copy: Option<PinnedBuf>,
|
||||
_zero_copy: Option<ZeroCopyBuf>,
|
||||
) -> Result<JsonOp, ErrBox> {
|
||||
let args: OpenPluginArgs = serde_json::from_value(args)?;
|
||||
let filename = deno_fs::resolve_from_cwd(Path::new(&args.filename))?;
|
||||
|
|
|
@ -80,7 +80,7 @@ impl Resource for ChildResource {}
|
|||
fn op_run(
|
||||
state: &ThreadSafeState,
|
||||
args: Value,
|
||||
_zero_copy: Option<PinnedBuf>,
|
||||
_zero_copy: Option<ZeroCopyBuf>,
|
||||
) -> Result<JsonOp, ErrBox> {
|
||||
let run_args: RunArgs = serde_json::from_value(args)?;
|
||||
|
||||
|
@ -208,7 +208,7 @@ struct RunStatusArgs {
|
|||
fn op_run_status(
|
||||
state: &ThreadSafeState,
|
||||
args: Value,
|
||||
_zero_copy: Option<PinnedBuf>,
|
||||
_zero_copy: Option<ZeroCopyBuf>,
|
||||
) -> Result<JsonOp, ErrBox> {
|
||||
let args: RunStatusArgs = serde_json::from_value(args)?;
|
||||
let rid = args.rid as u32;
|
||||
|
@ -256,7 +256,7 @@ struct KillArgs {
|
|||
fn op_kill(
|
||||
state: &ThreadSafeState,
|
||||
args: Value,
|
||||
_zero_copy: Option<PinnedBuf>,
|
||||
_zero_copy: Option<ZeroCopyBuf>,
|
||||
) -> Result<JsonOp, ErrBox> {
|
||||
state.check_run()?;
|
||||
|
||||
|
|
|
@ -16,7 +16,7 @@ pub fn init(i: &mut Isolate, s: &ThreadSafeState) {
|
|||
fn op_get_random_values(
|
||||
state: &ThreadSafeState,
|
||||
_args: Value,
|
||||
zero_copy: Option<PinnedBuf>,
|
||||
zero_copy: Option<ZeroCopyBuf>,
|
||||
) -> Result<JsonOp, ErrBox> {
|
||||
assert!(zero_copy.is_some());
|
||||
|
||||
|
|
|
@ -34,7 +34,7 @@ struct ReplStartArgs {
|
|||
fn op_repl_start(
|
||||
state: &ThreadSafeState,
|
||||
args: Value,
|
||||
_zero_copy: Option<PinnedBuf>,
|
||||
_zero_copy: Option<ZeroCopyBuf>,
|
||||
) -> Result<JsonOp, ErrBox> {
|
||||
let args: ReplStartArgs = serde_json::from_value(args)?;
|
||||
|
||||
|
@ -57,7 +57,7 @@ struct ReplReadlineArgs {
|
|||
fn op_repl_readline(
|
||||
state: &ThreadSafeState,
|
||||
args: Value,
|
||||
_zero_copy: Option<PinnedBuf>,
|
||||
_zero_copy: Option<ZeroCopyBuf>,
|
||||
) -> Result<JsonOp, ErrBox> {
|
||||
let args: ReplReadlineArgs = serde_json::from_value(args)?;
|
||||
let rid = args.rid as u32;
|
||||
|
|
|
@ -11,7 +11,7 @@ pub fn init(i: &mut Isolate, s: &ThreadSafeState) {
|
|||
fn op_resources(
|
||||
state: &ThreadSafeState,
|
||||
_args: Value,
|
||||
_zero_copy: Option<PinnedBuf>,
|
||||
_zero_copy: Option<ZeroCopyBuf>,
|
||||
) -> Result<JsonOp, ErrBox> {
|
||||
let resource_table = state.lock_resource_table();
|
||||
let serialized_resources = resource_table.entries();
|
||||
|
|
|
@ -24,7 +24,7 @@ struct CompileArgs {
|
|||
fn op_compile(
|
||||
state: &ThreadSafeState,
|
||||
args: Value,
|
||||
_zero_copy: Option<PinnedBuf>,
|
||||
_zero_copy: Option<ZeroCopyBuf>,
|
||||
) -> Result<JsonOp, ErrBox> {
|
||||
let args: CompileArgs = serde_json::from_value(args)?;
|
||||
Ok(JsonOp::Async(runtime_compile_async(
|
||||
|
@ -45,7 +45,7 @@ struct TranspileArgs {
|
|||
fn op_transpile(
|
||||
state: &ThreadSafeState,
|
||||
args: Value,
|
||||
_zero_copy: Option<PinnedBuf>,
|
||||
_zero_copy: Option<ZeroCopyBuf>,
|
||||
) -> Result<JsonOp, ErrBox> {
|
||||
let args: TranspileArgs = serde_json::from_value(args)?;
|
||||
Ok(JsonOp::Async(runtime_transpile_async(
|
||||
|
|
|
@ -58,7 +58,7 @@ struct SignalArgs {
|
|||
fn op_signal_bind(
|
||||
state: &ThreadSafeState,
|
||||
args: Value,
|
||||
_zero_copy: Option<PinnedBuf>,
|
||||
_zero_copy: Option<ZeroCopyBuf>,
|
||||
) -> Result<JsonOp, ErrBox> {
|
||||
let args: BindSignalArgs = serde_json::from_value(args)?;
|
||||
let mut table = state.lock_resource_table();
|
||||
|
@ -78,7 +78,7 @@ fn op_signal_bind(
|
|||
fn op_signal_poll(
|
||||
state: &ThreadSafeState,
|
||||
args: Value,
|
||||
_zero_copy: Option<PinnedBuf>,
|
||||
_zero_copy: Option<ZeroCopyBuf>,
|
||||
) -> Result<JsonOp, ErrBox> {
|
||||
let args: SignalArgs = serde_json::from_value(args)?;
|
||||
let rid = args.rid as u32;
|
||||
|
@ -101,7 +101,7 @@ fn op_signal_poll(
|
|||
pub fn op_signal_unbind(
|
||||
state: &ThreadSafeState,
|
||||
args: Value,
|
||||
_zero_copy: Option<PinnedBuf>,
|
||||
_zero_copy: Option<ZeroCopyBuf>,
|
||||
) -> Result<JsonOp, ErrBox> {
|
||||
let args: SignalArgs = serde_json::from_value(args)?;
|
||||
let rid = args.rid as u32;
|
||||
|
@ -122,7 +122,7 @@ pub fn op_signal_unbind(
|
|||
pub fn op_signal_bind(
|
||||
_state: &ThreadSafeState,
|
||||
_args: Value,
|
||||
_zero_copy: Option<PinnedBuf>,
|
||||
_zero_copy: Option<ZeroCopyBuf>,
|
||||
) -> Result<JsonOp, ErrBox> {
|
||||
unimplemented!();
|
||||
}
|
||||
|
@ -131,7 +131,7 @@ pub fn op_signal_bind(
|
|||
fn op_signal_unbind(
|
||||
_state: &ThreadSafeState,
|
||||
_args: Value,
|
||||
_zero_copy: Option<PinnedBuf>,
|
||||
_zero_copy: Option<ZeroCopyBuf>,
|
||||
) -> Result<JsonOp, ErrBox> {
|
||||
unimplemented!();
|
||||
}
|
||||
|
@ -140,7 +140,7 @@ fn op_signal_unbind(
|
|||
fn op_signal_poll(
|
||||
_state: &ThreadSafeState,
|
||||
_args: Value,
|
||||
_zero_copy: Option<PinnedBuf>,
|
||||
_zero_copy: Option<ZeroCopyBuf>,
|
||||
) -> Result<JsonOp, ErrBox> {
|
||||
unimplemented!();
|
||||
}
|
||||
|
|
|
@ -23,7 +23,7 @@ pub fn init(i: &mut Isolate, s: &ThreadSafeState) {
|
|||
fn op_global_timer_stop(
|
||||
state: &ThreadSafeState,
|
||||
_args: Value,
|
||||
_zero_copy: Option<PinnedBuf>,
|
||||
_zero_copy: Option<ZeroCopyBuf>,
|
||||
) -> Result<JsonOp, ErrBox> {
|
||||
let state = state;
|
||||
let mut t = state.global_timer.lock().unwrap();
|
||||
|
@ -39,7 +39,7 @@ struct GlobalTimerArgs {
|
|||
fn op_global_timer(
|
||||
state: &ThreadSafeState,
|
||||
args: Value,
|
||||
_zero_copy: Option<PinnedBuf>,
|
||||
_zero_copy: Option<ZeroCopyBuf>,
|
||||
) -> Result<JsonOp, ErrBox> {
|
||||
let args: GlobalTimerArgs = serde_json::from_value(args)?;
|
||||
let val = args.timeout;
|
||||
|
@ -61,7 +61,7 @@ fn op_global_timer(
|
|||
fn op_now(
|
||||
state: &ThreadSafeState,
|
||||
_args: Value,
|
||||
_zero_copy: Option<PinnedBuf>,
|
||||
_zero_copy: Option<ZeroCopyBuf>,
|
||||
) -> Result<JsonOp, ErrBox> {
|
||||
let seconds = state.start_time.elapsed().as_secs();
|
||||
let mut subsec_nanos = state.start_time.elapsed().subsec_nanos();
|
||||
|
|
|
@ -63,7 +63,7 @@ struct ConnectTLSArgs {
|
|||
pub fn op_connect_tls(
|
||||
state: &ThreadSafeState,
|
||||
args: Value,
|
||||
_zero_copy: Option<PinnedBuf>,
|
||||
_zero_copy: Option<ZeroCopyBuf>,
|
||||
) -> Result<JsonOp, ErrBox> {
|
||||
let args: ConnectTLSArgs = serde_json::from_value(args)?;
|
||||
let cert_file = args.cert_file.clone();
|
||||
|
@ -246,7 +246,7 @@ struct ListenTlsArgs {
|
|||
fn op_listen_tls(
|
||||
state: &ThreadSafeState,
|
||||
args: Value,
|
||||
_zero_copy: Option<PinnedBuf>,
|
||||
_zero_copy: Option<ZeroCopyBuf>,
|
||||
) -> Result<JsonOp, ErrBox> {
|
||||
let args: ListenTlsArgs = serde_json::from_value(args)?;
|
||||
assert_eq!(args.transport, "tcp");
|
||||
|
@ -357,7 +357,7 @@ struct AcceptTlsArgs {
|
|||
fn op_accept_tls(
|
||||
state: &ThreadSafeState,
|
||||
args: Value,
|
||||
_zero_copy: Option<PinnedBuf>,
|
||||
_zero_copy: Option<ZeroCopyBuf>,
|
||||
) -> Result<JsonOp, ErrBox> {
|
||||
let args: AcceptTlsArgs = serde_json::from_value(args)?;
|
||||
let rid = args.rid as u32;
|
||||
|
|
|
@ -27,7 +27,7 @@ pub fn init(i: &mut Isolate, s: &ThreadSafeState) {
|
|||
fn op_worker_get_message(
|
||||
state: &ThreadSafeState,
|
||||
_args: Value,
|
||||
_data: Option<PinnedBuf>,
|
||||
_data: Option<ZeroCopyBuf>,
|
||||
) -> Result<JsonOp, ErrBox> {
|
||||
let state_ = state.clone();
|
||||
let op = async move {
|
||||
|
@ -44,7 +44,7 @@ fn op_worker_get_message(
|
|||
fn op_worker_post_message(
|
||||
state: &ThreadSafeState,
|
||||
_args: Value,
|
||||
data: Option<PinnedBuf>,
|
||||
data: Option<ZeroCopyBuf>,
|
||||
) -> Result<JsonOp, ErrBox> {
|
||||
let d = Vec::from(data.unwrap().as_ref()).into_boxed_slice();
|
||||
let mut sender = state.worker_channels.sender.clone();
|
||||
|
|
|
@ -69,7 +69,7 @@ struct CreateWorkerArgs {
|
|||
fn op_create_worker(
|
||||
state: &ThreadSafeState,
|
||||
args: Value,
|
||||
_data: Option<PinnedBuf>,
|
||||
_data: Option<ZeroCopyBuf>,
|
||||
) -> Result<JsonOp, ErrBox> {
|
||||
let args: CreateWorkerArgs = serde_json::from_value(args)?;
|
||||
|
||||
|
@ -180,7 +180,7 @@ struct WorkerArgs {
|
|||
fn op_host_get_worker_loaded(
|
||||
state: &ThreadSafeState,
|
||||
args: Value,
|
||||
_data: Option<PinnedBuf>,
|
||||
_data: Option<ZeroCopyBuf>,
|
||||
) -> Result<JsonOp, ErrBox> {
|
||||
let args: WorkerArgs = serde_json::from_value(args)?;
|
||||
let id = args.id as u32;
|
||||
|
@ -198,7 +198,7 @@ fn op_host_get_worker_loaded(
|
|||
fn op_host_poll_worker(
|
||||
state: &ThreadSafeState,
|
||||
args: Value,
|
||||
_data: Option<PinnedBuf>,
|
||||
_data: Option<ZeroCopyBuf>,
|
||||
) -> Result<JsonOp, ErrBox> {
|
||||
let args: WorkerArgs = serde_json::from_value(args)?;
|
||||
let id = args.id as u32;
|
||||
|
@ -226,7 +226,7 @@ fn op_host_poll_worker(
|
|||
fn op_host_close_worker(
|
||||
state: &ThreadSafeState,
|
||||
args: Value,
|
||||
_data: Option<PinnedBuf>,
|
||||
_data: Option<ZeroCopyBuf>,
|
||||
) -> Result<JsonOp, ErrBox> {
|
||||
let args: WorkerArgs = serde_json::from_value(args)?;
|
||||
let id = args.id as u32;
|
||||
|
@ -249,7 +249,7 @@ fn op_host_close_worker(
|
|||
fn op_host_resume_worker(
|
||||
state: &ThreadSafeState,
|
||||
args: Value,
|
||||
_data: Option<PinnedBuf>,
|
||||
_data: Option<ZeroCopyBuf>,
|
||||
) -> Result<JsonOp, ErrBox> {
|
||||
let args: WorkerArgs = serde_json::from_value(args)?;
|
||||
let id = args.id as u32;
|
||||
|
@ -270,7 +270,7 @@ struct HostGetMessageArgs {
|
|||
fn op_host_get_message(
|
||||
state: &ThreadSafeState,
|
||||
args: Value,
|
||||
_data: Option<PinnedBuf>,
|
||||
_data: Option<ZeroCopyBuf>,
|
||||
) -> Result<JsonOp, ErrBox> {
|
||||
let args: HostGetMessageArgs = serde_json::from_value(args)?;
|
||||
let state_ = state.clone();
|
||||
|
@ -297,7 +297,7 @@ struct HostPostMessageArgs {
|
|||
fn op_host_post_message(
|
||||
state: &ThreadSafeState,
|
||||
args: Value,
|
||||
data: Option<PinnedBuf>,
|
||||
data: Option<ZeroCopyBuf>,
|
||||
) -> Result<JsonOp, ErrBox> {
|
||||
let args: HostPostMessageArgs = serde_json::from_value(args)?;
|
||||
let id = args.id as u32;
|
||||
|
@ -317,7 +317,7 @@ fn op_host_post_message(
|
|||
fn op_metrics(
|
||||
state: &ThreadSafeState,
|
||||
_args: Value,
|
||||
_zero_copy: Option<PinnedBuf>,
|
||||
_zero_copy: Option<ZeroCopyBuf>,
|
||||
) -> Result<JsonOp, ErrBox> {
|
||||
let m = &state.metrics;
|
||||
|
||||
|
|
28
cli/state.rs
28
cli/state.rs
|
@ -15,8 +15,8 @@ use deno_core::ErrBox;
|
|||
use deno_core::Loader;
|
||||
use deno_core::ModuleSpecifier;
|
||||
use deno_core::Op;
|
||||
use deno_core::PinnedBuf;
|
||||
use deno_core::ResourceTable;
|
||||
use deno_core::ZeroCopyBuf;
|
||||
use futures::channel::mpsc;
|
||||
use futures::future::FutureExt;
|
||||
use futures::future::TryFutureExt;
|
||||
|
@ -83,13 +83,13 @@ impl ThreadSafeState {
|
|||
pub fn core_op<D>(
|
||||
&self,
|
||||
dispatcher: D,
|
||||
) -> impl Fn(&[u8], Option<PinnedBuf>) -> CoreOp
|
||||
) -> impl Fn(&[u8], Option<ZeroCopyBuf>) -> CoreOp
|
||||
where
|
||||
D: Fn(&[u8], Option<PinnedBuf>) -> CoreOp,
|
||||
D: Fn(&[u8], Option<ZeroCopyBuf>) -> CoreOp,
|
||||
{
|
||||
let state = self.clone();
|
||||
|
||||
move |control: &[u8], zero_copy: Option<PinnedBuf>| -> CoreOp {
|
||||
move |control: &[u8], zero_copy: Option<ZeroCopyBuf>| -> CoreOp {
|
||||
let bytes_sent_control = control.len();
|
||||
let bytes_sent_zero_copy =
|
||||
zero_copy.as_ref().map(|b| b.len()).unwrap_or(0);
|
||||
|
@ -126,13 +126,13 @@ impl ThreadSafeState {
|
|||
pub fn stateful_minimal_op<D>(
|
||||
&self,
|
||||
dispatcher: D,
|
||||
) -> impl Fn(i32, Option<PinnedBuf>) -> Pin<Box<MinimalOp>>
|
||||
) -> impl Fn(i32, Option<ZeroCopyBuf>) -> Pin<Box<MinimalOp>>
|
||||
where
|
||||
D: Fn(&ThreadSafeState, i32, Option<PinnedBuf>) -> Pin<Box<MinimalOp>>,
|
||||
D: Fn(&ThreadSafeState, i32, Option<ZeroCopyBuf>) -> Pin<Box<MinimalOp>>,
|
||||
{
|
||||
let state = self.clone();
|
||||
|
||||
move |rid: i32, zero_copy: Option<PinnedBuf>| -> Pin<Box<MinimalOp>> {
|
||||
move |rid: i32, zero_copy: Option<ZeroCopyBuf>| -> Pin<Box<MinimalOp>> {
|
||||
dispatcher(&state, rid, zero_copy)
|
||||
}
|
||||
}
|
||||
|
@ -145,15 +145,19 @@ impl ThreadSafeState {
|
|||
pub fn stateful_op<D>(
|
||||
&self,
|
||||
dispatcher: D,
|
||||
) -> impl Fn(Value, Option<PinnedBuf>) -> Result<JsonOp, ErrBox>
|
||||
) -> impl Fn(Value, Option<ZeroCopyBuf>) -> Result<JsonOp, ErrBox>
|
||||
where
|
||||
D: Fn(&ThreadSafeState, Value, Option<PinnedBuf>) -> Result<JsonOp, ErrBox>,
|
||||
D: Fn(
|
||||
&ThreadSafeState,
|
||||
Value,
|
||||
Option<ZeroCopyBuf>,
|
||||
) -> Result<JsonOp, ErrBox>,
|
||||
{
|
||||
let state = self.clone();
|
||||
|
||||
move |args: Value, zero_copy: Option<PinnedBuf>| -> Result<JsonOp, ErrBox> {
|
||||
dispatcher(&state, args, zero_copy)
|
||||
}
|
||||
move |args: Value,
|
||||
zero_copy: Option<ZeroCopyBuf>|
|
||||
-> Result<JsonOp, ErrBox> { dispatcher(&state, args, zero_copy) }
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
use crate::es_isolate::EsIsolate;
|
||||
use crate::isolate::Isolate;
|
||||
use crate::isolate::PinnedBuf;
|
||||
use crate::isolate::ZeroCopyBuf;
|
||||
|
||||
use rusty_v8 as v8;
|
||||
use v8::MapFnTo;
|
||||
|
@ -405,9 +405,9 @@ fn send(
|
|||
Err(..) => &[],
|
||||
};
|
||||
|
||||
let zero_copy: Option<PinnedBuf> =
|
||||
let zero_copy: Option<ZeroCopyBuf> =
|
||||
v8::Local::<v8::ArrayBufferView>::try_from(args.get(2))
|
||||
.map(PinnedBuf::new)
|
||||
.map(ZeroCopyBuf::new)
|
||||
.ok();
|
||||
|
||||
// If response is empty then it's either async op or exception was thrown
|
||||
|
|
|
@ -597,7 +597,7 @@ pub mod tests {
|
|||
use super::*;
|
||||
use crate::isolate::js_check;
|
||||
use crate::isolate::tests::run_in_task;
|
||||
use crate::isolate::PinnedBuf;
|
||||
use crate::isolate::ZeroCopyBuf;
|
||||
use crate::modules::SourceCodeInfoFuture;
|
||||
use crate::ops::*;
|
||||
use std::io;
|
||||
|
@ -642,7 +642,7 @@ pub mod tests {
|
|||
let mut isolate = EsIsolate::new(loader, StartupData::None, false);
|
||||
|
||||
let dispatcher =
|
||||
move |control: &[u8], _zero_copy: Option<PinnedBuf>| -> CoreOp {
|
||||
move |control: &[u8], _zero_copy: Option<ZeroCopyBuf>| -> CoreOp {
|
||||
dispatch_count_.fetch_add(1, Ordering::Relaxed);
|
||||
assert_eq!(control.len(), 1);
|
||||
assert_eq!(control[0], 42);
|
||||
|
|
|
@ -108,12 +108,12 @@ fn test_record_from() {
|
|||
pub type HttpOp = dyn Future<Output = Result<i32, std::io::Error>> + Send;
|
||||
|
||||
pub type HttpOpHandler =
|
||||
fn(record: Record, zero_copy_buf: Option<PinnedBuf>) -> Pin<Box<HttpOp>>;
|
||||
fn(record: Record, zero_copy_buf: Option<ZeroCopyBuf>) -> Pin<Box<HttpOp>>;
|
||||
|
||||
fn http_op(
|
||||
handler: HttpOpHandler,
|
||||
) -> impl Fn(&[u8], Option<PinnedBuf>) -> CoreOp {
|
||||
move |control: &[u8], zero_copy_buf: Option<PinnedBuf>| -> CoreOp {
|
||||
) -> impl Fn(&[u8], Option<ZeroCopyBuf>) -> CoreOp {
|
||||
move |control: &[u8], zero_copy_buf: Option<ZeroCopyBuf>| -> CoreOp {
|
||||
let record = Record::from(control);
|
||||
let is_sync = record.promise_id == 0;
|
||||
let op = handler(record.clone(), zero_copy_buf);
|
||||
|
@ -232,7 +232,7 @@ impl Future for Accept {
|
|||
|
||||
fn op_accept(
|
||||
record: Record,
|
||||
_zero_copy_buf: Option<PinnedBuf>,
|
||||
_zero_copy_buf: Option<ZeroCopyBuf>,
|
||||
) -> Pin<Box<HttpOp>> {
|
||||
let rid = record.arg as u32;
|
||||
debug!("accept {}", rid);
|
||||
|
@ -250,7 +250,7 @@ fn op_accept(
|
|||
|
||||
fn op_listen(
|
||||
_record: Record,
|
||||
_zero_copy_buf: Option<PinnedBuf>,
|
||||
_zero_copy_buf: Option<ZeroCopyBuf>,
|
||||
) -> Pin<Box<HttpOp>> {
|
||||
debug!("listen");
|
||||
let fut = async {
|
||||
|
@ -266,7 +266,7 @@ fn op_listen(
|
|||
|
||||
fn op_close(
|
||||
record: Record,
|
||||
_zero_copy_buf: Option<PinnedBuf>,
|
||||
_zero_copy_buf: Option<ZeroCopyBuf>,
|
||||
) -> Pin<Box<HttpOp>> {
|
||||
debug!("close");
|
||||
let fut = async move {
|
||||
|
@ -282,7 +282,7 @@ fn op_close(
|
|||
|
||||
struct Read {
|
||||
rid: ResourceId,
|
||||
buf: PinnedBuf,
|
||||
buf: ZeroCopyBuf,
|
||||
}
|
||||
|
||||
impl Future for Read {
|
||||
|
@ -304,7 +304,7 @@ impl Future for Read {
|
|||
|
||||
fn op_read(
|
||||
record: Record,
|
||||
zero_copy_buf: Option<PinnedBuf>,
|
||||
zero_copy_buf: Option<ZeroCopyBuf>,
|
||||
) -> Pin<Box<HttpOp>> {
|
||||
let rid = record.arg as u32;
|
||||
debug!("read rid={}", rid);
|
||||
|
@ -325,7 +325,7 @@ fn op_read(
|
|||
|
||||
struct Write {
|
||||
rid: ResourceId,
|
||||
buf: PinnedBuf,
|
||||
buf: ZeroCopyBuf,
|
||||
}
|
||||
|
||||
impl Future for Write {
|
||||
|
@ -347,7 +347,7 @@ impl Future for Write {
|
|||
|
||||
fn op_write(
|
||||
record: Record,
|
||||
zero_copy_buf: Option<PinnedBuf>,
|
||||
zero_copy_buf: Option<ZeroCopyBuf>,
|
||||
) -> Pin<Box<HttpOp>> {
|
||||
let rid = record.arg as u32;
|
||||
debug!("write rid={}", rid);
|
||||
|
|
|
@ -30,20 +30,21 @@ use std::pin::Pin;
|
|||
use std::sync::{Arc, Mutex, Once};
|
||||
use std::task::Context;
|
||||
use std::task::Poll;
|
||||
/// A PinnedBuf encapsulates a slice that's been borrowed from a JavaScript
|
||||
|
||||
/// A ZeroCopyBuf encapsulates a slice that's been borrowed from a JavaScript
|
||||
/// ArrayBuffer object. JavaScript objects can normally be garbage collected,
|
||||
/// but the existence of a PinnedBuf inhibits this until it is dropped. It
|
||||
/// behaves much like an Arc<[u8]>, although a PinnedBuf currently can't be
|
||||
/// but the existence of a ZeroCopyBuf inhibits this until it is dropped. It
|
||||
/// behaves much like an Arc<[u8]>, although a ZeroCopyBuf currently can't be
|
||||
/// cloned.
|
||||
pub struct PinnedBuf {
|
||||
pub struct ZeroCopyBuf {
|
||||
backing_store: v8::SharedRef<v8::BackingStore>,
|
||||
byte_offset: usize,
|
||||
byte_length: usize,
|
||||
}
|
||||
|
||||
unsafe impl Send for PinnedBuf {}
|
||||
unsafe impl Send for ZeroCopyBuf {}
|
||||
|
||||
impl PinnedBuf {
|
||||
impl ZeroCopyBuf {
|
||||
pub fn new(view: v8::Local<v8::ArrayBufferView>) -> Self {
|
||||
let backing_store = view.buffer().unwrap().get_backing_store();
|
||||
let byte_offset = view.byte_offset();
|
||||
|
@ -56,7 +57,7 @@ impl PinnedBuf {
|
|||
}
|
||||
}
|
||||
|
||||
impl Deref for PinnedBuf {
|
||||
impl Deref for ZeroCopyBuf {
|
||||
type Target = [u8];
|
||||
fn deref(&self) -> &[u8] {
|
||||
let buf = unsafe { &**self.backing_store.get() };
|
||||
|
@ -64,20 +65,20 @@ impl Deref for PinnedBuf {
|
|||
}
|
||||
}
|
||||
|
||||
impl DerefMut for PinnedBuf {
|
||||
impl DerefMut for ZeroCopyBuf {
|
||||
fn deref_mut(&mut self) -> &mut [u8] {
|
||||
let buf = unsafe { &mut **self.backing_store.get() };
|
||||
&mut buf[self.byte_offset..self.byte_offset + self.byte_length]
|
||||
}
|
||||
}
|
||||
|
||||
impl AsRef<[u8]> for PinnedBuf {
|
||||
impl AsRef<[u8]> for ZeroCopyBuf {
|
||||
fn as_ref(&self) -> &[u8] {
|
||||
&*self
|
||||
}
|
||||
}
|
||||
|
||||
impl AsMut<[u8]> for PinnedBuf {
|
||||
impl AsMut<[u8]> for ZeroCopyBuf {
|
||||
fn as_mut(&mut self) -> &mut [u8] {
|
||||
&mut *self
|
||||
}
|
||||
|
@ -436,7 +437,7 @@ impl Isolate {
|
|||
/// Requires runtime to explicitly ask for op ids before using any of the ops.
|
||||
pub fn register_op<F>(&self, name: &str, op: F) -> OpId
|
||||
where
|
||||
F: Fn(&[u8], Option<PinnedBuf>) -> CoreOp + Send + Sync + 'static,
|
||||
F: Fn(&[u8], Option<ZeroCopyBuf>) -> CoreOp + Send + Sync + 'static,
|
||||
{
|
||||
self.op_registry.register(name, op)
|
||||
}
|
||||
|
@ -476,7 +477,7 @@ impl Isolate {
|
|||
&mut self,
|
||||
op_id: OpId,
|
||||
control_buf: &[u8],
|
||||
zero_copy_buf: Option<PinnedBuf>,
|
||||
zero_copy_buf: Option<ZeroCopyBuf>,
|
||||
) -> Option<(OpId, Box<[u8]>)> {
|
||||
let maybe_op = self.op_registry.call(op_id, control_buf, zero_copy_buf);
|
||||
|
||||
|
@ -817,7 +818,7 @@ pub mod tests {
|
|||
let mut isolate = Isolate::new(StartupData::None, false);
|
||||
|
||||
let dispatcher =
|
||||
move |control: &[u8], _zero_copy: Option<PinnedBuf>| -> CoreOp {
|
||||
move |control: &[u8], _zero_copy: Option<ZeroCopyBuf>| -> CoreOp {
|
||||
dispatch_count_.fetch_add(1, Ordering::Relaxed);
|
||||
match mode {
|
||||
Mode::Async => {
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license.
|
||||
use crate::PinnedBuf;
|
||||
use crate::ZeroCopyBuf;
|
||||
use futures::Future;
|
||||
use std::collections::HashMap;
|
||||
use std::pin::Pin;
|
||||
|
@ -32,7 +32,7 @@ pub type CoreOp = Op<CoreError>;
|
|||
|
||||
/// Main type describing op
|
||||
pub type OpDispatcher =
|
||||
dyn Fn(&[u8], Option<PinnedBuf>) -> CoreOp + Send + Sync + 'static;
|
||||
dyn Fn(&[u8], Option<ZeroCopyBuf>) -> CoreOp + Send + Sync + 'static;
|
||||
|
||||
#[derive(Default)]
|
||||
pub struct OpRegistry {
|
||||
|
@ -53,7 +53,7 @@ impl OpRegistry {
|
|||
|
||||
pub fn register<F>(&self, name: &str, op: F) -> OpId
|
||||
where
|
||||
F: Fn(&[u8], Option<PinnedBuf>) -> CoreOp + Send + Sync + 'static,
|
||||
F: Fn(&[u8], Option<ZeroCopyBuf>) -> CoreOp + Send + Sync + 'static,
|
||||
{
|
||||
let mut lock = self.dispatchers.write().unwrap();
|
||||
let op_id = lock.len() as u32;
|
||||
|
@ -82,7 +82,7 @@ impl OpRegistry {
|
|||
&self,
|
||||
op_id: OpId,
|
||||
control: &[u8],
|
||||
zero_copy_buf: Option<PinnedBuf>,
|
||||
zero_copy_buf: Option<ZeroCopyBuf>,
|
||||
) -> Option<CoreOp> {
|
||||
// Op with id 0 has special meaning - it's a special op that is always
|
||||
// provided to retrieve op id map. The map consists of name to `OpId`
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
use crate::isolate::PinnedBuf;
|
||||
use crate::isolate::ZeroCopyBuf;
|
||||
use crate::ops::CoreOp;
|
||||
|
||||
pub type PluginInitFn = fn(context: &mut dyn PluginInitContext);
|
||||
|
@ -7,7 +7,9 @@ pub trait PluginInitContext {
|
|||
fn register_op(
|
||||
&mut self,
|
||||
name: &str,
|
||||
op: Box<dyn Fn(&[u8], Option<PinnedBuf>) -> CoreOp + Send + Sync + 'static>,
|
||||
op: Box<
|
||||
dyn Fn(&[u8], Option<ZeroCopyBuf>) -> CoreOp + Send + Sync + 'static,
|
||||
>,
|
||||
);
|
||||
}
|
||||
|
||||
|
|
|
@ -12,8 +12,8 @@ use deno_core::CoreOp;
|
|||
use deno_core::ErrBox;
|
||||
use deno_core::Isolate;
|
||||
use deno_core::ModuleSpecifier;
|
||||
use deno_core::PinnedBuf;
|
||||
use deno_core::StartupData;
|
||||
use deno_core::ZeroCopyBuf;
|
||||
pub use ops::EmitResult;
|
||||
use ops::WrittenFile;
|
||||
use std::fs;
|
||||
|
@ -45,11 +45,11 @@ pub struct TSState {
|
|||
fn compiler_op<D>(
|
||||
ts_state: Arc<Mutex<TSState>>,
|
||||
dispatcher: D,
|
||||
) -> impl Fn(&[u8], Option<PinnedBuf>) -> CoreOp
|
||||
) -> impl Fn(&[u8], Option<ZeroCopyBuf>) -> CoreOp
|
||||
where
|
||||
D: Fn(&mut TSState, &[u8]) -> CoreOp,
|
||||
{
|
||||
move |control: &[u8], zero_copy_buf: Option<PinnedBuf>| -> CoreOp {
|
||||
move |control: &[u8], zero_copy_buf: Option<ZeroCopyBuf>| -> CoreOp {
|
||||
assert!(zero_copy_buf.is_none()); // zero_copy_buf unused in compiler.
|
||||
let mut s = ts_state.lock().unwrap();
|
||||
dispatcher(&mut s, control)
|
||||
|
|
|
@ -5,7 +5,7 @@ extern crate futures;
|
|||
use deno_core::CoreOp;
|
||||
use deno_core::Op;
|
||||
use deno_core::PluginInitContext;
|
||||
use deno_core::{Buf, PinnedBuf};
|
||||
use deno_core::{Buf, ZeroCopyBuf};
|
||||
use futures::future::FutureExt;
|
||||
|
||||
fn init(context: &mut dyn PluginInitContext) {
|
||||
|
@ -14,7 +14,7 @@ fn init(context: &mut dyn PluginInitContext) {
|
|||
}
|
||||
init_fn!(init);
|
||||
|
||||
pub fn op_test_sync(data: &[u8], zero_copy: Option<PinnedBuf>) -> CoreOp {
|
||||
pub fn op_test_sync(data: &[u8], zero_copy: Option<ZeroCopyBuf>) -> CoreOp {
|
||||
if let Some(buf) = zero_copy {
|
||||
let data_str = std::str::from_utf8(&data[..]).unwrap();
|
||||
let buf_str = std::str::from_utf8(&buf[..]).unwrap();
|
||||
|
@ -28,7 +28,7 @@ pub fn op_test_sync(data: &[u8], zero_copy: Option<PinnedBuf>) -> CoreOp {
|
|||
Op::Sync(result_box)
|
||||
}
|
||||
|
||||
pub fn op_test_async(data: &[u8], zero_copy: Option<PinnedBuf>) -> CoreOp {
|
||||
pub fn op_test_async(data: &[u8], zero_copy: Option<ZeroCopyBuf>) -> CoreOp {
|
||||
let data_str = std::str::from_utf8(&data[..]).unwrap().to_string();
|
||||
let fut = async move {
|
||||
if let Some(buf) = zero_copy {
|
||||
|
|
Loading…
Reference in a new issue