summaryrefslogtreecommitdiff
path: root/benchmark/util/inspect-proxy.js
diff options
context:
space:
mode:
authorJames M Snell <jasnell@gmail.com>2016-04-29 01:06:48 -0700
committerJames M Snell <jasnell@gmail.com>2016-05-03 10:08:24 -0700
commitba6196f84369f1c9c6ab87635de61f6162682cc3 (patch)
tree16e3370a320ac114e58f445b6adccf3fb0df6dc6 /benchmark/util/inspect-proxy.js
parenteb12f93b79ea76d5d34a635772ec9d2e44703544 (diff)
downloadandroid-node-v8-ba6196f84369f1c9c6ab87635de61f6162682cc3.tar.gz
android-node-v8-ba6196f84369f1c9c6ab87635de61f6162682cc3.tar.bz2
android-node-v8-ba6196f84369f1c9c6ab87635de61f6162682cc3.zip
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/util/inspect-proxy.js')
-rw-r--r--benchmark/util/inspect-proxy.js44
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 0000000000..92d5a9a47d
--- /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');
+ }
+}