Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
util: avoid out-of-bounds arguments index access
This updates util.inspect() to avoid accessing out-of-range indices of
the `arguments` object, which is known to cause optimization bailout.

Based on an average of 10 runs of the benchmark in
`benchmark/util/inspect.js`, this change improves the performance of
`util.inspect` by about 10%.

Relates to #10323

PR-URL: #10569
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Evan Lucas <evanlucas@me.com>
Reviewed-By: Brian White <mscdex@mscdex.net>
Reviewed-By: Jackson Tian <shyvo1987@gmail.com>
Reviewed-By: Jeremiah Senkpiel <fishrock123@rocketmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
  • Loading branch information
not-an-aardvark committed Jan 5, 2017
commit 26f2a6e87ce3911f5546ab24ee6a6d7c36587524
8 changes: 6 additions & 2 deletions lib/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -173,8 +173,12 @@ function inspect(obj, opts) {
stylize: stylizeNoColor
};
// legacy...
if (arguments[2] !== undefined) ctx.depth = arguments[2];
if (arguments[3] !== undefined) ctx.colors = arguments[3];
if (arguments.length >= 3 && arguments[2] !== undefined) {
ctx.depth = arguments[2];
}
if (arguments.length >= 4 && arguments[3] !== undefined) {
ctx.colors = arguments[3];
}
if (typeof opts === 'boolean') {
// legacy...
ctx.showHidden = opts;
Expand Down