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‎

Lines changed: 6 additions & 0 deletions
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‎

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

34
constcommon=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
constsa=newSocketAddress();
1525
strictEqual(sa.address,'127.0.0.1');
@@ -108,3 +118,20 @@ const{
108118
throws(()=>newSocketAddress({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+
constaddress='127.0.0.1';
128+
constport=8080;
129+
constflowlabel=0;
130+
consthandle=new_SocketAddress(address,port,AF_INET,flowlabel);
131+
constaddr=newInternalSocketAddress(handle);
132+
ok(addrinstanceofSocketAddress);
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)