25
25
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26
26
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27
27
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
+
28
35
// Node polyfill
29
36
const fs = require ( 'fs' ) ;
30
37
const cp = require ( 'child_process' ) ;
@@ -64,7 +71,18 @@ const fd = fs.openSync(logFile, 'r');
64
71
const buf = Buffer . allocUnsafe ( 4096 ) ;
65
72
const dec = new ( require ( 'string_decoder' ) . StringDecoder ) ( 'utf-8' ) ;
66
73
var 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
+
68
86
function readline ( ) {
69
87
while ( true ) {
70
88
const lineBreak = line . indexOf ( '\n' ) ;
@@ -81,27 +99,21 @@ function readline() {
81
99
}
82
100
}
83
101
84
- function versionCheck ( ) {
102
+ function versionCheck ( firstLine , expected ) {
85
103
// v8-version looks like
86
104
// "v8-version,$major,$minor,$build,$patch[,$embedder],$candidate"
87
105
// whereas process.versions.v8 is either "$major.$minor.$build-$embedder" or
88
106
// "$major.$minor.$build.$patch-$embedder".
89
- var firstLine = readline ( ) ;
90
- line = firstLine + '\n' + line ;
91
107
firstLine = firstLine . split ( ',' ) ;
92
- const curVer = process . versions . v8 . split ( / [ . \- ] / ) ;
108
+ const curVer = expected . split ( / [ . \- ] / ) ;
93
109
if ( firstLine . length !== 6 && firstLine . length !== 7 ||
94
110
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.' ;
97
112
}
98
113
// 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' ;
105
117
}
106
118
107
119
function macCppfiltNm ( out ) {
0 commit comments