util: protect against monkeypatched Object prototype for inspect() · nodejs/node@1847696 (original) (raw)
`@@ -63,6 +63,11 @@ const {
`
63
63
` isBigUint64Array
`
64
64
`} = require('internal/util/types');
`
65
65
``
``
66
`+
const assert = require('internal/assert');
`
``
67
+
``
68
`+
// Avoid monkey-patched built-ins.
`
``
69
`+
const { Object } = primordials;
`
``
70
+
66
71
`const ReflectApply = Reflect.apply;
`
67
72
``
68
73
`// This function is borrowed from the function with the same name on V8 Extras'
`
`@@ -383,13 +388,9 @@ function getKeys(value, showHidden) {
`
383
388
`try {
`
384
389
`keys = Object.keys(value);
`
385
390
`} catch (err) {
`
386
``
`-
if (isNativeError(err) &&
`
387
``
`-
err.name === 'ReferenceError' &&
`
388
``
`-
isModuleNamespaceObject(value)) {
`
389
``
`-
keys = Object.getOwnPropertyNames(value);
`
390
``
`-
} else {
`
391
``
`-
throw err;
`
392
``
`-
}
`
``
391
`+
assert(isNativeError(err) && err.name === 'ReferenceError' &&
`
``
392
`+
isModuleNamespaceObject(value));
`
``
393
`+
keys = Object.getOwnPropertyNames(value);
`
393
394
`}
`
394
395
`if (symbols.length !== 0) {
`
395
396
`keys.push(...symbols.filter((key) => propertyIsEnumerable(value, key)));
`