summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorRuben Bridgewater <ruben@bridgewater.de>2018-12-11 21:28:45 +0100
committerRuben Bridgewater <ruben@bridgewater.de>2019-02-28 17:49:13 +0100
commit7b674697d8005c29391ebaaf562eb4d92ed9b129 (patch)
tree5c222e4335b18e46d9966917135f3fbc2d8b8bd6 /test
parentbe78266fb39214b7ab3f1d2353d358561dd8f1f8 (diff)
downloadandroid-node-v8-7b674697d8005c29391ebaaf562eb4d92ed9b129.tar.gz
android-node-v8-7b674697d8005c29391ebaaf562eb4d92ed9b129.tar.bz2
android-node-v8-7b674697d8005c29391ebaaf562eb4d92ed9b129.zip
util: prevent leaking internal properties
This prevents leaking of the internal `inspect()` properties when using a custom inspect function. It also aligns the indentation to the way it was in v8.0.0 since that changed unintentionally. All strings returned by the custom inspect function will now be indented appropriately to the current depth. PR-URL: https://github.com/nodejs/node/pull/24971 Refs: https://github.com/nodejs/node/issues/24765 Reviewed-By: Gus Caplan <me@gus.host> Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Rich Trott <rtrott@gmail.com>
Diffstat (limited to 'test')
-rw-r--r--test/parallel/test-util-inspect.js20
1 files changed, 16 insertions, 4 deletions
diff --git a/test/parallel/test-util-inspect.js b/test/parallel/test-util-inspect.js
index 21a0634323..4e9f5ac004 100644
--- a/test/parallel/test-util-inspect.js
+++ b/test/parallel/test-util-inspect.js
@@ -775,9 +775,21 @@ util.inspect({ hasOwnProperty: null });
assert.strictEqual(util.inspect(subject), "{ foo: 'bar' }");
- subject[util.inspect.custom] = (depth, opts) => {
- assert.strictEqual(opts.customInspectOptions, true);
- };
+ subject[util.inspect.custom] = common.mustCall((depth, opts) => {
+ const clone = { ...opts };
+ // This might change at some point but for now we keep the stylize function.
+ // The function should either be documented or an alternative should be
+ // implemented.
+ assert.strictEqual(typeof opts.stylize, 'function');
+ assert.strictEqual(opts.seen, undefined);
+ assert.strictEqual(opts.budget, undefined);
+ assert.strictEqual(opts.indentationLvl, undefined);
+ assert.strictEqual(opts.showHidden, false);
+ opts.showHidden = true;
+ return { [util.inspect.custom]: common.mustCall((depth, opts2) => {
+ assert.deepStrictEqual(clone, opts2);
+ }) };
+ });
util.inspect(subject, { customInspectOptions: true });
@@ -1593,7 +1605,7 @@ util.inspect(process);
);
const longList = util.inspect(list, { depth: Infinity });
const match = longList.match(/next/g);
- assert(match.length > 1000 && match.length < 10000);
+ assert(match.length > 500 && match.length < 10000);
assert(longList.includes('[Object: Inspection interrupted ' +
'prematurely. Maximum call stack size exceeded.]'));
}