| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent b5b7438 commit ae17d18
10 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -32,6 +32,7 @@ const { isUint8Array } = require('internal/util/types'); | |||
| 32 | 32 | const spawn_sync = process.binding('spawn_sync'); | |
| 33 | 33 | const { HTTPParser } = process.binding('http_parser'); | |
| 34 | 34 | const { freeParser } = require('_http_common'); | |
| 35 | + const { kStateSymbol } = require('internal/dgram'); | ||
| 35 | 36 | ||
| 36 | 37 | const { | |
| 37 | 38 | UV_EACCES, | |
@@ -181,7 +182,7 @@ const handleConversion = { | |||
| 181 | 182 | send: function(message, socket, options) { | |
| 182 | 183 | message.dgramType = socket.type; | |
| 183 | 184 | ||
| 184 | - return socket._handle; | ||
| 185 | + return socket[kStateSymbol].handle; | ||
| 185 | 186 | }, | |
| 186 | 187 | ||
| 187 | 188 | got: function(message, handle, emit) { | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,4 @@ | |||
| 1 | + 'use strict'; | ||
| 2 | + const kStateSymbol = Symbol('state symbol'); | ||
| 3 | + | ||
| 4 | + module.exports = { kStateSymbol }; | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -104,6 +104,7 @@ | |||
| 104 | 104 | 'lib/internal/crypto/sig.js', | |
| 105 | 105 | 'lib/internal/crypto/util.js', | |
| 106 | 106 | 'lib/internal/constants.js', | |
| 107 | + 'lib/internal/dgram.js', | ||
| 107 | 108 | 'lib/internal/dns/promises.js', | |
| 108 | 109 | 'lib/internal/dns/utils.js', | |
| 109 | 110 | 'lib/internal/domexception.js', | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1,13 +1,16 @@ | |||
| 1 | + // Flags: --expose-internals | ||
| 1 | 2 | 'use strict'; | |
| 2 | 3 | const common = require('../common'); | |
| 3 | 4 | const dgram = require('dgram'); | |
| 5 | + const { kStateSymbol } = require('internal/dgram'); | ||
| 4 | 6 | const socket = dgram.createSocket('udp4'); | |
| 5 | - const lookup = socket._handle.lookup; | ||
| 7 | + const { handle } = socket[kStateSymbol]; | ||
| 8 | + const lookup = handle.lookup; | ||
| 6 | 9 | ||
| 7 | 10 | // Test the scenario where the socket is closed during a bind operation. | |
| 8 | - socket._handle.bind = common.mustNotCall('bind() should not be called.'); | ||
| 11 | + handle.bind = common.mustNotCall('bind() should not be called.'); | ||
| 9 | 12 | ||
| 10 | - socket._handle.lookup = common.mustCall(function(address, callback) { | ||
| 13 | + handle.lookup = common.mustCall(function(address, callback) { | ||
| 11 | 14 | socket.close(common.mustCall(() => { | |
| 12 | 15 | lookup.call(this, address, callback); | |
| 13 | 16 | })); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -19,18 +19,20 @@ | |||
| 19 | 19 | // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE | |
| 20 | 20 | // USE OR OTHER DEALINGS IN THE SOFTWARE. | |
| 21 | 21 | ||
| 22 | + // Flags: --expose-internals | ||
| 22 | 23 | 'use strict'; | |
| 23 | 24 | // Ensure that if a dgram socket is closed before the DNS lookup completes, it | |
| 24 | 25 | // won't crash. | |
| 25 | 26 | ||
| 26 | 27 | const common = require('../common'); | |
| 27 | 28 | const assert = require('assert'); | |
| 28 | 29 | const dgram = require('dgram'); | |
| 30 | + const { kStateSymbol } = require('internal/dgram'); | ||
| 29 | 31 | ||
| 30 | 32 | const buf = Buffer.alloc(1024, 42); | |
| 31 | 33 | ||
| 32 | 34 | let socket = dgram.createSocket('udp4'); | |
| 33 | - const handle = socket._handle; | ||
| 35 | + const { handle } = socket[kStateSymbol]; | ||
| 34 | 36 | ||
| 35 | 37 | // get a random port for send | |
| 36 | 38 | const portGetter = dgram.createSocket('udp4') | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1,8 +1,11 @@ | |||
| 1 | + // Flags: --expose-internals | ||
| 1 | 2 | 'use strict'; | |
| 2 | 3 | const common = require('../common'); | |
| 3 | 4 | const assert = require('assert'); | |
| 4 | 5 | const dgram = require('dgram'); | |
| 6 | + const { kStateSymbol } = require('internal/dgram'); | ||
| 5 | 7 | const s = dgram.createSocket('udp4'); | |
| 8 | + const { handle } = s[kStateSymbol]; | ||
| 6 | 9 | ||
| 7 | 10 | s.on('error', common.mustCall((err) => { | |
| 8 | 11 | s.close(); | |
@@ -13,4 +16,4 @@ s.on('error', common.mustCall((err) => { | |||
| 13 | 16 | })); | |
| 14 | 17 | ||
| 15 | 18 | s.on('message', common.mustNotCall('no message should be received.')); | |
| 16 | - s.bind(common.mustCall(() => s._handle.onmessage(-1, s._handle, null, null))); | ||
| 19 | + s.bind(common.mustCall(() => handle.onmessage(-1, handle, null, null))); | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1,15 +1,17 @@ | |||
| 1 | + // Flags: --expose-internals | ||
| 1 | 2 | 'use strict'; | |
| 2 | 3 | const common = require('../common'); | |
| 3 | 4 | const assert = require('assert'); | |
| 4 | 5 | const dgram = require('dgram'); | |
| 6 | + const { kStateSymbol } = require('internal/dgram'); | ||
| 5 | 7 | const mockError = new Error('mock DNS error'); | |
| 6 | 8 | ||
| 7 | 9 | function getSocket(callback) { | |
| 8 | 10 | const socket = dgram.createSocket('udp4'); | |
| 9 | 11 | ||
| 10 | 12 | socket.on('message', common.mustNotCall('Should not receive any messages.')); | |
| 11 | 13 | socket.bind(common.mustCall(() => { | |
| 12 | - socket._handle.lookup = function(address, callback) { | ||
| 14 | + socket[kStateSymbol].handle.lookup = function(address, callback) { | ||
| 13 | 15 | process.nextTick(callback, mockError); | |
| 14 | 16 | }; | |
| 15 | 17 | ||
@@ -57,7 +59,7 @@ getSocket((socket) => { | |||
| 57 | 59 | ); | |
| 58 | 60 | }); | |
| 59 | 61 | ||
| 60 | - socket._handle.send = function() { | ||
| 62 | + socket[kStateSymbol].handle.send = function() { | ||
| 61 | 63 | return errCode; | |
| 62 | 64 | }; | |
| 63 | 65 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1,3 +1,4 @@ | |||
| 1 | + // Flags: --expose-internals | ||
| 1 | 2 | 'use strict'; | |
| 2 | 3 | ||
| 3 | 4 | const common = require('../common'); | |
@@ -25,41 +26,46 @@ const strictEqual = require('assert').strictEqual; | |||
| 25 | 26 | ||
| 26 | 27 | ||
| 27 | 28 | const dgram = require('dgram'); | |
| 29 | + const { kStateSymbol } = require('internal/dgram'); | ||
| 28 | 30 | ||
| 29 | 31 | // dgram ipv4 | |
| 30 | 32 | { | |
| 31 | 33 | const sock4 = dgram.createSocket('udp4'); | |
| 32 | - strictEqual(Object.getPrototypeOf(sock4._handle).hasOwnProperty('hasRef'), | ||
| 34 | + const handle = sock4[kStateSymbol].handle; | ||
| 35 | + | ||
| 36 | + strictEqual(Object.getPrototypeOf(handle).hasOwnProperty('hasRef'), | ||
| 33 | 37 | true, 'udp_wrap: ipv4: hasRef() missing'); | |
| 34 | - strictEqual(sock4._handle.hasRef(), | ||
| 38 | + strictEqual(handle.hasRef(), | ||
| 35 | 39 | true, 'udp_wrap: ipv4: not initially refed'); | |
| 36 | 40 | sock4.unref(); | |
| 37 | - strictEqual(sock4._handle.hasRef(), | ||
| 41 | + strictEqual(handle.hasRef(), | ||
| 38 | 42 | false, 'udp_wrap: ipv4: unref() ineffective'); | |
| 39 | 43 | sock4.ref(); | |
| 40 | - strictEqual(sock4._handle.hasRef(), | ||
| 44 | + strictEqual(handle.hasRef(), | ||
| 41 | 45 | true, 'udp_wrap: ipv4: ref() ineffective'); | |
| 42 | - sock4._handle.close(common.mustCall(() => | ||
| 43 | - strictEqual(sock4._handle.hasRef(), | ||
| 46 | + handle.close(common.mustCall(() => | ||
| 47 | + strictEqual(handle.hasRef(), | ||
| 44 | 48 | false, 'udp_wrap: ipv4: not unrefed on close'))); | |
| 45 | 49 | } | |
| 46 | 50 | ||
| 47 | 51 | ||
| 48 | 52 | // dgram ipv6 | |
| 49 | 53 | { | |
| 50 | 54 | const sock6 = dgram.createSocket('udp6'); | |
| 51 | - strictEqual(Object.getPrototypeOf(sock6._handle).hasOwnProperty('hasRef'), | ||
| 55 | + const handle = sock6[kStateSymbol].handle; | ||
| 56 | + | ||
| 57 | + strictEqual(Object.getPrototypeOf(handle).hasOwnProperty('hasRef'), | ||
| 52 | 58 | true, 'udp_wrap: ipv6: hasRef() missing'); | |
| 53 | - strictEqual(sock6._handle.hasRef(), | ||
| 59 | + strictEqual(handle.hasRef(), | ||
| 54 | 60 | true, 'udp_wrap: ipv6: not initially refed'); | |
| 55 | 61 | sock6.unref(); | |
| 56 | - strictEqual(sock6._handle.hasRef(), | ||
| 62 | + strictEqual(handle.hasRef(), | ||
| 57 | 63 | false, 'udp_wrap: ipv6: unref() ineffective'); | |
| 58 | 64 | sock6.ref(); | |
| 59 | - strictEqual(sock6._handle.hasRef(), | ||
| 65 | + strictEqual(handle.hasRef(), | ||
| 60 | 66 | true, 'udp_wrap: ipv6: ref() ineffective'); | |
| 61 | - sock6._handle.close(common.mustCall(() => | ||
| 62 | - strictEqual(sock6._handle.hasRef(), | ||
| 67 | + handle.close(common.mustCall(() => | ||
| 68 | + strictEqual(handle.hasRef(), | ||
| 63 | 69 | false, 'udp_wrap: ipv6: not unrefed on close'))); | |
| 64 | 70 | } | |
| 65 | 71 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1,8 +1,10 @@ | |||
| 1 | + // Flags: --expose-internals | ||
| 1 | 2 | 'use strict'; | |
| 2 | 3 | const common = require('../common'); | |
| 3 | 4 | const assert = require('assert'); | |
| 4 | 5 | const dgram = require('dgram'); | |
| 5 | 6 | const dns = require('dns'); | |
| 7 | + const { kStateSymbol } = require('internal/dgram'); | ||
| 6 | 8 | ||
| 7 | 9 | // Monkey patch dns.lookup() so that it always fails. | |
| 8 | 10 | dns.lookup = function(address, family, callback) { | |
@@ -25,8 +27,8 @@ socket.on('error', (err) => { | |||
| 25 | 27 | // should also be two listeners - this function and the dgram internal one | |
| 26 | 28 | // time error handler. | |
| 27 | 29 | dnsFailures++; | |
| 28 | - assert(Array.isArray(socket._queue)); | ||
| 29 | - assert.strictEqual(socket._queue.length, 1); | ||
| 30 | + assert(Array.isArray(socket[kStateSymbol].queue)); | ||
| 31 | + assert.strictEqual(socket[kStateSymbol].queue.length, 1); | ||
| 30 | 32 | assert.strictEqual(socket.listenerCount('error'), 2); | |
| 31 | 33 | return; | |
| 32 | 34 | } | |
@@ -35,7 +37,7 @@ socket.on('error', (err) => { | |||
| 35 | 37 | // On error, the queue should be destroyed and this function should be | |
| 36 | 38 | // the only listener. | |
| 37 | 39 | sendFailures++; | |
| 38 | - assert.strictEqual(socket._queue, undefined); | ||
| 40 | + assert.strictEqual(socket[kStateSymbol].queue, undefined); | ||
| 39 | 41 | assert.strictEqual(socket.listenerCount('error'), 1); | |
| 40 | 42 | return; | |
| 41 | 43 | } | |
| Back | FazBrowse Home | New Git URL |
0 commit comments