summaryrefslogtreecommitdiff
path: root/test/parallel
diff options
context:
space:
mode:
authorRich Trott <rtrott@gmail.com>2017-10-22 14:37:34 -0700
committerRich Trott <rtrott@gmail.com>2017-11-16 22:00:39 -0800
commit617e3e96e671ae3507d233a23d5217bab56256c5 (patch)
tree00cf1af2ac7980d8d3fb36e62cfa62d433741eb2 /test/parallel
parent07d39a2262dac233b5f86b06ecc16484ab0f7858 (diff)
downloadandroid-node-v8-617e3e96e671ae3507d233a23d5217bab56256c5.tar.gz
android-node-v8-617e3e96e671ae3507d233a23d5217bab56256c5.tar.bz2
android-node-v8-617e3e96e671ae3507d233a23d5217bab56256c5.zip
util: runtime deprecation for custom .inspect()
Change documentation-only deprecation for custom inspection using `object.inspect` property to a runtime deprecation. This is a breaking change. Custom inspection via `object.inspect` is deprecated because there is a more robust Symbol-based alternative to `.inspect` and the custom inspection via `object.inspect` feature means that people can accidentally break `console.log()` simply by attaching a `.inspect` property to their objects. Note that since this is a deprecation, the custom inspection will still work. The breaking change is simply the printing of a warning which could alarm users, break tests or other things that might be dependent on specific output, etc. PR-URL: https://github.com/nodejs/node/pull/16393 Ref: https://github.com/nodejs/node/issues/15549 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Diffstat (limited to 'test/parallel')
-rw-r--r--test/parallel/test-util-inspect-deprecated.js18
-rw-r--r--test/parallel/test-util-inspect.js6
2 files changed, 24 insertions, 0 deletions
diff --git a/test/parallel/test-util-inspect-deprecated.js b/test/parallel/test-util-inspect-deprecated.js
new file mode 100644
index 0000000000..adabb06697
--- /dev/null
+++ b/test/parallel/test-util-inspect-deprecated.js
@@ -0,0 +1,18 @@
+'use strict';
+const common = require('../common');
+
+// Test that deprecation warning for custom inspection via the `.inspect()`
+// property (on the target object) is emitted once and only once.
+
+const util = require('util');
+
+{
+ const target = { inspect: () => 'Fhqwhgads' };
+ // `common.expectWarning` will expect the warning exactly one time only
+ common.expectWarning(
+ 'DeprecationWarning',
+ 'Custom inspection function on Objects via .inspect() is deprecated'
+ );
+ util.inspect(target); // should emit deprecation warning
+ util.inspect(target); // should not emit deprecation warning
+}
diff --git a/test/parallel/test-util-inspect.js b/test/parallel/test-util-inspect.js
index 2804ca4fb1..edd097ee7a 100644
--- a/test/parallel/test-util-inspect.js
+++ b/test/parallel/test-util-inspect.js
@@ -1150,3 +1150,9 @@ if (typeof Symbol !== 'undefined') {
}
assert.doesNotThrow(() => util.inspect(process));
+
+// Setting custom inspect property to a non-function should do nothing.
+{
+ const obj = { inspect: 'fhqwhgads' };
+ assert.strictEqual(util.inspect(obj), "{ inspect: 'fhqwhgads' }");
+}