Skip to content

Commit

Permalink
[Fix] if someone throws null/undefined, it shouldn’t crash
Browse files Browse the repository at this point in the history
Fixes #324.
  • Loading branch information
ljharb committed Sep 30, 2016
1 parent 407a0f6 commit ae7fec6
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
2 changes: 1 addition & 1 deletion lib/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -446,7 +446,7 @@ Test.prototype['throws'] = function (fn, expected, msg, extra) {
fn();
} catch (err) {
caught = { error : err };
if (!isEnumerable(err, 'message') || !has(err, 'message')) {
if ((err != null) && (!isEnumerable(err, 'message') || !has(err, 'message'))) {
var message = err.message;
delete err.message;
err.message = message;
Expand Down
14 changes: 11 additions & 3 deletions test/throws.js
Original file line number Diff line number Diff line change
Expand Up @@ -98,9 +98,11 @@ tap.test('failures', function (tt) {
+ 'ok 10 "message" is enumerable\n'
+ "ok 11 { custom: 'error', message: 'message' }\n"
+ 'ok 12 getter is still the same\n'
+ '\n1..12\n'
+ '# tests 12\n'
+ '# pass 3\n'
+ '# throws null\n'
+ 'ok 13 throws null\n'
+ '\n1..13\n'
+ '# tests 13\n'
+ '# pass 4\n'
+ '# fail 9\n'
);
}));
Expand Down Expand Up @@ -134,4 +136,10 @@ tap.test('failures', function (tt) {
t.throws(function () { throw messageGetterError; }, "{ custom: 'error', message: 'message' }");
t.equal(Object.getOwnPropertyDescriptor(messageGetterError, 'message').get, getter, 'getter is still the same');
});

test('throws null', function (t) {
t.plan(1);
t.throws(function () { throw null; }, 'throws null');
t.end();
});
});

0 comments on commit ae7fec6

Please sign in to comment.