|
1 | 1 | 'use strict'; |
2 | | -constcommon=require('../common'); |
| 2 | +require('../common'); |
3 | 3 | constassert=require('assert'); |
4 | 4 | constcp=require('child_process'); |
5 | 5 |
|
| 6 | +functiongetPrintedStackTrace(stderr){ |
| 7 | +constlines=stderr.split('\n'); |
| 8 | + |
| 9 | +letstate='initial'; |
| 10 | +constresult={ |
| 11 | +message: [], |
| 12 | +nativeStack: [], |
| 13 | +jsStack: [], |
| 14 | +}; |
| 15 | +for(leti=0;i<lines.length;++i){ |
| 16 | +constline=lines[i].trim(); |
| 17 | +if(line.length===0){ |
| 18 | +continue;// Skip empty lines. |
| 19 | +} |
| 20 | + |
| 21 | +switch(state){ |
| 22 | +case'initial': |
| 23 | +result.message.push(line); |
| 24 | +if(line.includes('Native stack trace')){ |
| 25 | +state='native-stack'; |
| 26 | +}else{ |
| 27 | +result.message.push(line); |
| 28 | +} |
| 29 | +break; |
| 30 | +case'native-stack': |
| 31 | +if(line.includes('JavaScript stack trace')){ |
| 32 | +state='js-stack'; |
| 33 | +}else{ |
| 34 | +result.nativeStack.push(line); |
| 35 | +} |
| 36 | +break; |
| 37 | +case'js-stack': |
| 38 | +result.jsStack.push(line); |
| 39 | +break; |
| 40 | +} |
| 41 | +} |
| 42 | +returnresult; |
| 43 | +} |
| 44 | + |
6 | 45 | if(process.argv[2]==='child'){ |
7 | 46 | process.abort(); |
8 | 47 | }else{ |
9 | 48 | constchild=cp.spawnSync(`${process.execPath}`,[`${__filename}`,'child']); |
10 | 49 | conststderr=child.stderr.toString(); |
11 | 50 |
|
12 | 51 | assert.strictEqual(child.stdout.toString(),''); |
13 | | -const{ nativeStack, jsStack }=common.getPrintedStackTrace(stderr); |
| 52 | +const{ nativeStack, jsStack }=getPrintedStackTrace(stderr); |
14 | 53 |
|
15 | 54 | if(!nativeStack.every((frame,index)=>frame.startsWith(`${index+1}:`))){ |
16 | 55 | assert.fail(`Each frame should start with a frame number:\n${stderr}`); |
17 | 56 | } |
18 | 57 |
|
19 | 58 | // For systems that don't support backtraces, the native stack is |
20 | 59 | // going to be empty. |
21 | | -if(!common.isWindows&&nativeStack.length>0){ |
| 60 | +if(process.platform!=='win32'&&nativeStack.length>0){ |
22 | 61 | const{ getBinaryPath }=require('../common/shared-lib-util'); |
23 | 62 | if(!nativeStack.some((frame)=>frame.includes(`[${getBinaryPath()}]`))){ |
24 | 63 | assert.fail(`Some native stack frame include the binary name:\n${stderr}`); |
|
0 commit comments