summaryrefslogtreecommitdiff
path: root/js/net.ts
diff options
context:
space:
mode:
authorYusuke Sakurai <kerokerokerop@gmail.com>2019-09-26 22:14:13 +0900
committerRyan Dahl <ry@tinyclouds.org>2019-09-26 09:14:13 -0400
commitd36391ad20afe56aaa6e42fd63597221636fdfcb (patch)
treee3e0aa455bfa909b658fb21ef66cad6274645129 /js/net.ts
parent3892cf59018acd71dd4bc1099d747bd683cd4118 (diff)
fix: listenDefaults/dialDefaults may be overriden in some cases (#3027)
Diffstat (limited to 'js/net.ts')
-rw-r--r--js/net.ts20
1 files changed, 13 insertions, 7 deletions
diff --git a/js/net.ts b/js/net.ts
index 4da6da38e..a7ad2b73c 100644
--- a/js/net.ts
+++ b/js/net.ts
@@ -135,7 +135,6 @@ export interface ListenOptions {
hostname?: string;
transport?: Transport;
}
-const listenDefaults = { hostname: "0.0.0.0", transport: "tcp" };
/** Listen announces on the local transport address.
*
@@ -155,9 +154,14 @@ const listenDefaults = { hostname: "0.0.0.0", transport: "tcp" };
* listen({ hostname: "golang.org", port: 80, transport: "tcp" })
*/
export function listen(options: ListenOptions): Listener {
- options = Object.assign(listenDefaults, options);
- const res = sendSync(dispatch.OP_LISTEN, options);
- return new ListenerImpl(res.rid, options.transport, res.localAddr);
+ const hostname = options.hostname || "0.0.0.0";
+ const transport = options.transport || "tcp";
+ const res = sendSync(dispatch.OP_LISTEN, {
+ hostname,
+ port: options.port,
+ transport
+ });
+ return new ListenerImpl(res.rid, transport, res.localAddr);
}
export interface DialOptions {
@@ -165,7 +169,6 @@ export interface DialOptions {
hostname?: string;
transport?: Transport;
}
-const dialDefaults = { hostname: "127.0.0.1", transport: "tcp" };
/** Dial connects to the address on the named transport.
*
@@ -185,8 +188,11 @@ const dialDefaults = { hostname: "127.0.0.1", transport: "tcp" };
* dial({ hostname: "golang.org", port: 80, transport: "tcp" })
*/
export async function dial(options: DialOptions): Promise<Conn> {
- options = Object.assign(dialDefaults, options);
- const res = await sendAsync(dispatch.OP_DIAL, options);
+ const res = await sendAsync(dispatch.OP_DIAL, {
+ hostname: options.hostname || "127.0.0.1",
+ port: options.port,
+ transport: options.transport || "tcp"
+ });
return new ConnImpl(res.rid, res.remoteAddr!, res.localAddr!);
}