Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
lib: remove v8_prof_polyfill from eslint ignore list
  • Loading branch information
aduh95 committed Dec 15, 2020
commit c85fe22d1efcd24810901efe3f0d3343353192e3
1 change: 0 additions & 1 deletion .eslintignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
node_modules
lib/internal/v8_prof_polyfill.js
lib/punycode.js
test/addons/??_*
test/fixtures
Expand Down
77 changes: 12 additions & 65 deletions lib/internal/v8_prof_polyfill.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 };

Expand All @@ -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) {
Comment thread
aduh95 marked this conversation as resolved.
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);
}
Expand Down Expand Up @@ -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 '';
}
Expand All @@ -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.';
}
Expand All @@ -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);
});
}