| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 8457033 commit 42df2ba
5 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1224,6 +1224,13 @@ time. | |||
| 1224 | 1224 | The `--input-type` flag was used to attempt to execute a file. This flag can | |
| 1225 | 1225 | only be used with input via `--eval`, `--print` or `STDIN`. | |
| 1226 | 1226 | ||
| 1227 | + <a id="ERR_INSPECTOR_ALREADY_ACTIVATED"></a> | ||
| 1228 | + ### `ERR_INSPECTOR_ALREADY_ACTIVATED` | ||
| 1229 | + | ||
| 1230 | + While using the `inspector` module, an attempt was made to activate the | ||
| 1231 | + inspector when it already started to listen on a port. Use `inspector.close()` | ||
| 1232 | + before activating it on a different address. | ||
| 1233 | + | ||
| 1227 | 1234 | <a id="ERR_INSPECTOR_ALREADY_CONNECTED"></a> | |
| 1228 | 1235 | ### `ERR_INSPECTOR_ALREADY_CONNECTED` | |
| 1229 | 1236 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -8,6 +8,7 @@ const { | |||
| 8 | 8 | } = primordials; | |
| 9 | 9 | ||
| 10 | 10 | const { | |
| 11 | + ERR_INSPECTOR_ALREADY_ACTIVATED, | ||
| 11 | 12 | ERR_INSPECTOR_ALREADY_CONNECTED, | |
| 12 | 13 | ERR_INSPECTOR_CLOSED, | |
| 13 | 14 | ERR_INSPECTOR_COMMAND, | |
@@ -33,6 +34,7 @@ const { | |||
| 33 | 34 | MainThreadConnection, | |
| 34 | 35 | open, | |
| 35 | 36 | url, | |
| 37 | + isEnabled, | ||
| 36 | 38 | waitForDebugger | |
| 37 | 39 | } = internalBinding('inspector'); | |
| 38 | 40 | ||
@@ -131,6 +133,9 @@ class Session extends EventEmitter { | |||
| 131 | 133 | } | |
| 132 | 134 | ||
| 133 | 135 | function inspectorOpen(port, host, wait) { | |
| 136 | + if (isEnabled()) { | ||
| 137 | + throw new ERR_INSPECTOR_ALREADY_ACTIVATED(); | ||
| 138 | + } | ||
| 134 | 139 | open(port, host); | |
| 135 | 140 | if (wait) | |
| 136 | 141 | waitForDebugger(); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -941,6 +941,10 @@ E('ERR_INCOMPATIBLE_OPTION_PAIR', | |||
| 941 | 941 | 'Option "%s" cannot be used in combination with option "%s"', TypeError); | |
| 942 | 942 | E('ERR_INPUT_TYPE_NOT_ALLOWED', '--input-type can only be used with string ' + | |
| 943 | 943 | 'input via --eval, --print, or STDIN', Error); | |
| 944 | + E('ERR_INSPECTOR_ALREADY_ACTIVATED', | ||
| 945 | + 'Inspector is already activated. Close it with inspector.close() ' + | ||
| 946 | + 'before activating it again.', | ||
| 947 | + Error); | ||
| 944 | 948 | E('ERR_INSPECTOR_ALREADY_CONNECTED', '%s is already connected', Error); | |
| 945 | 949 | E('ERR_INSPECTOR_CLOSED', 'Session was closed', Error); | |
| 946 | 950 | E('ERR_INSPECTOR_COMMAND', 'Inspector error %d: %s', Error); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,19 @@ | |||
| 1 | + // Flags: --inspect=0 | ||
| 2 | + 'use strict'; | ||
| 3 | + | ||
| 4 | + const common = require('../common'); | ||
| 5 | + common.skipIfInspectorDisabled(); | ||
| 6 | + common.skipIfWorker(); | ||
| 7 | + | ||
| 8 | + const assert = require('assert'); | ||
| 9 | + const inspector = require('inspector'); | ||
| 10 | + const wsUrl = inspector.url(); | ||
| 11 | + assert(wsUrl.startsWith('ws://')); | ||
| 12 | + assert.throws(() => { | ||
| 13 | + inspector.open(0, undefined, false); | ||
| 14 | + }, { | ||
| 15 | + code: 'ERR_INSPECTOR_ALREADY_ACTIVATED' | ||
| 16 | + }); | ||
| 17 | + assert.strictEqual(inspector.url(), wsUrl); | ||
| 18 | + inspector.close(); | ||
| 19 | + assert.strictEqual(inspector.url(), undefined); | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -10,6 +10,10 @@ const fork = require('child_process').fork; | |||
| 10 | 10 | const net = require('net'); | |
| 11 | 11 | const url = require('url'); | |
| 12 | 12 | ||
| 13 | + const kFirstOpen = 0; | ||
| 14 | + const kOpenWhileOpen = 1; | ||
| 15 | + const kReOpen = 2; | ||
| 16 | + | ||
| 13 | 17 | if (process.env.BE_CHILD) | |
| 14 | 18 | return beChild(); | |
| 15 | 19 | ||
@@ -19,7 +23,7 @@ const child = fork(__filename, | |||
| 19 | 23 | child.once('message', common.mustCall((msg) => { | |
| 20 | 24 | assert.strictEqual(msg.cmd, 'started'); | |
| 21 | 25 | ||
| 22 | - child.send({ cmd: 'open', args: [0] }); | ||
| 26 | + child.send({ cmd: 'open', args: [kFirstOpen] }); | ||
| 23 | 27 | child.once('message', common.mustCall(firstOpen)); | |
| 24 | 28 | })); | |
| 25 | 29 | ||
@@ -31,7 +35,7 @@ function firstOpen(msg) { | |||
| 31 | 35 | ping(port, (err) => { | |
| 32 | 36 | assert.ifError(err); | |
| 33 | 37 | // Inspector is already open, and won't be reopened, so args don't matter. | |
| 34 | - child.send({ cmd: 'open', args: [] }); | ||
| 38 | + child.send({ cmd: 'open', args: [kOpenWhileOpen] }); | ||
| 35 | 39 | child.once('message', common.mustCall(tryToOpenWhenOpen)); | |
| 36 | 40 | firstPort = port; | |
| 37 | 41 | }); | |
@@ -62,7 +66,7 @@ function closeWhenOpen(msg) { | |||
| 62 | 66 | function tryToCloseWhenClosed(msg) { | |
| 63 | 67 | assert.strictEqual(msg.cmd, 'url'); | |
| 64 | 68 | assert.strictEqual(msg.url, undefined); | |
| 65 | - child.send({ cmd: 'open', args: [] }); | ||
| 69 | + child.send({ cmd: 'open', args: [kReOpen] }); | ||
| 66 | 70 | child.once('message', common.mustCall(reopenAfterClose)); | |
| 67 | 71 | } | |
| 68 | 72 | ||
@@ -93,7 +97,17 @@ function beChild() { | |||
| 93 | 97 | ||
| 94 | 98 | process.on('message', (msg) => { | |
| 95 | 99 | if (msg.cmd === 'open') { | |
| 96 | - inspector.open(...msg.args); | ||
| 100 | + if (msg.args[0] === kFirstOpen) { | ||
| 101 | + inspector.open(0, false, undefined); | ||
| 102 | + } else if (msg.args[0] === kOpenWhileOpen) { | ||
| 103 | + assert.throws(() => { | ||
| 104 | + inspector.open(0, false, undefined); | ||
| 105 | + }, { | ||
| 106 | + code: 'ERR_INSPECTOR_ALREADY_ACTIVATED' | ||
| 107 | + }); | ||
| 108 | + } else if (msg.args[0] === kReOpen) { | ||
| 109 | + inspector.open(0, false, undefined); | ||
| 110 | + } | ||
| 97 | 111 | } | |
| 98 | 112 | if (msg.cmd === 'close') { | |
| 99 | 113 | inspector.close(); | |
| Back | FazBrowse Home | New Git URL |
0 commit comments