-
Notifications
You must be signed in to change notification settings - Fork 30.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
lib,src: make constants not inherit from Object
Make sure `constants` object and all the nested objects don't inherit from `Object.prototype` but from `null`. PR-URL: #10458 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Jeremiah Senkpiel <fishrock123@rocketmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Brian White <mscdex@mscdex.net>
- Loading branch information
1 parent
221b03a
commit caf9ae7
Showing
5 changed files
with
54 additions
and
4 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,30 @@ | ||
'use strict'; | ||
|
||
require('../common'); | ||
const constants = process.binding('constants'); | ||
const assert = require('assert'); | ||
|
||
assert.deepStrictEqual( | ||
Object.keys(constants).sort(), ['crypto', 'fs', 'os', 'zlib'] | ||
); | ||
|
||
assert.deepStrictEqual( | ||
Object.keys(constants.os).sort(), ['UV_UDP_REUSEADDR', 'errno', 'signals'] | ||
); | ||
|
||
// Make sure all the constants objects don't inherit from Object.prototype | ||
const inheritedProperties = Object.getOwnPropertyNames(Object.prototype); | ||
function test(obj) { | ||
assert(obj); | ||
assert.strictEqual(Object.prototype.toString.call(obj), '[object Object]'); | ||
assert.strictEqual(Object.getPrototypeOf(obj), null); | ||
|
||
inheritedProperties.forEach((property) => { | ||
assert.strictEqual(property in obj, false); | ||
}); | ||
} | ||
|
||
[ | ||
constants, constants.crypto, constants.fs, constants.os, constants.zlib, | ||
constants.os.errno, constants.os.signals | ||
].forEach(test); |