diff options
author | James M Snell <jasnell@gmail.com> | 2016-04-29 11:06:48 +0300 |
---|---|---|
committer | James M Snell <jasnell@gmail.com> | 2016-05-03 20:08:24 +0300 |
commit | ba6196f84369f1c9c6ab87635de61f6162682cc3 (patch) | |
tree | 16e3370a320ac114e58f445b6adccf3fb0df6dc6 /benchmark | |
parent | eb12f93b79ea76d5d34a635772ec9d2e44703544 (diff) |
util: fix inspecting of proxy objects
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>
Diffstat (limited to 'benchmark')
-rw-r--r-- | benchmark/util/inspect-proxy.js | 44 |
1 files changed, 44 insertions, 0 deletions
diff --git a/benchmark/util/inspect-proxy.js b/benchmark/util/inspect-proxy.js new file mode 100644 index 00000000000..92d5a9a47d6 --- /dev/null +++ b/benchmark/util/inspect-proxy.js @@ -0,0 +1,44 @@ +'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'); + } +} |