lib: copy arguments object instead of leaking it

Instead of leaking the arguments object by passing it as an
argument to a function, copy it's contents to a new array,
then pass the array. This allows V8 to optimize the function
that contains this code, improving performance.

PR-URL: https://github.com/nodejs/node/pull/4361
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Brian White <mscdex@mscdex.net>
This commit is contained in:
Nathan Woltman authored and James M Snell committed 2016-03-10 18:45:08 -08:00
1 parent 0ea3899cab
commit d0582ef9e1
5 files changed
+43 -14

No files matched your search

+4 -1
View File
@@ -85,7 +85,10 @@ Console.prototype.trace = function trace() {
Console.prototype.assert = function(expression) {
if (!expression) {
var arr = Array.prototype.slice.call(arguments, 1);
const argsLen = arguments.length || 1;
const arr = new Array(argsLen - 1);
for (var i = 1; i < argsLen; i++)
arr[i - 1] = arguments[i];
require('assert').ok(false, util.format.apply(null, arr));
}
};