diff options
author | Bartek IwaĆczuk <biwanczuk@gmail.com> | 2022-11-10 22:03:28 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-11-10 22:03:28 +0100 |
commit | 8d5c0112fbbed188f97218ace2357feba3a8746f (patch) | |
tree | cf08da990c8bf90da116e8db3ac6332cd37578a1 /ext/net/ops.rs | |
parent | 53e974b276b095faf52918c4c6e988e9d2788cef (diff) |
feat: don't require --unstable flag for npm programs (#16520)
This PR adds copies of several unstable APIs that are available
in "Deno[Deno.internal].nodeUnstable" namespace.
These copies do not perform unstable check (ie. don't require
"--unstable" flag to be present). Otherwise they work exactly
the same, including permission checks.
These APIs are not meant to be used by users directly and
can change at any time.
Copies of following APIs are available in that namespace:
- Deno.spawnChild
- Deno.spawn
- Deno.spawnSync
- Deno.serve
- Deno.upgradeHttpRaw
- Deno.listenDatagram
Diffstat (limited to 'ext/net/ops.rs')
-rw-r--r-- | ext/net/ops.rs | 33 |
1 files changed, 30 insertions, 3 deletions
diff --git a/ext/net/ops.rs b/ext/net/ops.rs index e6420bf9e..96de8cff1 100644 --- a/ext/net/ops.rs +++ b/ext/net/ops.rs @@ -53,10 +53,13 @@ pub fn init<P: NetPermissions + 'static>() -> Vec<OpDecl> { crate::ops_unix::op_net_connect_unix::decl::<P>(), op_net_listen_tcp::decl::<P>(), op_net_listen_udp::decl::<P>(), + op_node_unstable_net_listen_udp::decl::<P>(), #[cfg(unix)] crate::ops_unix::op_net_listen_unix::decl::<P>(), #[cfg(unix)] crate::ops_unix::op_net_listen_unixpacket::decl::<P>(), + #[cfg(unix)] + crate::ops_unix::op_node_unstable_net_listen_unixpacket::decl::<P>(), op_net_recv_udp::decl(), #[cfg(unix)] crate::ops_unix::op_net_recv_unixpacket::decl(), @@ -288,8 +291,7 @@ where Ok((rid, IpAddr::from(local_addr))) } -#[op] -fn op_net_listen_udp<NP>( +fn net_listen_udp<NP>( state: &mut OpState, addr: IpAddr, reuse_address: bool, @@ -297,7 +299,6 @@ fn op_net_listen_udp<NP>( where NP: NetPermissions + 'static, { - super::check_unstable(state, "Deno.listenDatagram"); state .borrow_mut::<NP>() .check_net(&(&addr.hostname, Some(addr.port)), "Deno.listenDatagram()")?; @@ -343,6 +344,32 @@ where Ok((rid, IpAddr::from(local_addr))) } +#[op] +fn op_net_listen_udp<NP>( + state: &mut OpState, + addr: IpAddr, + reuse_address: bool, +) -> Result<(ResourceId, IpAddr), AnyError> +where + NP: NetPermissions + 'static, +{ + super::check_unstable(state, "Deno.listenDatagram"); + net_listen_udp::<NP>(state, addr, reuse_address) +} + +#[op] +fn op_node_unstable_net_listen_udp<NP>( + state: &mut OpState, + addr: IpAddr, + reuse_address: bool, +) -> Result<(ResourceId, IpAddr), AnyError> +where + NP: NetPermissions + 'static, +{ + super::check_unstable(state, "Deno.listenDatagram"); + net_listen_udp::<NP>(state, addr, reuse_address) +} + #[derive(Serialize, Eq, PartialEq, Debug)] #[serde(untagged)] pub enum DnsReturnRecord { |