1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2024-11-21 15:04:11 -05:00

chore(ext/web): migrate to deno_core typed externals (#21114)

Use our safer typed externals for the external required for resource
streams.
This commit is contained in:
Matt Mastracci 2023-11-08 12:46:13 -07:00 committed by GitHub
parent e4593873a9
commit f8d1d84c5a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 48 additions and 53 deletions

73
Cargo.lock generated
View file

@ -973,29 +973,6 @@ dependencies = [
"zstd",
]
[[package]]
name = "deno-proc-macro-rules"
version = "0.3.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3c65c2ffdafc1564565200967edc4851c7b55422d3913466688907efd05ea26f"
dependencies = [
"deno-proc-macro-rules-macros",
"proc-macro2",
"syn 2.0.37",
]
[[package]]
name = "deno-proc-macro-rules-macros"
version = "0.3.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3047b312b7451e3190865713a4dd6e1f821aed614ada219766ebc3024a690435"
dependencies = [
"once_cell",
"proc-macro2",
"quote",
"syn 2.0.37",
]
[[package]]
name = "deno_ast"
version = "0.31.3"
@ -1113,9 +1090,9 @@ dependencies = [
[[package]]
name = "deno_core"
version = "0.227.0"
version = "0.228.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d6218d09d15ef76df4f81178b9d97d176d7e780565c323a42c4860b67c214101"
checksum = "78996b42de9975a052cfc9234be39eabf3d6f7721e7cfe79f14a5bd0a252b552"
dependencies = [
"anyhow",
"bytes",
@ -1539,15 +1516,15 @@ dependencies = [
[[package]]
name = "deno_ops"
version = "0.103.0"
version = "0.104.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "14decb93ef6058b9c237ca86d8807563cc4ca19a3c0424e9ea8f1df3045723ad"
checksum = "a06291034a0ad5293efcfa01826e4af6adabdfd513b766e2f2cc60dd6c75a94f"
dependencies = [
"deno-proc-macro-rules",
"lazy-regex",
"once_cell",
"pmutil",
"proc-macro-crate",
"proc-macro-rules",
"proc-macro2",
"quote",
"regex",
@ -3983,11 +3960,10 @@ dependencies = [
[[package]]
name = "proc-macro-crate"
version = "1.3.1"
version = "2.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7f4c021e1093a56626774e81216a4ce732a735e5bad4868a03f3ed65ca0c3919"
checksum = "7e8366a6159044a37876a2b9817124296703c586a5c92e2c53751fa06d8d43e8"
dependencies = [
"once_cell",
"toml_edit",
]
@ -4021,6 +3997,29 @@ version = "0.5.20+deprecated"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "dc375e1527247fe1a97d8b7156678dfe7c1af2fc075c9a4db3690ecd2a148068"
[[package]]
name = "proc-macro-rules"
version = "0.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "07c277e4e643ef00c1233393c673f655e3672cf7eb3ba08a00bdd0ea59139b5f"
dependencies = [
"proc-macro-rules-macros",
"proc-macro2",
"syn 2.0.37",
]
[[package]]
name = "proc-macro-rules-macros"
version = "0.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "207fffb0fe655d1d47f6af98cc2793405e85929bdbc420d685554ff07be27ac7"
dependencies = [
"once_cell",
"proc-macro2",
"quote",
"syn 2.0.37",
]
[[package]]
name = "proc-macro2"
version = "1.0.67"
@ -4783,9 +4782,9 @@ dependencies = [
[[package]]
name = "serde_v8"
version = "0.136.0"
version = "0.137.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "813256f4379caece177ca747ffa35a7f4c0422cec9258f9cecaa9b15ded0cc5c"
checksum = "2c22cbbd634a5b13e9c6a0c6718ae9a8da3696aec5e5eff48fb90e4c9be0809e"
dependencies = [
"bytes",
"derive_more",
@ -5879,15 +5878,15 @@ dependencies = [
[[package]]
name = "toml_datetime"
version = "0.6.3"
version = "0.6.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7cda73e2f1397b1262d6dfdcef8aafae14d1de7748d66822d3bfeeb6d03e5e4b"
checksum = "3550f4e9685620ac18a50ed434eb3aec30db8ba93b0287467bca5826ea25baf1"
[[package]]
name = "toml_edit"
version = "0.19.15"
version = "0.20.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1b5bb770da30e5cbfde35a2d7b9b8a2c4b8ef89548a7a6aeab5c9a576e3e7421"
checksum = "70f427fce4d84c72b5b732388bf4a9f4531b53f74e2887e3ecb2481f68f66d81"
dependencies = [
"indexmap 2.0.2",
"toml_datetime",

View file

@ -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" }

View file

@ -2,6 +2,7 @@
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;
@ -9,6 +10,7 @@ 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;
@ -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)
}
@ -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();
}
}