GeezerVison is showing github.com — util: improve performance inspecting proxies · nodejs/node@a309ee1
File treeExpand file treeCollapse file tree Open diff view settings Expand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboardExpand all lines: benchmark/util/inspect-proxy.js +1-1Lines changed: 1 addition & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -4,7 +4,7 @@ const util = require('util'); | 4 | 4 | const common = require('../common.js'); | 5 | 5 |
| 6 | 6 | const bench = common.createBenchmark(main, { | 7 | | - n: [2e4], | | 7 | + n: [1e5], | 8 | 8 | showProxy: [0, 1], | 9 | 9 | isProxy: [0, 1] | 10 | 10 | }); | |
Collapse file Copy file name to clipboardExpand all lines: lib/internal/util/inspect.js +2-2Lines changed: 2 additions & 2 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -640,12 +640,12 @@ function formatValue(ctx, value, recurseTimes, typedArray) { | 640 | 640 | const context = value; | 641 | 641 | // Always check for proxies to prevent side effects and to prevent triggering | 642 | 642 | // any proxy handlers. | 643 | | - const proxy = getProxyDetails(value); | | 643 | + const proxy = getProxyDetails(value, !!ctx.showProxy); | 644 | 644 | if (proxy !== undefined) { | 645 | 645 | if (ctx.showProxy) { | 646 | 646 | return formatProxy(ctx, proxy, recurseTimes); | 647 | 647 | } | 648 | | - value = proxy[0]; | | 648 | + value = proxy; | 649 | 649 | } | 650 | 650 |
| 651 | 651 | // Provide a hook for user-specified inspect functions. | |
Collapse file Copy file name to clipboardExpand all lines: src/node_util.cc +14-6Lines changed: 14 additions & 6 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -91,15 +91,23 @@ static void GetProxyDetails(const FunctionCallbackInfo<Value>& args) { | 91 | 91 | if (!args[0]->IsProxy()) | 92 | 92 | return; | 93 | 93 |
| | 94 | + CHECK(args[1]->IsBoolean()); | | 95 | + | 94 | 96 | Local<Proxy> proxy = args[0].As<Proxy>(); | 95 | 97 |
| 96 | | - Local<Value> ret[] = { | 97 | | - proxy->GetTarget(), | 98 | | - proxy->GetHandler() | 99 | | - }; | | 98 | + if (args[1]->IsTrue()) { | | 99 | + Local<Value> ret[] = { | | 100 | + proxy->GetTarget(), | | 101 | + proxy->GetHandler() | | 102 | + }; | 100 | 103 |
| 101 | | - args.GetReturnValue().Set( | 102 | | - Array::New(args.GetIsolate(), ret, arraysize(ret))); | | 104 | + args.GetReturnValue().Set( | | 105 | + Array::New(args.GetIsolate(), ret, arraysize(ret))); | | 106 | + } else { | | 107 | + Local<Value> ret = proxy->GetTarget(); | | 108 | + | | 109 | + args.GetReturnValue().Set(ret); | | 110 | + } | 103 | 111 | } | 104 | 112 |
| 105 | 113 | static void PreviewEntries(const FunctionCallbackInfo<Value>& args) { | |
Collapse file Copy file name to clipboardExpand all lines: test/parallel/test-util-inspect-proxy.js +5-2Lines changed: 5 additions & 2 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -43,10 +43,13 @@ util.inspect(proxyObj, opts); | 43 | 43 |
| 44 | 44 | // getProxyDetails is an internal method, not intended for public use. | 45 | 45 | // This is here to test that the internals are working correctly. | 46 | | -const details = processUtil.getProxyDetails(proxyObj); | | 46 | +let details = processUtil.getProxyDetails(proxyObj, true); | 47 | 47 | assert.strictEqual(target, details[0]); | 48 | 48 | assert.strictEqual(handler, details[1]); | 49 | 49 |
| | 50 | +details = processUtil.getProxyDetails(proxyObj, false); | | 51 | +assert.strictEqual(target, details); | | 52 | + | 50 | 53 | assert.strictEqual( | 51 | 54 | util.inspect(proxyObj, opts), | 52 | 55 | 'Proxy [\n' + | @@ -105,7 +108,7 @@ const expected6 = 'Proxy [\n' + | 105 | 108 | ' ]\n' + | 106 | 109 | ']'; | 107 | 110 | assert.strictEqual( | 108 | | - util.inspect(proxy1, { showProxy: true, depth: null }), | | 111 | + util.inspect(proxy1, { showProxy: 1, depth: null }), | 109 | 112 | expected1); | 110 | 113 | assert.strictEqual(util.inspect(proxy2, opts), expected2); | 111 | 114 | assert.strictEqual(util.inspect(proxy3, opts), expected3); | |
|