diff options
author | Yusuke Sakurai <kerokerokerop@gmail.com> | 2019-09-26 22:14:13 +0900 |
---|---|---|
committer | Ryan Dahl <ry@tinyclouds.org> | 2019-09-26 09:14:13 -0400 |
commit | d36391ad20afe56aaa6e42fd63597221636fdfcb (patch) | |
tree | e3e0aa455bfa909b658fb21ef66cad6274645129 /js/net.ts | |
parent | 3892cf59018acd71dd4bc1099d747bd683cd4118 (diff) |
fix: listenDefaults/dialDefaults may be overriden in some cases (#3027)
Diffstat (limited to 'js/net.ts')
-rw-r--r-- | js/net.ts | 20 |
1 files changed, 13 insertions, 7 deletions
@@ -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!); } |