Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit d628f3a

Browse filesBrowse files
not-an-aardvarkItalo A. Casas
authored andcommitted
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>
1 parent b2d0c44 commit d628f3a
Copy full SHA for d628f3a

File tree

Expand file treeCollapse file tree

1 file changed

+6
-2
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

1 file changed

+6
-2
lines changed
Open diff view settings
Collapse file

‎lib/util.js‎

Copy file name to clipboardExpand all lines: lib/util.js
+6-2Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -173,8 +173,12 @@ function inspect(obj, opts) {
173173
stylize: stylizeNoColor
174174
};
175175
// legacy...
176-
if (arguments[2] !== undefined) ctx.depth = arguments[2];
177-
if (arguments[3] !== undefined) ctx.colors = arguments[3];
176+
if (arguments.length >= 3 && arguments[2] !== undefined) {
177+
ctx.depth = arguments[2];
178+
}
179+
if (arguments.length >= 4 && arguments[3] !== undefined) {
180+
ctx.colors = arguments[3];
181+
}
178182
if (typeof opts === 'boolean') {
179183
// legacy...
180184
ctx.showHidden = opts;

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.