diff options
author | cjihrig <cjihrig@gmail.com> | 2019-02-22 14:52:42 -0500 |
---|---|---|
committer | cjihrig <cjihrig@gmail.com> | 2019-02-26 17:04:56 -0500 |
commit | d64aea059902efb32f01c46c9ac0467662d93628 (patch) | |
tree | d6354fea1f0d87198182bd7704c168e20447c5d2 /lib/internal/process/report.js | |
parent | e3d4a7d9994ff7d1bd144779f8b91d8302112bc0 (diff) | |
download | android-node-v8-d64aea059902efb32f01c46c9ac0467662d93628.tar.gz android-node-v8-d64aea059902efb32f01c46c9ac0467662d93628.tar.bz2 android-node-v8-d64aea059902efb32f01c46c9ac0467662d93628.zip |
report: refactor triggerReport()
This commit fixes the triggerReport() argument validation. The
existing test is also updated, as it was not passing the Error
object to triggerReport().
PR-URL: https://github.com/nodejs/node/pull/26268
Reviewed-By: Richard Lau <riclau@uk.ibm.com>
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
Reviewed-By: James M Snell <jasnell@gmail.com>
Diffstat (limited to 'lib/internal/process/report.js')
-rw-r--r-- | lib/internal/process/report.js | 24 |
1 files changed, 11 insertions, 13 deletions
diff --git a/lib/internal/process/report.js b/lib/internal/process/report.js index 87fad4c195..50ddc8c4b3 100644 --- a/lib/internal/process/report.js +++ b/lib/internal/process/report.js @@ -75,20 +75,18 @@ const report = { }, triggerReport(file, err) { emitExperimentalWarning('report'); - if (err == null) { - if (file == null) { - return nr.triggerReport(new ERR_SYNTHETIC().stack); - } - if (typeof file !== 'string') - throw new ERR_INVALID_ARG_TYPE('file', 'String', file); - return nr.triggerReport(file, new ERR_SYNTHETIC().stack); - } - if (typeof err !== 'object') - throw new ERR_INVALID_ARG_TYPE('err', 'Object', err); - if (file == null) - return nr.triggerReport(err.stack); - if (typeof file !== 'string') + + if (typeof file === 'object' && file !== null) { + err = file; + file = undefined; + } else if (file !== undefined && typeof file !== 'string') { throw new ERR_INVALID_ARG_TYPE('file', 'String', file); + } else if (err === undefined) { + err = new ERR_SYNTHETIC(); + } else if (err === null || typeof err !== 'object') { + throw new ERR_INVALID_ARG_TYPE('err', 'Object', err); + } + return nr.triggerReport(file, err.stack); }, getReport(err) { |