Skip to content

Commit f6caeb9

Browse files
XadillaXrefack
authored andcommitted
os: make EOL configurable and read only
PR-URL: nodejs#14622 Fixes: nodejs#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>
1 parent 3a886ff commit f6caeb9

File tree

2 files changed

+40
-5
lines changed

2 files changed

+40
-5
lines changed

lib/os.js

+13-5
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,6 @@ function networkInterfaces() {
140140
module.exports = exports = {
141141
arch,
142142
cpus,
143-
EOL: isWindows ? '\r\n' : '\n',
144143
endianness,
145144
freemem: getFreeMem,
146145
homedir: getHomeDirectory,
@@ -162,8 +161,17 @@ module.exports = exports = {
162161
tmpDir: deprecate(tmpdir, tmpDirDeprecationMsg, 'DEP0022')
163162
};
164163

165-
Object.defineProperty(module.exports, 'constants', {
166-
configurable: false,
167-
enumerable: true,
168-
value: constants
164+
Object.defineProperties(module.exports, {
165+
constants: {
166+
configurable: false,
167+
enumerable: true,
168+
value: constants
169+
},
170+
171+
EOL: {
172+
configurable: true,
173+
enumerable: true,
174+
writable: false,
175+
value: isWindows ? '\r\n' : '\n'
176+
}
169177
});

test/parallel/test-os-eol.js

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
'use strict';
2+
3+
const common = require('../common');
4+
const assert = require('assert');
5+
const os = require('os');
6+
7+
const eol = common.isWindows ? '\r\n' : '\n';
8+
9+
assert.strictEqual(os.EOL, eol);
10+
11+
common.expectsError(function() {
12+
os.EOL = 123;
13+
}, {
14+
type: TypeError,
15+
message: /^Cannot assign to read only property 'EOL' of object '#<Object>'$/
16+
});
17+
18+
const foo = 'foo';
19+
Object.defineProperties(os, {
20+
EOL: {
21+
configurable: true,
22+
enumerable: true,
23+
writable: false,
24+
value: foo
25+
}
26+
});
27+
assert.strictEqual(os.EOL, foo);

0 commit comments

Comments
 (0)