-
Notifications
You must be signed in to change notification settings - Fork 29.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
errors: fix stacktrace of SystemError
PR-URL: #49956 Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com> Reviewed-By: Stephen Belanger <admin@stephenbelanger.com> Reviewed-By: James M Snell <jasnell@gmail.com>
- Loading branch information
Showing
2 changed files
with
344 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
'use strict'; | ||
|
||
const common = require('../common'); | ||
const assert = require('assert'); | ||
|
||
const bench = common.createBenchmark(main, { | ||
n: [1e6], | ||
code: [ | ||
'built-in', | ||
'ERR_FS_CP_DIR_TO_NON_DIR', | ||
], | ||
stackTraceLimit: [0, 10], | ||
}, { | ||
flags: ['--expose-internals'], | ||
}); | ||
|
||
function getErrorFactory(code) { | ||
const { | ||
ERR_FS_CP_DIR_TO_NON_DIR, | ||
} = require('internal/errors').codes; | ||
|
||
switch (code) { | ||
case 'built-in': | ||
return (n) => new Error(); | ||
case 'ERR_FS_CP_DIR_TO_NON_DIR': | ||
return (n) => new ERR_FS_CP_DIR_TO_NON_DIR({ | ||
message: 'cannot overwrite directory', | ||
path: 'dest', | ||
syscall: 'cp', | ||
errno: 21, | ||
code: 'EISDIR', | ||
}); | ||
default: | ||
throw new Error(`${code} not supported`); | ||
} | ||
} | ||
|
||
function main({ n, code, stackTraceLimit }) { | ||
const getError = getErrorFactory(code); | ||
|
||
Error.stackTraceLimit = stackTraceLimit; | ||
|
||
// Warm up. | ||
const length = 1024; | ||
const array = []; | ||
for (let i = 0; i < length; ++i) { | ||
array.push(getError(i)); | ||
} | ||
|
||
bench.start(); | ||
|
||
for (let i = 0; i < n; ++i) { | ||
const index = i % length; | ||
array[index] = getError(index); | ||
} | ||
|
||
bench.end(n); | ||
|
||
// Verify the entries to prevent dead code elimination from making | ||
// the benchmark invalid. | ||
for (let i = 0; i < length; ++i) { | ||
assert.strictEqual(typeof array[i], 'object'); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters