mirror of
https://github.com/nodejs/node.git
synced 2025-08-15 13:48:44 +02:00
errors: improve hideStackFrames
PR-URL: https://github.com/nodejs/node/pull/49990 Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com> Reviewed-By: James M Snell <jasnell@gmail.com>
This commit is contained in:
parent
6b27f5b09e
commit
83e6350b82
41 changed files with 984 additions and 572 deletions
|
@ -108,7 +108,6 @@ const {
|
|||
ERR_UNKNOWN_ENCODING,
|
||||
},
|
||||
genericNodeError,
|
||||
hideStackFrames,
|
||||
} = require('internal/errors');
|
||||
const {
|
||||
validateArray,
|
||||
|
@ -386,19 +385,12 @@ Buffer.of = of;
|
|||
|
||||
ObjectSetPrototypeOf(Buffer, Uint8Array);
|
||||
|
||||
// The 'assertSize' method will remove itself from the callstack when an error
|
||||
// occurs. This is done simply to keep the internal details of the
|
||||
// implementation from bleeding out to users.
|
||||
const assertSize = hideStackFrames((size) => {
|
||||
validateNumber(size, 'size', 0, kMaxLength);
|
||||
});
|
||||
|
||||
/**
|
||||
* Creates a new filled Buffer instance.
|
||||
* alloc(size[, fill[, encoding]])
|
||||
*/
|
||||
Buffer.alloc = function alloc(size, fill, encoding) {
|
||||
assertSize(size);
|
||||
validateNumber(size, 'size', 0, kMaxLength);
|
||||
if (fill !== undefined && fill !== 0 && size > 0) {
|
||||
const buf = createUnsafeBuffer(size);
|
||||
return _fill(buf, fill, 0, buf.length, encoding);
|
||||
|
@ -411,7 +403,7 @@ Buffer.alloc = function alloc(size, fill, encoding) {
|
|||
* instance. If `--zero-fill-buffers` is set, will zero-fill the buffer.
|
||||
*/
|
||||
Buffer.allocUnsafe = function allocUnsafe(size) {
|
||||
assertSize(size);
|
||||
validateNumber(size, 'size', 0, kMaxLength);
|
||||
return allocate(size);
|
||||
};
|
||||
|
||||
|
@ -421,15 +413,15 @@ Buffer.allocUnsafe = function allocUnsafe(size) {
|
|||
* If `--zero-fill-buffers` is set, will zero-fill the buffer.
|
||||
*/
|
||||
Buffer.allocUnsafeSlow = function allocUnsafeSlow(size) {
|
||||
assertSize(size);
|
||||
validateNumber(size, 'size', 0, kMaxLength);
|
||||
return createUnsafeBuffer(size);
|
||||
};
|
||||
|
||||
// If --zero-fill-buffers command line argument is set, a zero-filled
|
||||
// buffer is returned.
|
||||
function SlowBuffer(length) {
|
||||
assertSize(length);
|
||||
return createUnsafeBuffer(length);
|
||||
function SlowBuffer(size) {
|
||||
validateNumber(size, 'size', 0, kMaxLength);
|
||||
return createUnsafeBuffer(size);
|
||||
}
|
||||
|
||||
ObjectSetPrototypeOf(SlowBuffer.prototype, Uint8ArrayPrototype);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue