os: make EOL configurable and read only
PR-URL: https://github.com/nodejs/node/pull/14622 Fixes: https://github.com/nodejs/node/issues/14619 Reviewed-By: Vse Mozhet Byt <vsemozhetbyt@gmail.com> Reviewed-By: Timothy Gu <timothygu99@gmail.com> Reviewed-By: Tobias Nießen <tniessen@tnie.de> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Alexey Orlenko <eaglexrlnk@gmail.com> Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Rod Vagg <rod@vagg.org> Reviewed-By: Refael Ackermann <refack@gmail.com> Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
This commit is contained in:
parent
3a886ffa24
commit
f6caeb9526
12
lib/os.js
12
lib/os.js
@ -140,7 +140,6 @@ function networkInterfaces() {
|
|||||||
module.exports = exports = {
|
module.exports = exports = {
|
||||||
arch,
|
arch,
|
||||||
cpus,
|
cpus,
|
||||||
EOL: isWindows ? '\r\n' : '\n',
|
|
||||||
endianness,
|
endianness,
|
||||||
freemem: getFreeMem,
|
freemem: getFreeMem,
|
||||||
homedir: getHomeDirectory,
|
homedir: getHomeDirectory,
|
||||||
@ -162,8 +161,17 @@ module.exports = exports = {
|
|||||||
tmpDir: deprecate(tmpdir, tmpDirDeprecationMsg, 'DEP0022')
|
tmpDir: deprecate(tmpdir, tmpDirDeprecationMsg, 'DEP0022')
|
||||||
};
|
};
|
||||||
|
|
||||||
Object.defineProperty(module.exports, 'constants', {
|
Object.defineProperties(module.exports, {
|
||||||
|
constants: {
|
||||||
configurable: false,
|
configurable: false,
|
||||||
enumerable: true,
|
enumerable: true,
|
||||||
value: constants
|
value: constants
|
||||||
|
},
|
||||||
|
|
||||||
|
EOL: {
|
||||||
|
configurable: true,
|
||||||
|
enumerable: true,
|
||||||
|
writable: false,
|
||||||
|
value: isWindows ? '\r\n' : '\n'
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
27
test/parallel/test-os-eol.js
Normal file
27
test/parallel/test-os-eol.js
Normal file
@ -0,0 +1,27 @@
|
|||||||
|
'use strict';
|
||||||
|
|
||||||
|
const common = require('../common');
|
||||||
|
const assert = require('assert');
|
||||||
|
const os = require('os');
|
||||||
|
|
||||||
|
const eol = common.isWindows ? '\r\n' : '\n';
|
||||||
|
|
||||||
|
assert.strictEqual(os.EOL, eol);
|
||||||
|
|
||||||
|
common.expectsError(function() {
|
||||||
|
os.EOL = 123;
|
||||||
|
}, {
|
||||||
|
type: TypeError,
|
||||||
|
message: /^Cannot assign to read only property 'EOL' of object '#<Object>'$/
|
||||||
|
});
|
||||||
|
|
||||||
|
const foo = 'foo';
|
||||||
|
Object.defineProperties(os, {
|
||||||
|
EOL: {
|
||||||
|
configurable: true,
|
||||||
|
enumerable: true,
|
||||||
|
writable: false,
|
||||||
|
value: foo
|
||||||
|
}
|
||||||
|
});
|
||||||
|
assert.strictEqual(os.EOL, foo);
|
Loading…
x
Reference in New Issue
Block a user