diff options
author | cjihrig <cjihrig@gmail.com> | 2015-01-12 11:13:18 -0500 |
---|---|---|
committer | cjihrig <cjihrig@gmail.com> | 2015-01-12 14:10:33 -0500 |
commit | 14dc9175eb48789043d87bbd8e40d26727209bd0 (patch) | |
tree | 0f6a48c424f1cc890810f2ceafa3fe5cf0aa012e /lib/assert.js | |
parent | 7c4a50dd2fc8ca7325292ef0cca99295a39cc6da (diff) | |
download | nodejs-14dc9175eb48789043d87bbd8e40d26727209bd0.tar.gz nodejs-14dc9175eb48789043d87bbd8e40d26727209bd0.tar.bz2 nodejs-14dc9175eb48789043d87bbd8e40d26727209bd0.zip |
assert: throw when block is not a function
Currently, anything passed as the block argument to throws()
and doesNotThrow() is interpreted as a function, which can
lead to unexpected results. This commit checks the type of
block, and throws a TypeError if it is not a function.
Fixes: https://github.com/iojs/io.js/issues/275
PR-URL: https://github.com/iojs/io.js/pull/308
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Diffstat (limited to 'lib/assert.js')
-rw-r--r-- | lib/assert.js | 4 |
1 files changed, 4 insertions, 0 deletions
diff --git a/lib/assert.js b/lib/assert.js index 7e18a071e..863651d2d 100644 --- a/lib/assert.js +++ b/lib/assert.js @@ -283,6 +283,10 @@ function expectedException(actual, expected) { function _throws(shouldThrow, block, expected, message) { var actual; + if (!util.isFunction(block)) { + throw new TypeError('block must be a function'); + } + if (util.isString(expected)) { message = expected; expected = null; |