From c442d89ad69f2c57219c673734676d113d320dc2 Mon Sep 17 00:00:00 2001 From: Antoine du Hamel Date: Fri, 20 Nov 2020 19:01:12 +0100 Subject: [PATCH] os: refactor to use more primordials PR-URL: https://github.com/nodejs/node/pull/36284 Reviewed-By: Rich Trott Reviewed-By: Luigi Pinca --- lib/os.js | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/lib/os.js b/lib/os.js index d02a4ada5de5d7..a68b77ab64d304 100644 --- a/lib/os.js +++ b/lib/os.js @@ -22,9 +22,13 @@ 'use strict'; const { + ArrayPrototypePush, Float64Array, NumberParseInt, ObjectDefineProperties, + StringPrototypeEndsWith, + StringPrototypeSlice, + StringPrototypeSplit, SymbolToPrimitive, } = primordials; @@ -132,7 +136,7 @@ function cpus() { const result = []; let i = 0; while (i < data.length) { - result.push({ + ArrayPrototypePush(result, { model: data[i++], speed: data[i++], times: { @@ -172,15 +176,16 @@ function tmpdir() { path = process.env.TEMP || process.env.TMP || (process.env.SystemRoot || process.env.windir) + '\\temp'; - if (path.length > 1 && path.endsWith('\\') && !path.endsWith(':\\')) - path = path.slice(0, -1); + if (path.length > 1 && StringPrototypeEndsWith(path, '\\') && + !StringPrototypeEndsWith(path, ':\\')) + path = StringPrototypeSlice(path, 0, -1); } else { path = safeGetenv('TMPDIR') || safeGetenv('TMP') || safeGetenv('TEMP') || '/tmp'; - if (path.length > 1 && path.endsWith('/')) - path = path.slice(0, -1); + if (path.length > 1 && StringPrototypeEndsWith(path, '/')) + path = StringPrototypeSlice(path, 0, -1); } return path; @@ -217,7 +222,7 @@ function getCIDR(address, netmask, family) { groupLength = 16; } - const parts = netmask.split(split); + const parts = StringPrototypeSplit(netmask, split); for (var i = 0; i < parts.length; i++) { if (parts[i] !== '') { const binary = NumberParseInt(parts[i], range); @@ -272,7 +277,7 @@ function networkInterfaces() { const existing = result[name]; if (existing !== undefined) - existing.push(entry); + ArrayPrototypePush(existing, entry); else result[name] = [entry]; }