| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -11,7 +11,6 @@ const { | |||
| 11 | 11 | FunctionPrototypeBind, | |
| 12 | 12 | Number, | |
| 13 | 13 | Promise, | |
| 14 | - PromisePrototypeCatch, | ||
| 15 | 14 | PromisePrototypeThen, | |
| 16 | 15 | PromiseResolve, | |
| 17 | 16 | Proxy, | |
@@ -169,12 +168,17 @@ class NodeInspector { | |||
| 169 | 168 | process.once('SIGTERM', exitCodeZero); | |
| 170 | 169 | process.once('SIGHUP', exitCodeZero); | |
| 171 | 170 | ||
| 172 | - PromisePrototypeCatch(PromisePrototypeThen(this.run(), async () => { | ||
| 173 | - const repl = await startRepl(); | ||
| 174 | - this.repl = repl; | ||
| 175 | - this.repl.on('exit', exitCodeZero); | ||
| 176 | - this.paused = false; | ||
| 177 | - }), (error) => process.nextTick(() => { throw error; })); | ||
| 171 | + (async () => { | ||
| 172 | + try { | ||
| 173 | + await this.run(); | ||
| 174 | + const repl = await startRepl(); | ||
| 175 | + this.repl = repl; | ||
| 176 | + this.repl.on('exit', exitCodeZero); | ||
| 177 | + this.paused = false; | ||
| 178 | + } catch (error) { | ||
| 179 | + process.nextTick(() => { throw error; }); | ||
| 180 | + } | ||
| 181 | + })(); | ||
| 178 | 182 | } | |
| 179 | 183 | ||
| 180 | 184 | suspendReplWhile(fn) { | |
@@ -183,16 +187,19 @@ class NodeInspector { | |||
| 183 | 187 | } | |
| 184 | 188 | this.stdin.pause(); | |
| 185 | 189 | this.paused = true; | |
| 186 | - return PromisePrototypeCatch(PromisePrototypeThen(new Promise((resolve) => { | ||
| 187 | - resolve(fn()); | ||
| 188 | - }), () => { | ||
| 189 | - this.paused = false; | ||
| 190 | - if (this.repl) { | ||
| 191 | - this.repl.resume(); | ||
| 192 | - this.repl.displayPrompt(); | ||
| 190 | + return (async () => { | ||
| 191 | + try { | ||
| 192 | + await fn(); | ||
| 193 | + this.paused = false; | ||
| 194 | + if (this.repl) { | ||
| 195 | + this.repl.resume(); | ||
| 196 | + this.repl.displayPrompt(); | ||
| 197 | + } | ||
| 198 | + this.stdin.resume(); | ||
| 199 | + } catch (error) { | ||
| 200 | + process.nextTick(() => { throw error; }); | ||
| 193 | 201 | } | |
| 194 | - this.stdin.resume(); | ||
| 195 | - }), (error) => process.nextTick(() => { throw error; })); | ||
| 202 | + })(); | ||
| 196 | 203 | } | |
| 197 | 204 | ||
| 198 | 205 | killChild() { | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -17,7 +17,7 @@ const { | |||
| 17 | 17 | ObjectDefineProperty, | |
| 18 | 18 | ObjectPrototypeHasOwnProperty, | |
| 19 | 19 | Promise, | |
| 20 | - PromisePrototypeCatch, | ||
| 20 | + PromisePrototypeThen, | ||
| 21 | 21 | Proxy, | |
| 22 | 22 | ReflectApply, | |
| 23 | 23 | ReflectGet, | |
@@ -2451,8 +2451,8 @@ function processHeaders(oldHeaders, options) { | |||
| 2451 | 2451 | function onFileUnpipe() { | |
| 2452 | 2452 | const stream = this.sink[kOwner]; | |
| 2453 | 2453 | if (stream.ownsFd) | |
| 2454 | - PromisePrototypeCatch(this.source.close(), | ||
| 2455 | - FunctionPrototypeBind(stream.destroy, stream)); | ||
| 2454 | + PromisePrototypeThen(this.source.close(), undefined, | ||
| 2455 | + FunctionPrototypeBind(stream.destroy, stream)); | ||
| 2456 | 2456 | else | |
| 2457 | 2457 | this.source.releaseFD(); | |
| 2458 | 2458 | } | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -8,7 +8,7 @@ const { | |||
| 8 | 8 | ArrayPrototypePushApply, | |
| 9 | 9 | ArrayPrototypeSplice, | |
| 10 | 10 | ObjectDefineProperty, | |
| 11 | - PromisePrototypeCatch, | ||
| 11 | + PromisePrototypeThen, | ||
| 12 | 12 | globalThis: { Atomics }, | |
| 13 | 13 | } = primordials; | |
| 14 | 14 | ||
@@ -185,7 +185,7 @@ port.on('message', (message) => { | |||
| 185 | 185 | evalScript(name, filename); | |
| 186 | 186 | } else if (doEval === 'module') { | |
| 187 | 187 | const { evalModule } = require('internal/process/execution'); | |
| 188 | - PromisePrototypeCatch(evalModule(filename), (e) => { | ||
| 188 | + PromisePrototypeThen(evalModule(filename), undefined, (e) => { | ||
| 189 | 189 | workerOnGlobalUncaughtException(e, true); | |
| 190 | 190 | }); | |
| 191 | 191 | } else { | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -8,7 +8,7 @@ const { | |||
| 8 | 8 | ObjectCreate, | |
| 9 | 9 | ObjectSetPrototypeOf, | |
| 10 | 10 | PromiseResolve, | |
| 11 | - PromisePrototypeCatch, | ||
| 11 | + PromisePrototypeThen, | ||
| 12 | 12 | ReflectApply, | |
| 13 | 13 | RegExpPrototypeExec, | |
| 14 | 14 | RegExpPrototypeSymbolReplace, | |
@@ -88,7 +88,7 @@ class ModuleJob { | |||
| 88 | 88 | this.linked = link(); | |
| 89 | 89 | // This promise is awaited later anyway, so silence | |
| 90 | 90 | // 'unhandled rejection' warnings. | |
| 91 | - PromisePrototypeCatch(this.linked, noop); | ||
| 91 | + PromisePrototypeThen(this.linked, undefined, noop); | ||
| 92 | 92 | ||
| 93 | 93 | // instantiated == deep dependency jobs wrappers are instantiated, | |
| 94 | 94 | // and module wrapper is instantiated. | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -409,9 +409,6 @@ const SafePromise = makeSafe( | |||
| 409 | 409 | } | |
| 410 | 410 | ); | |
| 411 | 411 | ||
| 412 | - primordials.PromisePrototypeCatch = (thisPromise, onRejected) => | ||
| 413 | - PromisePrototypeThen(thisPromise, undefined, onRejected); | ||
| 414 | - | ||
| 415 | 412 | /** | |
| 416 | 413 | * Attaches a callback that is invoked when the Promise is settled (fulfilled or | |
| 417 | 414 | * rejected). The resolved value cannot be modified from the callback. | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -25,7 +25,7 @@ const { | |||
| 25 | 25 | NumberIsNaN, | |
| 26 | 26 | Promise, | |
| 27 | 27 | PromiseReject, | |
| 28 | - PromisePrototypeCatch, | ||
| 28 | + PromisePrototypeThen, | ||
| 29 | 29 | Symbol, | |
| 30 | 30 | } = primordials; | |
| 31 | 31 | ||
@@ -113,7 +113,7 @@ function map(fn, options) { | |||
| 113 | 113 | queue.push(kEof); | |
| 114 | 114 | } catch (err) { | |
| 115 | 115 | const val = PromiseReject(err); | |
| 116 | - PromisePrototypeCatch(val, onDone); | ||
| 116 | + PromisePrototypeThen(val, undefined, onDone); | ||
| 117 | 117 | queue.push(val); | |
| 118 | 118 | } finally { | |
| 119 | 119 | done = true; | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -16,7 +16,6 @@ const { | |||
| 16 | 16 | ObjectDefineProperties, | |
| 17 | 17 | ObjectSetPrototypeOf, | |
| 18 | 18 | Promise, | |
| 19 | - PromisePrototypeCatch, | ||
| 20 | 19 | PromisePrototypeThen, | |
| 21 | 20 | PromiseResolve, | |
| 22 | 21 | PromiseReject, | |
@@ -1329,7 +1328,7 @@ function readableStreamPipeTo( | |||
| 1329 | 1328 | if (stream[kState].state === 'errored') | |
| 1330 | 1329 | action(stream[kState].storedError); | |
| 1331 | 1330 | else | |
| 1332 | - PromisePrototypeCatch(promise, action); | ||
| 1331 | + PromisePrototypeThen(promise, undefined, action); | ||
| 1333 | 1332 | } | |
| 1334 | 1333 | ||
| 1335 | 1334 | function watchClosed(stream, promise, action) { | |
@@ -1498,8 +1497,9 @@ function readableStreamTee(stream, cloneForBranch2) { | |||
| 1498 | 1497 | branch2 = | |
| 1499 | 1498 | createTeeReadableStream(nonOpStart, pullAlgorithm, cancel2Algorithm); | |
| 1500 | 1499 | ||
| 1501 | - PromisePrototypeCatch( | ||
| 1500 | + PromisePrototypeThen( | ||
| 1502 | 1501 | reader[kState].close.promise, | |
| 1502 | + undefined, | ||
| 1503 | 1503 | (error) => { | |
| 1504 | 1504 | readableStreamDefaultControllerError(branch1[kState].controller, error); | |
| 1505 | 1505 | readableStreamDefaultControllerError(branch2[kState].controller, error); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -203,5 +203,25 @@ new RuleTester({ | |||
| 203 | 203 | code: 'new Proxy({}, { ...{ __proto__: null } })', | |
| 204 | 204 | errors: [{ message: /null-prototype/ }] | |
| 205 | 205 | }, | |
| 206 | + { | ||
| 207 | + code: 'PromisePrototypeCatch(promise, ()=>{})', | ||
| 208 | + errors: [{ message: /\bPromisePrototypeThen\b/ }] | ||
| 209 | + }, | ||
| 210 | + { | ||
| 211 | + code: 'PromiseAll([])', | ||
| 212 | + errors: [{ message: /\bSafePromiseAll\b/ }] | ||
| 213 | + }, | ||
| 214 | + { | ||
| 215 | + code: 'PromiseAllSettled([])', | ||
| 216 | + errors: [{ message: /\bSafePromiseAllSettled\b/ }] | ||
| 217 | + }, | ||
| 218 | + { | ||
| 219 | + code: 'PromiseAny([])', | ||
| 220 | + errors: [{ message: /\bSafePromiseAny\b/ }] | ||
| 221 | + }, | ||
| 222 | + { | ||
| 223 | + code: 'PromiseRace([])', | ||
| 224 | + errors: [{ message: /\bSafePromiseRace\b/ }] | ||
| 225 | + }, | ||
| 206 | 226 | ] | |
| 207 | 227 | }); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -5,7 +5,6 @@ const common = require('../common'); | |||
| 5 | 5 | const assert = require('assert'); | |
| 6 | 6 | ||
| 7 | 7 | const { | |
| 8 | - PromisePrototypeCatch, | ||
| 9 | 8 | PromisePrototypeThen, | |
| 10 | 9 | SafePromiseAll, | |
| 11 | 10 | SafePromiseAllSettled, | |
@@ -14,16 +13,15 @@ const { | |||
| 14 | 13 | SafePromiseRace, | |
| 15 | 14 | } = require('internal/test/binding').primordials; | |
| 16 | 15 | ||
| 17 | - Array.prototype[Symbol.iterator] = common.mustNotCall(); | ||
| 18 | - Promise.all = common.mustNotCall(); | ||
| 19 | - Promise.allSettled = common.mustNotCall(); | ||
| 20 | - Promise.any = common.mustNotCall(); | ||
| 21 | - Promise.race = common.mustNotCall(); | ||
| 22 | - Promise.prototype.catch = common.mustNotCall(); | ||
| 23 | - Promise.prototype.finally = common.mustNotCall(); | ||
| 24 | - Promise.prototype.then = common.mustNotCall(); | ||
| 16 | + Array.prototype[Symbol.iterator] = common.mustNotCall('%Array.prototype%[@@iterator]'); | ||
| 17 | + Promise.all = common.mustNotCall('%Promise%.all'); | ||
| 18 | + Promise.allSettled = common.mustNotCall('%Promise%.allSettled'); | ||
| 19 | + Promise.any = common.mustNotCall('%Promise%.any'); | ||
| 20 | + Promise.race = common.mustNotCall('%Promise%.race'); | ||
| 21 | + Promise.prototype.catch = common.mustNotCall('%Promise.prototype%.catch'); | ||
| 22 | + Promise.prototype.finally = common.mustNotCall('%Promise.prototype%.finally'); | ||
| 23 | + Promise.prototype.then = common.mustNotCall('%Promise.prototype%.then'); | ||
| 25 | 24 | ||
| 26 | - assertIsPromise(PromisePrototypeCatch(Promise.reject(), common.mustCall())); | ||
| 27 | 25 | assertIsPromise(PromisePrototypeThen(test(), common.mustCall())); | |
| 28 | 26 | assertIsPromise(SafePromisePrototypeFinally(test(), common.mustCall())); | |
| 29 | 27 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -109,11 +109,11 @@ module.exports = { | |||
| 109 | 109 | testRange.start = testRange.start + 'RegexpPrototype'.length; | |
| 110 | 110 | testRange.end = testRange.start + 'Test'.length; | |
| 111 | 111 | return [ | |
| 112 | - fixer.replaceTextRange(node.range, 'Exec'), | ||
| 112 | + fixer.replaceTextRange(testRange, 'Exec'), | ||
| 113 | 113 | fixer.insertTextAfter(node, ' !== null'), | |
| 114 | 114 | ]; | |
| 115 | 115 | } | |
| 116 | - }] | ||
| 116 | + }], | ||
| 117 | 117 | }); | |
| 118 | 118 | }, | |
| 119 | 119 | [`${CallExpression}[expression.callee.name=${/^RegExpPrototypeSymbol(Match|MatchAll|Search)$/}]`](node) { | |
@@ -142,9 +142,33 @@ module.exports = { | |||
| 142 | 142 | } | |
| 143 | 143 | context.report({ | |
| 144 | 144 | node, | |
| 145 | - message: 'Proxy handler must be a null-prototype object' | ||
| 145 | + message: 'Proxy handler must be a null-prototype object', | ||
| 146 | 146 | }); | |
| 147 | - } | ||
| 147 | + }, | ||
| 148 | + | ||
| 149 | + [`${CallExpression}[expression.callee.name=PromisePrototypeCatch]`](node) { | ||
| 150 | + context.report({ | ||
| 151 | + node, | ||
| 152 | + message: '%Promise.prototype.catch% look up the `then` property of ' + | ||
| 153 | + 'the `this` argument, use PromisePrototypeThen instead', | ||
| 154 | + }); | ||
| 155 | + }, | ||
| 156 | + | ||
| 157 | + [`${CallExpression}[expression.callee.name=PromisePrototypeFinally]`](node) { | ||
| 158 | + context.report({ | ||
| 159 | + node, | ||
| 160 | + message: '%Promise.prototype.finally% look up the `then` property of ' + | ||
| 161 | + 'the `this` argument, use SafePromisePrototypeFinally or ' + | ||
| 162 | + 'try/finally instead', | ||
| 163 | + }); | ||
| 164 | + }, | ||
| 165 | + | ||
| 166 | + [`${CallExpression}[expression.callee.name=${/^Promise(All(Settled)?|Any|Race)/}]`](node) { | ||
| 167 | + context.report({ | ||
| 168 | + node, | ||
| 169 | + message: `Use Safe${node.expression.callee.name} instead of ${node.expression.callee.name}`, | ||
| 170 | + }); | ||
| 171 | + }, | ||
| 148 | 172 | }; | |
| 149 | 173 | }, | |
| 150 | 174 | }; | |
| Back | FazBrowse Home | New Git URL |
0 commit comments