summaryrefslogtreecommitdiff
path: root/lib/assert.js
diff options
context:
space:
mode:
authorBen Noordhuis <info@bnoordhuis.nl>2018-01-07 23:17:29 +0100
committerJames M Snell <jasnell@gmail.com>2018-01-09 16:14:50 -0800
commit71203f5230fbe0f6d0e73793f5b7767378325875 (patch)
tree9273401f03e14d04d4142b76be984d2b04c59d3c /lib/assert.js
parent7a18f093e464ac7b7aad3345963a8f173f3f4cad (diff)
downloadandroid-node-v8-71203f5230fbe0f6d0e73793f5b7767378325875.tar.gz
android-node-v8-71203f5230fbe0f6d0e73793f5b7767378325875.tar.bz2
android-node-v8-71203f5230fbe0f6d0e73793f5b7767378325875.zip
lib: handle `throw undefined` in assert.throws()
And make `assert.doesNotThrow()` handle it as well. PR-URL: https://github.com/nodejs/node/pull/18029 Fixes: https://github.com/nodejs/node/issues/18027 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de> Reviewed-By: Khaidi Chu <i@2333.moe> Reviewed-By: Tiancheng "Timothy" Gu <timothygu99@gmail.com> Reviewed-By: Daniel Bevenius <daniel.bevenius@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
Diffstat (limited to 'lib/assert.js')
-rw-r--r--lib/assert.js9
1 files changed, 6 insertions, 3 deletions
diff --git a/lib/assert.js b/lib/assert.js
index 57d45ed2eb..0762ec7507 100644
--- a/lib/assert.js
+++ b/lib/assert.js
@@ -31,6 +31,8 @@ const { inspect } = require('util');
const assert = module.exports = ok;
+const NO_EXCEPTION_SENTINEL = {};
+
// All of the following functions must throw an AssertionError
// when a corresponding condition is not met, with a message that
// may be undefined if not provided. All assertion methods provide
@@ -253,6 +255,7 @@ function getActual(block) {
} catch (e) {
return e;
}
+ return NO_EXCEPTION_SENTINEL;
}
// Expected to throw an error.
@@ -270,7 +273,7 @@ assert.throws = function throws(block, error, message) {
error = null;
}
- if (actual === undefined) {
+ if (actual === NO_EXCEPTION_SENTINEL) {
let details = '';
if (error && error.name) {
details += ` (${error.name})`;
@@ -291,7 +294,7 @@ assert.throws = function throws(block, error, message) {
assert.doesNotThrow = function doesNotThrow(block, error, message) {
const actual = getActual(block);
- if (actual === undefined)
+ if (actual === NO_EXCEPTION_SENTINEL)
return;
if (typeof error === 'string') {
@@ -305,7 +308,7 @@ assert.doesNotThrow = function doesNotThrow(block, error, message) {
actual,
expected: error,
operator: 'doesNotThrow',
- message: `Got unwanted exception${details}\n${actual.message}`,
+ message: `Got unwanted exception${details}\n${actual && actual.message}`,
stackStartFn: doesNotThrow
});
}