Skip to content

Commit 2a24096

Browse files
aduh95danielleadams
authored andcommitted
os: refactor to use more primordials
PR-URL: #36284 Reviewed-By: Rich Trott <rtrott@gmail.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
1 parent ea09da4 commit 2a24096

File tree

1 file changed

+12
-7
lines changed

1 file changed

+12
-7
lines changed

lib/os.js

+12-7
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,13 @@
2222
'use strict';
2323

2424
const {
25+
ArrayPrototypePush,
2526
Float64Array,
2627
NumberParseInt,
2728
ObjectDefineProperties,
29+
StringPrototypeEndsWith,
30+
StringPrototypeSlice,
31+
StringPrototypeSplit,
2832
SymbolToPrimitive,
2933
} = primordials;
3034

@@ -104,7 +108,7 @@ function cpus() {
104108
const result = [];
105109
let i = 0;
106110
while (i < data.length) {
107-
result.push({
111+
ArrayPrototypePush(result, {
108112
model: data[i++],
109113
speed: data[i++],
110114
times: {
@@ -135,15 +139,16 @@ function tmpdir() {
135139
path = process.env.TEMP ||
136140
process.env.TMP ||
137141
(process.env.SystemRoot || process.env.windir) + '\\temp';
138-
if (path.length > 1 && path.endsWith('\\') && !path.endsWith(':\\'))
139-
path = path.slice(0, -1);
142+
if (path.length > 1 && StringPrototypeEndsWith(path, '\\') &&
143+
!StringPrototypeEndsWith(path, ':\\'))
144+
path = StringPrototypeSlice(path, 0, -1);
140145
} else {
141146
path = safeGetenv('TMPDIR') ||
142147
safeGetenv('TMP') ||
143148
safeGetenv('TEMP') ||
144149
'/tmp';
145-
if (path.length > 1 && path.endsWith('/'))
146-
path = path.slice(0, -1);
150+
if (path.length > 1 && StringPrototypeEndsWith(path, '/'))
151+
path = StringPrototypeSlice(path, 0, -1);
147152
}
148153

149154
return path;
@@ -177,7 +182,7 @@ function getCIDR(address, netmask, family) {
177182
groupLength = 16;
178183
}
179184

180-
const parts = netmask.split(split);
185+
const parts = StringPrototypeSplit(netmask, split);
181186
for (var i = 0; i < parts.length; i++) {
182187
if (parts[i] !== '') {
183188
const binary = NumberParseInt(parts[i], range);
@@ -221,7 +226,7 @@ function networkInterfaces() {
221226

222227
const existing = result[name];
223228
if (existing !== undefined)
224-
existing.push(entry);
229+
ArrayPrototypePush(existing, entry);
225230
else
226231
result[name] = [entry];
227232
}

0 commit comments

Comments
 (0)