diff options
author | Rich Trott <rtrott@gmail.com> | 2019-02-05 15:41:18 -0800 |
---|---|---|
committer | Rich Trott <rtrott@gmail.com> | 2019-02-10 12:51:38 -0800 |
commit | 1847696f4b6284bad45f452bc8595927074118dc (patch) | |
tree | bc4999e8cf4363569f5182d68354b360a0f3e287 /test | |
parent | ba4df925eb7143606d5a57f49e4ecb179dd7743b (diff) | |
download | android-node-v8-1847696f4b6284bad45f452bc8595927074118dc.tar.gz android-node-v8-1847696f4b6284bad45f452bc8595927074118dc.tar.bz2 android-node-v8-1847696f4b6284bad45f452bc8595927074118dc.zip |
util: protect against monkeypatched Object prototype for inspect()
Prevent affects of monkeypatching (for example) Object.keys() when
calling util.inspect().
PR-URL: https://github.com/nodejs/node/pull/25953
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Diffstat (limited to 'test')
-rw-r--r-- | test/parallel/test-util-primordial-monkeypatching.js | 11 |
1 files changed, 11 insertions, 0 deletions
diff --git a/test/parallel/test-util-primordial-monkeypatching.js b/test/parallel/test-util-primordial-monkeypatching.js new file mode 100644 index 0000000000..bf282a1212 --- /dev/null +++ b/test/parallel/test-util-primordial-monkeypatching.js @@ -0,0 +1,11 @@ +'use strict'; + +// Monkeypatch Object.keys() so that it throws an unexpected error. This tests +// that `util.inspect()` is unaffected by monkey-patching `Object`. + +require('../common'); +const assert = require('assert'); +const util = require('util'); + +Object.keys = () => { throw new Error('fhqwhgads'); }; +assert.strictEqual(util.inspect({}), '{}'); |