From c85fe22d1efcd24810901efe3f0d3343353192e3 Mon Sep 17 00:00:00 2001 From: Antoine du Hamel Date: Tue, 15 Dec 2020 22:35:15 +0100 Subject: [PATCH 1/4] lib: remove v8_prof_polyfill from eslint ignore list --- .eslintignore | 1 - lib/internal/v8_prof_polyfill.js | 77 +++++--------------------------- 2 files changed, 12 insertions(+), 66 deletions(-) diff --git a/.eslintignore b/.eslintignore index bdfdfaeab2388d..19e0fcee9e1b5a 100644 --- a/.eslintignore +++ b/.eslintignore @@ -1,5 +1,4 @@ node_modules -lib/internal/v8_prof_polyfill.js lib/punycode.js test/addons/??_* test/fixtures diff --git a/lib/internal/v8_prof_polyfill.js b/lib/internal/v8_prof_polyfill.js index 5f5922c5386543..c286bfb68432f9 100644 --- a/lib/internal/v8_prof_polyfill.js +++ b/lib/internal/v8_prof_polyfill.js @@ -25,7 +25,11 @@ // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -/* eslint-disable no-restricted-globals */ +'use strict'; + +const { + JSONStringify, +} = primordials; module.exports = { versionCheck }; @@ -36,43 +40,14 @@ if (module.id === 'internal/v8_prof_polyfill') return; // Node polyfill const fs = require('fs'); -const cp = require('child_process'); -const os = { - system: function(name, args) { - if (process.platform === 'linux' && name === 'nm') { - // Filter out vdso and vsyscall entries. - const arg = args[args.length - 1]; - if (arg === '[vdso]' || - arg === '[vsyscall]' || - /^[0-9a-f]+-[0-9a-f]+$/.test(arg)) { - return ''; - } - } - let out = cp.spawnSync(name, args).stdout.toString(); - // Auto c++filt names, but not [iItT] - if (process.platform === 'darwin' && name === 'nm') { - // nm prints an error along the lines of "Run xcodebuild -license" and - // exits when Xcode hasn't been properly installed or when its license - // hasn't been accepted yet. Basically any mention of xcodebuild in - // the output means the nm command is non-functional. - const match = out.match(/(?:^|\n)([^\n]*xcodebuild[^\n]*)(?:\n|$)/); - if (match) throw new Error(match[1]); - out = macCppfiltNm(out); - } - return out; - } -}; -const print = console.log; -function read(fileName) { - return fs.readFileSync(fileName, 'utf8'); -} -const quit = process.exit; +const console = require('internal/console/global'); +const { Buffer } = require('buffer'); // Polyfill "readline()". -const logFile = arguments[arguments.length - 1]; +const logFile = arguments[arguments.length - 1]; // eslint-disable-line no-undef try { fs.accessSync(logFile); -} catch(e) { +} catch { console.error('Please provide a valid isolate file as the final argument.'); process.exit(1); } @@ -108,7 +83,7 @@ function readline() { if (bytes === 0) { process.emitWarning(`Profile file ${logFile} is broken`, { code: 'BROKEN_PROFILE_FILE', - detail: `${JSON.stringify(line)} at the file end is broken` + detail: `${JSONStringify(line)} at the file end is broken` }); return ''; } @@ -121,8 +96,8 @@ function versionCheck(firstLine, expected) { // whereas process.versions.v8 is either "$major.$minor.$build-$embedder" or // "$major.$minor.$build.$patch-$embedder". firstLine = firstLine.split(','); - const curVer = expected.split(/[.\-]/); - if (firstLine.length !== 6 && firstLine.length !== 7 || + const curVer = expected.split(/[.-]/); + if ((firstLine.length !== 6 && firstLine.length !== 7) || firstLine[0] !== 'v8-version') { return 'Unable to read v8-version from log file.'; } @@ -131,31 +106,3 @@ function versionCheck(firstLine, expected) { if (curVer[i] !== firstLine[i + 1]) return 'Testing v8 version different from logging version'; } - -function macCppfiltNm(out) { - // Re-grouped copy-paste from `tickprocessor.js` - const FUNC_RE = /^([0-9a-fA-F]{8,16} [iItT] )(.*)$/gm; - const CLEAN_RE = /^[0-9a-fA-F]{8,16} [iItT] /; - let entries = out.match(FUNC_RE); - if (entries === null) - return out; - - entries = entries.map((entry) => { - return entry.replace(CLEAN_RE, '') - }); - - let filtered; - try { - filtered = cp.spawnSync('c++filt', [ '-p' , '-i' ], { - input: entries.join('\n') - }).stdout.toString(); - } catch { - return out; - } - - let i = 0; - filtered = filtered.split('\n'); - return out.replace(FUNC_RE, (all, prefix, postfix) => { - return prefix + (filtered[i++] || postfix); - }); -} From 57843b63fa1d771ca15d22b82f7fe598579a7283 Mon Sep 17 00:00:00 2001 From: Antoine du Hamel Date: Wed, 16 Dec 2020 00:19:44 +0100 Subject: [PATCH 2/4] fixup! lib: remove v8_prof_polyfill from eslint ignore list --- lib/internal/v8_prof_polyfill.js | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/lib/internal/v8_prof_polyfill.js b/lib/internal/v8_prof_polyfill.js index c286bfb68432f9..faf979226e9fb2 100644 --- a/lib/internal/v8_prof_polyfill.js +++ b/lib/internal/v8_prof_polyfill.js @@ -27,9 +27,7 @@ 'use strict'; -const { - JSONStringify, -} = primordials; +/* eslint-disable node-core/prefer-primordials */ module.exports = { versionCheck }; @@ -83,7 +81,7 @@ function readline() { if (bytes === 0) { process.emitWarning(`Profile file ${logFile} is broken`, { code: 'BROKEN_PROFILE_FILE', - detail: `${JSONStringify(line)} at the file end is broken` + detail: `${JSON.stringify(line)} at the file end is broken` }); return ''; } From 62bb36b4deae0e29ed0faab6649c537a9a88dad3 Mon Sep 17 00:00:00 2001 From: Antoine du Hamel Date: Sat, 2 Jan 2021 22:46:36 +0100 Subject: [PATCH 3/4] fixup! lib: remove v8_prof_polyfill from eslint ignore list --- lib/internal/v8_prof_polyfill.js | 63 +++++++++++++++++++++++++++++++- 1 file changed, 61 insertions(+), 2 deletions(-) diff --git a/lib/internal/v8_prof_polyfill.js b/lib/internal/v8_prof_polyfill.js index faf979226e9fb2..6b97deafcb93ff 100644 --- a/lib/internal/v8_prof_polyfill.js +++ b/lib/internal/v8_prof_polyfill.js @@ -28,6 +28,7 @@ 'use strict'; /* eslint-disable node-core/prefer-primordials */ +/* global Buffer, console */ module.exports = { versionCheck }; @@ -38,8 +39,38 @@ if (module.id === 'internal/v8_prof_polyfill') return; // Node polyfill const fs = require('fs'); -const console = require('internal/console/global'); -const { Buffer } = require('buffer'); +const cp = require('child_process'); +const os = { // eslint-disable-line no-unused-vars + system: function(name, args) { + if (process.platform === 'linux' && name === 'nm') { + // Filter out vdso and vsyscall entries. + const arg = args[args.length - 1]; + if (arg === '[vdso]' || + arg === '[vsyscall]' || + /^[0-9a-f]+-[0-9a-f]+$/.test(arg)) { + return ''; + } + } + let out = cp.spawnSync(name, args).stdout.toString(); + // Auto c++filt names, but not [iItT] + if (process.platform === 'darwin' && name === 'nm') { + // Nm prints an error along the lines of "Run xcodebuild -license" and + // exits when Xcode hasn't been properly installed or when its license + // hasn't been accepted yet. Basically any mention of xcodebuild in + // the output means the nm command is non-functional. + const match = out.match(/(?:^|\n)([^\n]*xcodebuild[^\n]*)(?:\n|$)/); + // eslint-disable-next-line no-restricted-syntax + if (match) throw new Error(match[1]); + out = macCppfiltNm(out); + } + return out; + } +}; +const print = console.log; // eslint-disable-line no-unused-vars +function read(fileName) { // eslint-disable-line no-unused-vars + return fs.readFileSync(fileName, 'utf8'); +} +const quit = process.exit; // eslint-disable-line no-unused-vars // Polyfill "readline()". const logFile = arguments[arguments.length - 1]; // eslint-disable-line no-undef @@ -104,3 +135,31 @@ function versionCheck(firstLine, expected) { if (curVer[i] !== firstLine[i + 1]) return 'Testing v8 version different from logging version'; } + +function macCppfiltNm(out) { + // Re-grouped copy-paste from `tickprocessor.js` + const FUNC_RE = /^([0-9a-fA-F]{8,16} [iItT] )(.*)$/gm; + const CLEAN_RE = /^[0-9a-fA-F]{8,16} [iItT] /; + let entries = out.match(FUNC_RE); + if (entries === null) + return out; + + entries = entries.map((entry) => { + return entry.replace(CLEAN_RE, ''); + }); + + let filtered; + try { + filtered = cp.spawnSync('c++filt', [ '-p', '-i' ], { + input: entries.join('\n') + }).stdout.toString(); + } catch { + return out; + } + + let i = 0; + filtered = filtered.split('\n'); + return out.replace(FUNC_RE, (all, prefix, postfix) => { + return prefix + (filtered[i++] || postfix); + }); +} From d5e972a71f77b4dd3d1d80b30eece2cc3643cefa Mon Sep 17 00:00:00 2001 From: Antoine du Hamel Date: Sat, 2 Jan 2021 22:49:29 +0100 Subject: [PATCH 4/4] fixup! lib: remove v8_prof_polyfill from eslint ignore list --- lib/internal/v8_prof_polyfill.js | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/lib/internal/v8_prof_polyfill.js b/lib/internal/v8_prof_polyfill.js index 6b97deafcb93ff..ae98a03ab206d8 100644 --- a/lib/internal/v8_prof_polyfill.js +++ b/lib/internal/v8_prof_polyfill.js @@ -54,7 +54,7 @@ const os = { // eslint-disable-line no-unused-vars let out = cp.spawnSync(name, args).stdout.toString(); // Auto c++filt names, but not [iItT] if (process.platform === 'darwin' && name === 'nm') { - // Nm prints an error along the lines of "Run xcodebuild -license" and + // `nm` prints an error along the lines of "Run xcodebuild -license" and // exits when Xcode hasn't been properly installed or when its license // hasn't been accepted yet. Basically any mention of xcodebuild in // the output means the nm command is non-functional. @@ -144,9 +144,7 @@ function macCppfiltNm(out) { if (entries === null) return out; - entries = entries.map((entry) => { - return entry.replace(CLEAN_RE, ''); - }); + entries = entries.map((entry) => entry.replace(CLEAN_RE, '')); let filtered; try {