(size, callback)
| 98 | } |
| 99 | |
| 100 | function randomBytes(size, callback) { |
| 101 | size = assertSize(size, 1, 0, Infinity); |
| 102 | if (callback !== undefined) { |
| 103 | validateFunction(callback, 'callback'); |
| 104 | } |
| 105 | |
| 106 | const buf = new FastBuffer(size); |
| 107 | |
| 108 | if (callback === undefined) { |
| 109 | randomFillSync(TypedArrayPrototypeGetBuffer(buf), 0, size); |
| 110 | return buf; |
| 111 | } |
| 112 | |
| 113 | // Keep the callback as a regular function so this is propagated. |
| 114 | randomFill(TypedArrayPrototypeGetBuffer(buf), 0, size, function(error) { |
| 115 | if (error) return FunctionPrototypeCall(callback, this, error); |
| 116 | FunctionPrototypeCall(callback, this, null, buf); |
| 117 | }); |
| 118 | } |
| 119 | |
| 120 | function randomFillSync(buf, offset = 0, size) { |
| 121 | if (!isAnyArrayBuffer(buf) && !isArrayBufferView(buf)) { |
no test coverage detected
searching dependent graphs…