Permalink
Browse files

os: make EOL configurable and read only

PR-URL: #14622
Fixes: #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>
  • Loading branch information...
XadillaX authored and refack committed Aug 17, 2017
1 parent 3a886ff commit f6caeb952605ffa9968ccd88eb330829f980a536
Showing with 40 additions and 5 deletions.
  1. +13 −5 lib/os.js
  2. +27 −0 test/parallel/test-os-eol.js
View
@@ -140,7 +140,6 @@ function networkInterfaces() {
module.exports = exports = {
arch,
cpus,
EOL: isWindows ? '\r\n' : '\n',
endianness,
freemem: getFreeMem,
homedir: getHomeDirectory,
@@ -162,8 +161,17 @@ module.exports = exports = {
tmpDir: deprecate(tmpdir, tmpDirDeprecationMsg, 'DEP0022')
};
Object.defineProperty(module.exports, 'constants', {
configurable: false,
enumerable: true,
value: constants
Object.defineProperties(module.exports, {
constants: {
configurable: false,
enumerable: true,
value: constants
},
EOL: {
configurable: true,
enumerable: true,
writable: false,
value: isWindows ? '\r\n' : '\n'
}
});
@@ -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);

0 comments on commit f6caeb9

Please sign in to comment.