| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 0bac547 commit d36b60e
6 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -2802,6 +2802,14 @@ import 'package-name'; // supported | |||
| 2802 | 2802 | ||
| 2803 | 2803 | `import` with URL schemes other than `file` and `data` is unsupported. | |
| 2804 | 2804 | ||
| 2805 | + <a id="ERR_USE_AFTER_CLOSE"></a> | ||
| 2806 | + | ||
| 2807 | + ### `ERR_USE_AFTER_CLOSE` | ||
| 2808 | + | ||
| 2809 | + > Stability: 1 - Experimental | ||
| 2810 | + | ||
| 2811 | + An attempt was made to use something that was already closed. | ||
| 2812 | + | ||
| 2805 | 2813 | <a id="ERR_VALID_PERFORMANCE_ENTRY_TYPE"></a> | |
| 2806 | 2814 | ||
| 2807 | 2815 | ### `ERR_VALID_PERFORMANCE_ENTRY_TYPE` | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -330,6 +330,8 @@ The `callback` function passed to `rl.question()` does not follow the typical | |||
| 330 | 330 | pattern of accepting an `Error` object or `null` as the first argument. | |
| 331 | 331 | The `callback` is called with the provided answer as the only argument. | |
| 332 | 332 | ||
| 333 | + An error will be thrown if calling `rl.question()` after `rl.close()`. | ||
| 334 | + | ||
| 333 | 335 | Example usage: | |
| 334 | 336 | ||
| 335 | 337 | ```js | |
@@ -586,6 +588,8 @@ paused. | |||
| 586 | 588 | If the `readlinePromises.Interface` was created with `output` set to `null` or | |
| 587 | 589 | `undefined` the `query` is not written. | |
| 588 | 590 | ||
| 591 | + If the question is called after `rl.close()`, it returns a rejected promise. | ||
| 592 | + | ||
| 589 | 593 | Example usage: | |
| 590 | 594 | ||
| 591 | 595 | ```mjs | |
@@ -855,6 +859,8 @@ The `callback` function passed to `rl.question()` does not follow the typical | |||
| 855 | 859 | pattern of accepting an `Error` object or `null` as the first argument. | |
| 856 | 860 | The `callback` is called with the provided answer as the only argument. | |
| 857 | 861 | ||
| 862 | + An error will be thrown if calling `rl.question()` after `rl.close()`. | ||
| 863 | + | ||
| 858 | 864 | Example usage: | |
| 859 | 865 | ||
| 860 | 866 | ```js | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1627,6 +1627,7 @@ E('ERR_UNSUPPORTED_ESM_URL_SCHEME', (url, supported) => { | |||
| 1627 | 1627 | msg += `. Received protocol '${url.protocol}'`; | |
| 1628 | 1628 | return msg; | |
| 1629 | 1629 | }, Error); | |
| 1630 | + E('ERR_USE_AFTER_CLOSE', '%s was closed', Error); | ||
| 1630 | 1631 | ||
| 1631 | 1632 | // This should probably be a `TypeError`. | |
| 1632 | 1633 | E('ERR_VALID_PERFORMANCE_ENTRY_TYPE', | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -38,7 +38,10 @@ const { | |||
| 38 | 38 | ||
| 39 | 39 | const { codes } = require('internal/errors'); | |
| 40 | 40 | ||
| 41 | - const { ERR_INVALID_ARG_VALUE } = codes; | ||
| 41 | + const { | ||
| 42 | + ERR_INVALID_ARG_VALUE, | ||
| 43 | + ERR_USE_AFTER_CLOSE, | ||
| 44 | + } = codes; | ||
| 42 | 45 | const { | |
| 43 | 46 | validateAbortSignal, | |
| 44 | 47 | validateArray, | |
@@ -398,6 +401,9 @@ class Interface extends InterfaceConstructor { | |||
| 398 | 401 | } | |
| 399 | 402 | ||
| 400 | 403 | question(query, cb) { | |
| 404 | + if (this.closed) { | ||
| 405 | + throw new ERR_USE_AFTER_CLOSE('readline'); | ||
| 406 | + } | ||
| 401 | 407 | if (this[kQuestionCallback]) { | |
| 402 | 408 | this.prompt(); | |
| 403 | 409 | } else { | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1092,6 +1092,40 @@ for (let i = 0; i < 12; i++) { | |||
| 1092 | 1092 | rli.close(); | |
| 1093 | 1093 | } | |
| 1094 | 1094 | ||
| 1095 | + // Call question after close | ||
| 1096 | + { | ||
| 1097 | + const [rli, fi] = getInterface({ terminal }); | ||
| 1098 | + rli.question('What\'s your name?', common.mustCall((name) => { | ||
| 1099 | + assert.strictEqual(name, 'Node.js'); | ||
| 1100 | + rli.close(); | ||
| 1101 | + assert.throws(() => { | ||
| 1102 | + rli.question('How are you?', common.mustNotCall()); | ||
| 1103 | + }, { | ||
| 1104 | + name: 'Error', | ||
| 1105 | + code: 'ERR_USE_AFTER_CLOSE' | ||
| 1106 | + }); | ||
| 1107 | + assert.notStrictEqual(rli.getPrompt(), 'How are you?'); | ||
| 1108 | + })); | ||
| 1109 | + fi.emit('data', 'Node.js\n'); | ||
| 1110 | + } | ||
| 1111 | + | ||
| 1112 | + // Call promisified question after close | ||
| 1113 | + { | ||
| 1114 | + const [rli, fi] = getInterface({ terminal }); | ||
| 1115 | + const question = util.promisify(rli.question).bind(rli); | ||
| 1116 | + question('What\'s your name?').then(common.mustCall((name) => { | ||
| 1117 | + assert.strictEqual(name, 'Node.js'); | ||
| 1118 | + rli.close(); | ||
| 1119 | + question('How are you?') | ||
| 1120 | + .then(common.mustNotCall(), common.expectsError({ | ||
| 1121 | + code: 'ERR_USE_AFTER_CLOSE', | ||
| 1122 | + name: 'Error' | ||
| 1123 | + })); | ||
| 1124 | + assert.notStrictEqual(rli.getPrompt(), 'How are you?'); | ||
| 1125 | + })); | ||
| 1126 | + fi.emit('data', 'Node.js\n'); | ||
| 1127 | + } | ||
| 1128 | + | ||
| 1095 | 1129 | // Can create a new readline Interface with a null output argument | |
| 1096 | 1130 | { | |
| 1097 | 1131 | const [rli, fi] = getInterface({ output: null, terminal }); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -952,6 +952,23 @@ for (let i = 0; i < 12; i++) { | |||
| 952 | 952 | rli.close(); | |
| 953 | 953 | } | |
| 954 | 954 | ||
| 955 | + // Call question after close | ||
| 956 | + { | ||
| 957 | + const [rli, fi] = getInterface({ terminal }); | ||
| 958 | + rli.question('What\'s your name?').then(common.mustCall((name) => { | ||
| 959 | + assert.strictEqual(name, 'Node.js'); | ||
| 960 | + rli.close(); | ||
| 961 | + rli.question('How are you?') | ||
| 962 | + .then(common.mustNotCall(), common.expectsError({ | ||
| 963 | + code: 'ERR_USE_AFTER_CLOSE', | ||
| 964 | + name: 'Error' | ||
| 965 | + })); | ||
| 966 | + assert.notStrictEqual(rli.getPrompt(), 'How are you?'); | ||
| 967 | + })); | ||
| 968 | + fi.emit('data', 'Node.js\n'); | ||
| 969 | + } | ||
| 970 | + | ||
| 971 | + | ||
| 955 | 972 | // Can create a new readline Interface with a null output argument | |
| 956 | 973 | { | |
| 957 | 974 | const [rli, fi] = getInterface({ output: null, terminal }); | |
| Back | FazBrowse Home | New Git URL |
0 commit comments