Skip to content

Commit

Permalink
chore(ext/web): migrate to deno_core typed externals (denoland#21114)
Browse files Browse the repository at this point in the history
Use our safer typed externals for the external required for resource
streams.
  • Loading branch information
mmastrac committed Nov 8, 2023
1 parent e459387 commit f8d1d84
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 53 deletions.
73 changes: 36 additions & 37 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ repository = "https://github.com/denoland/deno"

[workspace.dependencies]
deno_ast = { version = "0.31.2", features = ["transpiling"] }
deno_core = { version = "0.227.0" }
deno_core = { version = "0.228.0" }

deno_runtime = { version = "0.130.0", path = "./runtime" }
napi_sym = { version = "0.52.0", path = "./cli/napi/sym" }
Expand Down
26 changes: 11 additions & 15 deletions ext/web/stream_resource.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,15 @@
use bytes::BytesMut;
use deno_core::error::type_error;
use deno_core::error::AnyError;
use deno_core::external;
use deno_core::op2;
use deno_core::serde_v8::V8Slice;
use deno_core::unsync::TaskQueue;
use deno_core::AsyncResult;
use deno_core::BufView;
use deno_core::CancelFuture;
use deno_core::CancelHandle;
use deno_core::ExternalPointer;
use deno_core::JsBuffer;
use deno_core::OpState;
use deno_core::RcLike;
Expand Down Expand Up @@ -290,17 +292,6 @@ impl BoundedBufferChannel {
self.inner.borrow_mut()
}

pub fn into_raw(self) -> *const BoundedBufferChannel {
Rc::into_raw(self.inner) as _
}

pub unsafe fn clone_from_raw(ptr: *const BoundedBufferChannel) -> Self {
let rc = Rc::from_raw(ptr as *const RefCell<BoundedBufferChannelInner>);
let clone = rc.clone();
std::mem::forget(rc);
std::mem::transmute(clone)
}

pub fn read(&self, limit: usize) -> Result<Option<BufView>, AnyError> {
self.inner().read(limit)
}
Expand Down Expand Up @@ -460,19 +451,24 @@ pub fn op_readable_stream_resource_get_sink(
else {
return std::ptr::null();
};
resource.channel.clone().into_raw() as _
ExternalPointer::new(resource.channel.clone()).into_raw()
}

external!(BoundedBufferChannel, "stream resource channel");

fn get_sender(sender: *const c_void) -> BoundedBufferChannel {
// SAFETY: We know this is a valid v8::External
unsafe { BoundedBufferChannel::clone_from_raw(sender as _) }
unsafe {
ExternalPointer::<BoundedBufferChannel>::from_raw(sender)
.unsafely_deref()
.clone()
}
}

fn drop_sender(sender: *const c_void) {
// SAFETY: We know this is a valid v8::External
unsafe {
assert!(!sender.is_null());
_ = Rc::from_raw(sender as *mut RefCell<BoundedBufferChannelInner>);
ExternalPointer::<BoundedBufferChannel>::from_raw(sender).unsafely_take();
}
}

Expand Down

0 comments on commit f8d1d84

Please sign in to comment.