| 43 | const kDetail = Symbol('kDetail'); |
| 44 | |
| 45 | class SocketAddress { |
| 46 | static isSocketAddress(value) { |
| 47 | return value?.[kHandle] !== undefined; |
| 48 | } |
| 49 | |
| 50 | constructor(options = kEmptyObject) { |
| 51 | markTransferMode(this, true, false); |
| 52 | |
| 53 | validateObject(options, 'options'); |
| 54 | let { family = 'ipv4' } = options; |
| 55 | const { |
| 56 | address = (family === 'ipv4' ? '127.0.0.1' : '::'), |
| 57 | port = 0, |
| 58 | flowlabel = 0, |
| 59 | } = options; |
| 60 | |
| 61 | let type; |
| 62 | if (typeof family?.toLowerCase === 'function') |
| 63 | family = family.toLowerCase(); |
| 64 | switch (family) { |
| 65 | case 'ipv4': |
| 66 | type = AF_INET; |
| 67 | break; |
| 68 | case 'ipv6': |
| 69 | type = AF_INET6; |
| 70 | break; |
| 71 | default: |
| 72 | throw new ERR_INVALID_ARG_VALUE('options.family', options.family); |
| 73 | } |
| 74 | |
| 75 | validateString(address, 'options.address'); |
| 76 | validatePort(port, 'options.port'); |
| 77 | validateUint32(flowlabel, 'options.flowlabel', false); |
| 78 | |
| 79 | this[kHandle] = new _SocketAddress(address, port | 0, type, flowlabel | 0); |
| 80 | this[kDetail] = this[kHandle].detail({ |
| 81 | address: undefined, |
| 82 | port: undefined, |
| 83 | family: undefined, |
| 84 | flowlabel: undefined, |
| 85 | }); |
| 86 | } |
| 87 | |
| 88 | get address() { |
| 89 | return this[kDetail].address; |
| 90 | } |
| 91 | |
| 92 | get port() { |
| 93 | return this[kDetail].port; |
| 94 | } |
| 95 | |
| 96 | get family() { |
| 97 | return this[kDetail].family === AF_INET ? 'ipv4' : 'ipv6'; |
| 98 | } |
| 99 | |
| 100 | get flowlabel() { |
| 101 | // The flow label can be changed internally. |
| 102 | return this[kHandle].flowlabel(); |
nothing calls this directly
no outgoing calls
no test coverage detected
searching dependent graphs…