|
1 | 1 | 'use strict'; |
2 | | -var common = require('../common'); |
3 | | -var assert = require('assert'); |
| 2 | +const common = require('../common'); |
4 | 3 |
|
5 | 4 | if (!common.hasCrypto) { |
6 | 5 | common.skip('missing crypto'); |
7 | 6 | return; |
8 | 7 | } |
9 | | -var crypto = require('crypto'); |
| 8 | + |
| 9 | +const assert = require('assert'); |
| 10 | +const crypto = require('crypto'); |
10 | 11 |
|
11 | 12 | crypto.DEFAULT_ENCODING = 'buffer'; |
12 | 13 |
|
13 | 14 | // bump, we register a lot of exit listeners |
14 | 15 | process.setMaxListeners(256); |
15 | 16 |
|
16 | | -[crypto.randomBytes, |
17 | | - crypto.pseudoRandomBytes |
18 | | -].forEach(function(f) { |
19 | | - [-1, |
20 | | - undefined, |
21 | | - null, |
22 | | - false, |
23 | | - true, |
24 | | - {}, |
25 | | - [] |
26 | | - ].forEach(function(value) { |
27 | | - assert.throws(function() { f(value); }); |
28 | | - assert.throws(function() { f(value, function() {}); }); |
| 17 | +[crypto.randomBytes, crypto.pseudoRandomBytes].forEach(function(f) { |
| 18 | + [-1, undefined, null, false, true, {}, []].forEach(function(value) { |
| 19 | + assert.throws(function() { f(value); }, TypeError); |
| 20 | + assert.throws(function() { f(value, function() {}); }, TypeError); |
29 | 21 | }); |
30 | 22 |
|
31 | 23 | [0, 1, 2, 4, 16, 256, 1024].forEach(function(len) { |
32 | | - f(len, checkCall(function(ex, buf) { |
33 | | - assert.equal(null, ex); |
34 | | - assert.equal(len, buf.length); |
| 24 | + f(len, common.mustCall(function(ex, buf) { |
| 25 | + assert.strictEqual(ex, null); |
| 26 | + assert.strictEqual(buf.length, len); |
35 | 27 | assert.ok(Buffer.isBuffer(buf)); |
36 | 28 | })); |
37 | 29 | }); |
38 | 30 | }); |
39 | 31 |
|
40 | | -// assert that the callback is indeed called |
41 | | -function checkCall(cb, desc) { |
42 | | - var called_ = false; |
43 | | - |
44 | | - process.on('exit', function() { |
45 | | - assert.equal(true, called_, desc || ('callback not called: ' + cb)); |
46 | | - }); |
47 | | - |
48 | | - return function() { |
49 | | - return called_ = true, cb.apply(cb, Array.prototype.slice.call(arguments)); |
50 | | - }; |
51 | | -} |
52 | | - |
53 | 32 | // #5126, "FATAL ERROR: v8::Object::SetIndexedPropertiesToExternalArrayData() |
54 | 33 | // length exceeds max acceptable value" |
55 | 34 | assert.throws(function() { |
|
0 commit comments