|
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 | constfs=require('fs'); |
42 | 40 | constcp=require('child_process'); |
43 | 41 | const{ Buffer }=require('buffer'); |
| 42 | +const{ StringDecoder }=require('string_decoder'); |
| 43 | + |
44 | 44 | constos={ |
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 | constprint=console.log; |
| 71 | + |
71 | 72 | functionread(fileName){ |
72 | 73 | returnfs.readFileSync(fileName,'utf8'); |
73 | 74 | } |
74 | 75 | constquit=process.exit; |
75 | | -// Polyfill "readline()". |
76 | | -constlogFile=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 | +consttickArguments=[]; |
| 78 | +if(process.platform==='darwin'){ |
| 79 | +ArrayPrototypePush(tickArguments,'--mac'); |
| 80 | +}elseif(process.platform==='win32'){ |
| 81 | +ArrayPrototypePush(tickArguments,'--windows'); |
82 | 82 | } |
83 | | -constfd=fs.openSync(logFile,'r'); |
| 83 | +ArrayPrototypePushApply(tickArguments, |
| 84 | +ArrayPrototypeSlice(process.argv,1)); |
| 85 | + |
| 86 | +functionwrite(str){process.stdout.write(str);}; |
| 87 | +functionprintErr(str){process.stderr.write(str);}; |
| 88 | + |
| 89 | +letlogFile; |
| 90 | +letfd; |
84 | 91 | constbuf=Buffer.allocUnsafe(4096); |
85 | | -constdec=new(require('string_decoder').StringDecoder)('utf-8'); |
| 92 | +constdec=newStringDecoder('utf-8'); |
86 | 93 | letline=''; |
87 | 94 |
|
88 | | -{ |
| 95 | +functionopenFile(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 | +throwe; |
| 103 | +} |
| 104 | + |
89 | 105 | constmessage=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