2525// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
2626// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
2727
28+ module . exports = { versionCheck } ;
29+
30+ // Don't execute when required directly instead of being eval'd from
31+ // lib/internal/v8_prof_processor.js. This way we can test functions
32+ // from this file in isolation.
33+ if ( module . id === 'internal/v8_prof_polyfill' ) return ;
34+
2835// Node polyfill
2936const fs = require ( 'fs' ) ;
3037const cp = require ( 'child_process' ) ;
@@ -64,7 +71,18 @@ const fd = fs.openSync(logFile, 'r');
6471const buf = Buffer . allocUnsafe ( 4096 ) ;
6572const dec = new ( require ( 'string_decoder' ) . StringDecoder ) ( 'utf-8' ) ;
6673var line = '' ;
67- versionCheck ( ) ;
74+
75+ {
76+ const message = versionCheck ( peekline ( ) , process . versions . v8 ) ;
77+ if ( message ) console . log ( message ) ;
78+ }
79+
80+ function peekline ( ) {
81+ const s = readline ( ) ;
82+ line = s + '\n' + line ;
83+ return s ;
84+ }
85+
6886function readline ( ) {
6987 while ( true ) {
7088 const lineBreak = line . indexOf ( '\n' ) ;
@@ -81,27 +99,21 @@ function readline() {
8199 }
82100}
83101
84- function versionCheck ( ) {
102+ function versionCheck ( firstLine , expected ) {
85103 // v8-version looks like
86104 // "v8-version,$major,$minor,$build,$patch[,$embedder],$candidate"
87105 // whereas process.versions.v8 is either "$major.$minor.$build-$embedder" or
88106 // "$major.$minor.$build.$patch-$embedder".
89- var firstLine = readline ( ) ;
90- line = firstLine + '\n' + line ;
91107 firstLine = firstLine . split ( ',' ) ;
92- const curVer = process . versions . v8 . split ( / [ . \- ] / ) ;
108+ const curVer = expected . split ( / [ . \- ] / ) ;
93109 if ( firstLine . length !== 6 && firstLine . length !== 7 ||
94110 firstLine [ 0 ] !== 'v8-version' ) {
95- console . log ( 'Unable to read v8-version from log file.' ) ;
96- return ;
111+ return 'Unable to read v8-version from log file.' ;
97112 }
98113 // Compare major, minor and build; ignore the patch and candidate fields.
99- for ( var i = 0 ; i < 3 ; i ++ ) {
100- if ( curVer [ i ] !== firstLine [ i + 1 ] ) {
101- console . log ( 'Testing v8 version different from logging version' ) ;
102- return ;
103- }
104- }
114+ for ( var i = 0 ; i < 3 ; i ++ )
115+ if ( curVer [ i ] !== firstLine [ i + 1 ] )
116+ return 'Testing v8 version different from logging version' ;
105117}
106118
107119function macCppfiltNm ( out ) {
0 commit comments