forked from nodejs/node
-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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. Also adds util.isProxy() Fixes: nodejs#6464
- Loading branch information
Showing
5 changed files
with
76 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
'use strict'; | ||
|
||
require('../common'); | ||
const assert = require('assert'); | ||
const util = require('util'); | ||
const processUtil = process.binding('util'); | ||
|
||
const target = {}; | ||
const handler = { | ||
get: function() { throw new Error('Getter should not be called'); } | ||
}; | ||
const proxyObj = new Proxy(target, handler); | ||
|
||
assert.strictEqual(util.isProxy(proxyObj), true); | ||
|
||
// Inspecting the proxy should not actually walk it's properties | ||
assert.doesNotThrow(() => util.inspect(proxyObj)); | ||
|
||
const details = processUtil.getProxyDetails(proxyObj); | ||
assert.deepStrictEqual(target, details.target); | ||
assert.deepStrictEqual(handler, details.handler); | ||
|
||
assert.strictEqual(util.inspect(proxyObj), | ||
'Proxy { handler: { get: [Function] }, target: {} }'); | ||
|
||
// Using getProxyDetails with non-proxy returns undefined | ||
assert.strictEqual(processUtil.getProxyDetails({}), undefined); | ||
// isProxy with non-Proxy returns false | ||
assert.strictEqual(util.isProxy({}), false); |