Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

lib,test: fix bug in InternalSocketAddress #44618

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 6 additions & 0 deletions lib/internal/socketaddress.js
Expand Up @@ -142,6 +142,12 @@ class InternalSocketAddress extends JSTransferable {
constructor(handle) {
super();
this[kHandle] = handle;
this[kDetail] = this[kHandle]?.detail({
address: undefined,
port: undefined,
family: undefined,
flowlabel: undefined,
});
}
}

Expand Down
27 changes: 27 additions & 0 deletions test/parallel/test-socketaddress.js
@@ -1,3 +1,4 @@
// Flags: --expose-internals
'use strict';

const common = require('../common');
Expand All @@ -10,6 +11,15 @@ const {
SocketAddress,
} = require('net');

const {
InternalSocketAddress,
} = require('internal/socketaddress');
const { internalBinding } = require('internal/test/binding');
const {
SocketAddress: _SocketAddress,
AF_INET
} = internalBinding('block_list');

{
const sa = new SocketAddress();
strictEqual(sa.address, '127.0.0.1');
Expand Down Expand Up @@ -108,3 +118,20 @@ const {
throws(() => new SocketAddress({ flowlabel: -1 }), {
code: 'ERR_OUT_OF_RANGE'
});

{
// Test that the internal helper class InternalSocketAddress correctly
// inherits from SocketAddress and that it does not throw when its properties
// are accessed.

const address = '127.0.0.1';
const port = 8080;
const flowlabel = 0;
const handle = new _SocketAddress(address, port, AF_INET, flowlabel);
const addr = new InternalSocketAddress(handle);
ok(addr instanceof SocketAddress);
strictEqual(addr.address, address);
strictEqual(addr.port, port);
strictEqual(addr.family, 'ipv4');
strictEqual(addr.flowlabel, flowlabel);
}