| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent f38cefa commit 0368f2f
6 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -3748,14 +3748,17 @@ It is recommended to use the `new` qualifier instead. This applies to all Zlib c | |||
| 3748 | 3748 | ||
| 3749 | 3749 | <!-- YAML | |
| 3750 | 3750 | changes: | |
| 3751 | + - version: REPLACEME | ||
| 3752 | + pr-url: https://github.com/nodejs/node/pull/54869 | ||
| 3753 | + description: Runtime deprecation. | ||
| 3751 | 3754 | - version: | |
| 3752 | 3755 | - v22.9.0 | |
| 3753 | 3756 | - v20.18.0 | |
| 3754 | 3757 | pr-url: https://github.com/nodejs/node/pull/54842 | |
| 3755 | 3758 | description: Documentation-only deprecation. | |
| 3756 | 3759 | --> | |
| 3757 | 3760 | ||
| 3758 | - Type: Documentation-only | ||
| 3761 | + Type: Runtime | ||
| 3759 | 3762 | ||
| 3760 | 3763 | Instantiating classes without the `new` qualifier exported by the `node:repl` module is deprecated. | |
| 3761 | 3764 | It is recommended to use the `new` qualifier instead. This applies to all REPL classes, including | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -63,6 +63,7 @@ const { | |||
| 63 | 63 | } = internalBinding('util'); | |
| 64 | 64 | const { isNativeError, isPromise } = internalBinding('types'); | |
| 65 | 65 | const { getOptionValue } = require('internal/options'); | |
| 66 | + const assert = require('internal/assert'); | ||
| 66 | 67 | const { encodings } = internalBinding('string_decoder'); | |
| 67 | 68 | ||
| 68 | 69 | const noCrypto = !process.versions.openssl; | |
@@ -179,6 +180,14 @@ function deprecate(fn, msg, code, useEmitSync) { | |||
| 179 | 180 | return deprecated; | |
| 180 | 181 | } | |
| 181 | 182 | ||
| 183 | + function deprecateInstantiation(target, code, ...args) { | ||
| 184 | + assert(typeof code === 'string'); | ||
| 185 | + | ||
| 186 | + getDeprecationWarningEmitter(code, `Instantiating ${target.name} without the 'new' keyword has been deprecated.`, target)(); | ||
| 187 | + | ||
| 188 | + return ReflectConstruct(target, args); | ||
| 189 | + } | ||
| 190 | + | ||
| 182 | 191 | function decorateErrorStack(err) { | |
| 183 | 192 | if (!(isError(err) && err.stack) || err[decorated_private_symbol]) | |
| 184 | 193 | return; | |
@@ -879,6 +888,7 @@ module.exports = { | |||
| 879 | 888 | defineLazyProperties, | |
| 880 | 889 | defineReplaceableLazyAttribute, | |
| 881 | 890 | deprecate, | |
| 891 | + deprecateInstantiation, | ||
| 882 | 892 | emitExperimentalWarning, | |
| 883 | 893 | encodingsMap, | |
| 884 | 894 | exposeInterface, | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -111,6 +111,7 @@ const { | |||
| 111 | 111 | decorateErrorStack, | |
| 112 | 112 | isError, | |
| 113 | 113 | deprecate, | |
| 114 | + deprecateInstantiation, | ||
| 114 | 115 | SideEffectFreeRegExpPrototypeSymbolReplace, | |
| 115 | 116 | SideEffectFreeRegExpPrototypeSymbolSplit, | |
| 116 | 117 | } = require('internal/util'); | |
@@ -262,12 +263,7 @@ function REPLServer(prompt, | |||
| 262 | 263 | ignoreUndefined, | |
| 263 | 264 | replMode) { | |
| 264 | 265 | if (!(this instanceof REPLServer)) { | |
| 265 | - return new REPLServer(prompt, | ||
| 266 | - stream, | ||
| 267 | - eval_, | ||
| 268 | - useGlobal, | ||
| 269 | - ignoreUndefined, | ||
| 270 | - replMode); | ||
| 266 | + return deprecateInstantiation(REPLServer, 'DEP0185', prompt, stream, eval_, useGlobal, ignoreUndefined, replMode); | ||
| 271 | 267 | } | |
| 272 | 268 | ||
| 273 | 269 | let options; | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -65,7 +65,7 @@ function runAndWait(cmds, repl) { | |||
| 65 | 65 | return promise; | |
| 66 | 66 | } | |
| 67 | 67 | ||
| 68 | - const repl = REPLServer({ | ||
| 68 | + const repl = new REPLServer({ | ||
| 69 | 69 | prompt: PROMPT, | |
| 70 | 70 | stream: new REPLStream(), | |
| 71 | 71 | ignoreUndefined: true, | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -57,7 +57,7 @@ function runAndWait(cmds, repl) { | |||
| 57 | 57 | } | |
| 58 | 58 | ||
| 59 | 59 | async function tests(options) { | |
| 60 | - const repl = REPLServer({ | ||
| 60 | + const repl = new REPLServer({ | ||
| 61 | 61 | prompt: PROMPT, | |
| 62 | 62 | stream: new REPLStream(), | |
| 63 | 63 | ignoreUndefined: true, | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1035,3 +1035,17 @@ function event(ee, expected) { | |||
| 1035 | 1035 | })); | |
| 1036 | 1036 | }); | |
| 1037 | 1037 | } | |
| 1038 | + | ||
| 1039 | + { | ||
| 1040 | + const server = repl.REPLServer(); | ||
| 1041 | + common.expectWarning({ | ||
| 1042 | + DeprecationWarning: { | ||
| 1043 | + DEP0185: 'Instantiating REPLServer without the \'new\' keyword has been deprecated.', | ||
| 1044 | + // For the 'url.format' test-case. | ||
| 1045 | + DEP0169: | ||
| 1046 | + '`url.parse()` behavior is not standardized and prone to errors that have security implications. ' + | ||
| 1047 | + 'Use the WHATWG URL API instead. CVEs are not issued for `url.parse()` vulnerabilities.', | ||
| 1048 | + } | ||
| 1049 | + }); | ||
| 1050 | + server.emit('line', '.exit'); | ||
| 1051 | + } | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments