Skip to content

Commit

Permalink
os: make EOL configurable and read only
Browse files Browse the repository at this point in the history
PR-URL: #14622
Fixes: #14619
Reviewed-By: Vse Mozhet Byt <[email protected]>
Reviewed-By: Timothy Gu <[email protected]>
Reviewed-By: Tobias Nießen <[email protected]>
Reviewed-By: Colin Ihrig <[email protected]>
Reviewed-By: Luigi Pinca <[email protected]>
Reviewed-By: Alexey Orlenko <[email protected]>
Reviewed-By: Joyee Cheung <[email protected]>
Reviewed-By: James M Snell <[email protected]>
Reviewed-By: Rod Vagg <[email protected]>
Reviewed-By: Refael Ackermann <[email protected]>
Reviewed-By: Matteo Collina <[email protected]>
  • Loading branch information
XadillaX authored and refack committed Aug 21, 2017
1 parent 3a886ff commit f6caeb9
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 5 deletions.
18 changes: 13 additions & 5 deletions lib/os.js
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,6 @@ function networkInterfaces() {
module.exports = exports = {
arch,
cpus,
EOL: isWindows ? '\r\n' : '\n',
endianness,
freemem: getFreeMem,
homedir: getHomeDirectory,
Expand All @@ -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'
}
});
27 changes: 27 additions & 0 deletions test/parallel/test-os-eol.js
Original file line number Diff line number Diff line change
@@ -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.