diff options
author | Ryan Dahl <ry@tinyclouds.org> | 2020-04-21 09:48:44 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-04-21 09:48:44 -0400 |
commit | cc1720132a9c875d377c559d301bccdda2fb71c1 (patch) | |
tree | bba93c08ab0eaea148e754381b5a668f1a88ca28 /cli/ops/io.rs | |
parent | ef6ee25e09c902e1f9d89a40cf05660432e7143c (diff) |
Move resource_table from deno::State to deno_core::Isolate (#4834)
Diffstat (limited to 'cli/ops/io.rs')
-rw-r--r-- | cli/ops/io.rs | 35 |
1 files changed, 15 insertions, 20 deletions
diff --git a/cli/ops/io.rs b/cli/ops/io.rs index 9c228ffad..45fd6ff95 100644 --- a/cli/ops/io.rs +++ b/cli/ops/io.rs @@ -1,7 +1,6 @@ use super::dispatch_minimal::MinimalOp; use crate::http_util::HttpBody; use crate::op_error::OpError; -use crate::ops::minimal_op; use crate::state::State; use deno_core::*; use futures::future::poll_fn; @@ -60,14 +59,8 @@ lazy_static! { } pub fn init(i: &mut Isolate, s: &State) { - i.register_op( - "op_read", - s.core_op(minimal_op(s.stateful_minimal_op(op_read))), - ); - i.register_op( - "op_write", - s.core_op(minimal_op(s.stateful_minimal_op(op_write))), - ); + i.register_op("op_read", s.stateful_minimal_op2(op_read)); + i.register_op("op_write", s.stateful_minimal_op2(op_write)); } pub fn get_stdio() -> ( @@ -211,7 +204,8 @@ impl DenoAsyncRead for StreamResource { } pub fn op_read( - state: &State, + isolate: &mut deno_core::Isolate, + _state: &State, is_sync: bool, rid: i32, zero_copy: Option<ZeroCopyBuf>, @@ -220,15 +214,15 @@ pub fn op_read( if zero_copy.is_none() { return MinimalOp::Sync(Err(no_buffer_specified())); } + let resource_table = isolate.resource_table.clone(); - let state = state.clone(); let mut buf = zero_copy.unwrap(); if is_sync { MinimalOp::Sync({ // First we look up the rid in the resource table. - let resource_table = &mut state.borrow_mut().resource_table; - std_file_resource(resource_table, rid as u32, move |r| match r { + let mut resource_table = resource_table.borrow_mut(); + std_file_resource(&mut resource_table, rid as u32, move |r| match r { Ok(std_file) => { use std::io::Read; std_file @@ -244,7 +238,7 @@ pub fn op_read( } else { MinimalOp::Async( poll_fn(move |cx| { - let resource_table = &mut state.borrow_mut().resource_table; + let mut resource_table = resource_table.borrow_mut(); let resource_holder = resource_table .get_mut::<StreamResourceHolder>(rid as u32) .ok_or_else(OpError::bad_resource_id)?; @@ -334,7 +328,8 @@ impl DenoAsyncWrite for StreamResource { } pub fn op_write( - state: &State, + isolate: &mut deno_core::Isolate, + _state: &State, is_sync: bool, rid: i32, zero_copy: Option<ZeroCopyBuf>, @@ -344,14 +339,13 @@ pub fn op_write( return MinimalOp::Sync(Err(no_buffer_specified())); } - let state = state.clone(); let buf = zero_copy.unwrap(); if is_sync { MinimalOp::Sync({ // First we look up the rid in the resource table. - let resource_table = &mut state.borrow_mut().resource_table; - std_file_resource(resource_table, rid as u32, move |r| match r { + let mut resource_table = isolate.resource_table.borrow_mut(); + std_file_resource(&mut resource_table, rid as u32, move |r| match r { Ok(std_file) => { use std::io::Write; std_file @@ -365,10 +359,11 @@ pub fn op_write( }) }) } else { + let resource_table = isolate.resource_table.clone(); MinimalOp::Async( async move { let nwritten = poll_fn(|cx| { - let resource_table = &mut state.borrow_mut().resource_table; + let mut resource_table = resource_table.borrow_mut(); let resource_holder = resource_table .get_mut::<StreamResourceHolder>(rid as u32) .ok_or_else(OpError::bad_resource_id)?; @@ -381,7 +376,7 @@ pub fn op_write( // Figure out why it's needed and preferably remove it. // https://github.com/denoland/deno/issues/3565 poll_fn(|cx| { - let resource_table = &mut state.borrow_mut().resource_table; + let mut resource_table = resource_table.borrow_mut(); let resource_holder = resource_table .get_mut::<StreamResourceHolder>(rid as u32) .ok_or_else(OpError::bad_resource_id)?; |