mirror of
https://github.com/nodejs/node.git
synced 2024-12-01 16:10:02 +01:00
ba6196f843
In certain conditions, inspecting a Proxy object can lead to a max call stack error. Avoid that by detecting the Proxy object and outputting information about the Proxy object itself. Fixes: https://github.com/nodejs/node/issues/6464 PR-URL: https://github.com/nodejs/node/pull/6465 Reviewed-By: Myles Borins <myles.borins@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
45 lines
1018 B
JavaScript
45 lines
1018 B
JavaScript
'use strict';
|
|
|
|
const util = require('util');
|
|
const common = require('../common.js');
|
|
|
|
const bench = common.createBenchmark(main, {
|
|
v: [1, 2],
|
|
n: [1e6]
|
|
});
|
|
|
|
function twoDifferentProxies(n) {
|
|
// This one should be slower between we're looking up multiple proxies.
|
|
const proxyA = new Proxy({}, {get: () => {}});
|
|
const proxyB = new Proxy({}, {get: () => {}});
|
|
bench.start();
|
|
for (var i = 0; i < n; i += 1)
|
|
util.inspect({a: proxyA, b: proxyB}, {showProxy: true});
|
|
bench.end(n);
|
|
}
|
|
|
|
function oneProxy(n) {
|
|
// This one should be a bit faster because of the internal caching.
|
|
const proxy = new Proxy({}, {get: () => {}});
|
|
bench.start();
|
|
for (var i = 0; i < n; i += 1)
|
|
util.inspect({a: proxy, b: proxy}, {showProxy: true});
|
|
bench.end(n);
|
|
}
|
|
|
|
function main(conf) {
|
|
const n = conf.n | 0;
|
|
const v = conf.v | 0;
|
|
|
|
switch (v) {
|
|
case 1:
|
|
oneProxy(n);
|
|
break;
|
|
case 2:
|
|
twoDifferentProxies(n);
|
|
break;
|
|
default:
|
|
throw new Error('Should not get to here');
|
|
}
|
|
}
|