|
30 | 30 | /* eslint-disable node-core/prefer-primordials, no-restricted-globals */ |
31 | 31 | /* global console */ |
32 | 32 |
|
33 | | -module.exports = { versionCheck }; |
| 33 | +const { |
| 34 | + ArrayPrototypePush, |
| 35 | + ArrayPrototypePushApply, |
| 36 | + ArrayPrototypeSlice, |
| 37 | +} = primordials; |
34 | 38 |
|
35 | | -// Don't execute when required directly instead of being eval'd from |
36 | | -// lib/internal/v8_prof_processor.js. This way we can test functions |
37 | | -// from this file in isolation. |
38 | | -if (module.id === 'internal/v8_prof_polyfill') return; |
39 | | - |
40 | | -// Node polyfill |
41 | 39 | const fs = require('fs'); |
42 | 40 | const cp = require('child_process'); |
43 | 41 | const { Buffer } = require('buffer'); |
| 42 | +const { StringDecoder } = require('string_decoder'); |
| 43 | + |
44 | 44 | const os = { |
45 | 45 | system: function(name, args) { |
46 | 46 | if (process.platform === 'linux' && name === 'nm') { |
@@ -68,24 +68,40 @@ const os = { |
68 | 68 | }, |
69 | 69 | }; |
70 | 70 | const print = console.log; |
| 71 | + |
71 | 72 | function read(fileName) { |
72 | 73 | return fs.readFileSync(fileName, 'utf8'); |
73 | 74 | } |
74 | 75 | const quit = process.exit; |
75 | | -// Polyfill "readline()". |
76 | | -const logFile = globalThis.arguments[globalThis.arguments.length - 1]; |
77 | | -try { |
78 | | - fs.accessSync(logFile); |
79 | | -} catch { |
80 | | - console.error('Please provide a valid isolate file as the final argument.'); |
81 | | - process.exit(1); |
| 76 | + |
| 77 | +const tickArguments = []; |
| 78 | +if (process.platform === 'darwin') { |
| 79 | + ArrayPrototypePush(tickArguments, '--mac'); |
| 80 | +} else if (process.platform === 'win32') { |
| 81 | + ArrayPrototypePush(tickArguments, '--windows'); |
82 | 82 | } |
83 | | -const fd = fs.openSync(logFile, 'r'); |
| 83 | +ArrayPrototypePushApply(tickArguments, |
| 84 | + ArrayPrototypeSlice(process.argv, 1)); |
| 85 | + |
| 86 | +function write(str) { process.stdout.write(str); }; |
| 87 | +function printErr(str) { process.stderr.write(str); }; |
| 88 | + |
| 89 | +let logFile; |
| 90 | +let fd; |
84 | 91 | const buf = Buffer.allocUnsafe(4096); |
85 | | -const dec = new (require('string_decoder').StringDecoder)('utf-8'); |
| 92 | +const dec = new StringDecoder('utf-8'); |
86 | 93 | let line = ''; |
87 | 94 |
|
88 | | -{ |
| 95 | +function openFile(filename) { |
| 96 | + logFile = filename; |
| 97 | + try { |
| 98 | + fd = fs.openSync(logFile, 'r'); |
| 99 | + } catch (e) { |
| 100 | + console.error(`Cannot access log file: ${logFile}`); |
| 101 | + console.error('Please provide a valid isolate file as the final argument.'); |
| 102 | + throw e; |
| 103 | + } |
| 104 | + |
89 | 105 | const message = versionCheck(peekline(), process.versions.v8); |
90 | 106 | if (message) console.log(message); |
91 | 107 | } |
@@ -162,10 +178,17 @@ function macCppfiltNm(out) { |
162 | 178 | }); |
163 | 179 | } |
164 | 180 |
|
165 | | -Object.assign(globalThis, { |
166 | | - os, |
167 | | - print, |
168 | | - read, |
169 | | - quit, |
170 | | - readline, |
171 | | -}); |
| 181 | +module.exports = { |
| 182 | + globals: { |
| 183 | + arguments: tickArguments, |
| 184 | + write, |
| 185 | + printErr, |
| 186 | + os, |
| 187 | + print, |
| 188 | + read, |
| 189 | + quit, |
| 190 | + readline, |
| 191 | + }, |
| 192 | + openFile, |
| 193 | + versionCheck, |
| 194 | +}; |
0 commit comments