Skip to content

Commit debf730

Browse files
tniessenjuanarbol
authored andcommitted
lib,test: fix bug in InternalSocketAddress
InternalSocketAddress must set [kDetails] in order for the inherited properties to function correctly. Co-authored-by: Tobias Nießen <[email protected]> PR-URL: #44618 Reviewed-By: Joyee Cheung <[email protected]> Reviewed-By: Antoine du Hamel <[email protected]>
1 parent 3614f5a commit debf730

File tree

2 files changed

+33
-0
lines changed

2 files changed

+33
-0
lines changed

lib/internal/socketaddress.js

+6
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,12 @@ class InternalSocketAddress extends JSTransferable {
142142
constructor(handle) {
143143
super();
144144
this[kHandle] = handle;
145+
this[kDetail] = this[kHandle]?.detail({
146+
address: undefined,
147+
port: undefined,
148+
family: undefined,
149+
flowlabel: undefined,
150+
});
145151
}
146152
}
147153

test/parallel/test-socketaddress.js

+27
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
// Flags: --expose-internals
12
'use strict';
23

34
const common = require('../common');
@@ -10,6 +11,15 @@ const {
1011
SocketAddress,
1112
} = require('net');
1213

14+
const {
15+
InternalSocketAddress,
16+
} = require('internal/socketaddress');
17+
const { internalBinding } = require('internal/test/binding');
18+
const {
19+
SocketAddress: _SocketAddress,
20+
AF_INET
21+
} = internalBinding('block_list');
22+
1323
{
1424
const sa = new SocketAddress();
1525
strictEqual(sa.address, '127.0.0.1');
@@ -108,3 +118,20 @@ const {
108118
throws(() => new SocketAddress({ flowlabel: -1 }), {
109119
code: 'ERR_OUT_OF_RANGE'
110120
});
121+
122+
{
123+
// Test that the internal helper class InternalSocketAddress correctly
124+
// inherits from SocketAddress and that it does not throw when its properties
125+
// are accessed.
126+
127+
const address = '127.0.0.1';
128+
const port = 8080;
129+
const flowlabel = 0;
130+
const handle = new _SocketAddress(address, port, AF_INET, flowlabel);
131+
const addr = new InternalSocketAddress(handle);
132+
ok(addr instanceof SocketAddress);
133+
strictEqual(addr.address, address);
134+
strictEqual(addr.port, port);
135+
strictEqual(addr.family, 'ipv4');
136+
strictEqual(addr.flowlabel, flowlabel);
137+
}

0 commit comments

Comments
 (0)