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/01_net.js | |
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/01_net.js')
-rw-r--r-- | ext/net/01_net.js | 50 |
1 files changed, 26 insertions, 24 deletions
diff --git a/ext/net/01_net.js b/ext/net/01_net.js index 765b94035..971ec2e8b 100644 --- a/ext/net/01_net.js +++ b/ext/net/01_net.js @@ -319,30 +319,32 @@ } } - function listenDatagram(args) { - switch (args.transport) { - case "udp": { - const [rid, addr] = ops.op_net_listen_udp( - { - hostname: args.hostname ?? "127.0.0.1", - port: args.port, - }, - args.reuseAddress ?? false, - ); - addr.transport = "udp"; - return new Datagram(rid, addr); - } - case "unixpacket": { - const [rid, path] = ops.op_net_listen_unixpacket(args.path); - const addr = { - transport: "unixpacket", - path, - }; - return new Datagram(rid, addr); + function createListenDatagram(udpOpFn, unixOpFn) { + return function listenDatagram(args) { + switch (args.transport) { + case "udp": { + const [rid, addr] = udpOpFn( + { + hostname: args.hostname ?? "127.0.0.1", + port: args.port, + }, + args.reuseAddress ?? false, + ); + addr.transport = "udp"; + return new Datagram(rid, addr); + } + case "unixpacket": { + const [rid, path] = unixOpFn(args.path); + const addr = { + transport: "unixpacket", + path, + }; + return new Datagram(rid, addr); + } + default: + throw new TypeError(`Unsupported transport: '${transport}'`); } - default: - throw new TypeError(`Unsupported transport: '${transport}'`); - } + }; } async function connect(args) { @@ -389,7 +391,7 @@ TcpConn, UnixConn, listen, - listenDatagram, + createListenDatagram, Listener, shutdown, Datagram, |