@@ -54,17 +54,20 @@ function validateContent(report, fields = []) {
5454
5555function _validateContent ( report , fields = [ ] ) {
5656 const isWindows = process . platform === 'win32' ;
57+ const isJavaScriptThreadReport = report . javascriptStack != null ;
5758
5859 // Verify that all sections are present as own properties of the report.
59- const sections = [ 'header' , 'javascriptStack' , 'nativeStack' ,
60- 'javascriptHeap' , 'libuv' , 'environmentVariables' ,
60+ const sections = [ 'header' , 'nativeStack' , 'libuv' , 'environmentVariables' ,
6161 'sharedObjects' , 'resourceUsage' , 'workers' ] ;
6262 if ( ! isWindows )
6363 sections . push ( 'userLimits' ) ;
6464
6565 if ( report . uvthreadResourceUsage )
6666 sections . push ( 'uvthreadResourceUsage' ) ;
6767
68+ if ( isJavaScriptThreadReport )
69+ sections . push ( 'javascriptStack' , 'javascriptHeap' ) ;
70+
6871 checkForUnknownFields ( report , sections ) ;
6972 sections . forEach ( ( section ) => {
7073 assert ( report . hasOwnProperty ( section ) ) ;
@@ -163,19 +166,6 @@ function _validateContent(report, fields = []) {
163166 } ) ;
164167 assert . strictEqual ( header . host , os . hostname ( ) ) ;
165168
166- // Verify the format of the javascriptStack section.
167- checkForUnknownFields ( report . javascriptStack ,
168- [ 'message' , 'stack' , 'errorProperties' ] ) ;
169- assert . strictEqual ( typeof report . javascriptStack . errorProperties ,
170- 'object' ) ;
171- assert . strictEqual ( typeof report . javascriptStack . message , 'string' ) ;
172- if ( report . javascriptStack . stack !== undefined ) {
173- assert ( Array . isArray ( report . javascriptStack . stack ) ) ;
174- report . javascriptStack . stack . forEach ( ( frame ) => {
175- assert . strictEqual ( typeof frame , 'string' ) ;
176- } ) ;
177- }
178-
179169 // Verify the format of the nativeStack section.
180170 assert ( Array . isArray ( report . nativeStack ) ) ;
181171 report . nativeStack . forEach ( ( frame ) => {
@@ -186,26 +176,41 @@ function _validateContent(report, fields = []) {
186176 assert . strictEqual ( typeof frame . symbol , 'string' ) ;
187177 } ) ;
188178
189- // Verify the format of the javascriptHeap section.
190- const heap = report . javascriptHeap ;
191- const jsHeapFields = [ 'totalMemory' , 'totalCommittedMemory' , 'usedMemory' ,
192- 'availableMemory' , 'memoryLimit' , 'heapSpaces' ] ;
193- checkForUnknownFields ( heap , jsHeapFields ) ;
194- assert ( Number . isSafeInteger ( heap . totalMemory ) ) ;
195- assert ( Number . isSafeInteger ( heap . totalCommittedMemory ) ) ;
196- assert ( Number . isSafeInteger ( heap . usedMemory ) ) ;
197- assert ( Number . isSafeInteger ( heap . availableMemory ) ) ;
198- assert ( Number . isSafeInteger ( heap . memoryLimit ) ) ;
199- assert ( typeof heap . heapSpaces === 'object' && heap . heapSpaces !== null ) ;
200- const heapSpaceFields = [ 'memorySize' , 'committedMemory' , 'capacity' , 'used' ,
201- 'available' ] ;
202- Object . keys ( heap . heapSpaces ) . forEach ( ( spaceName ) => {
203- const space = heap . heapSpaces [ spaceName ] ;
204- checkForUnknownFields ( space , heapSpaceFields ) ;
205- heapSpaceFields . forEach ( ( field ) => {
206- assert ( Number . isSafeInteger ( space [ field ] ) ) ;
179+ if ( isJavaScriptThreadReport ) {
180+ // Verify the format of the javascriptStack section.
181+ checkForUnknownFields ( report . javascriptStack ,
182+ [ 'message' , 'stack' , 'errorProperties' ] ) ;
183+ assert . strictEqual ( typeof report . javascriptStack . errorProperties ,
184+ 'object' ) ;
185+ assert . strictEqual ( typeof report . javascriptStack . message , 'string' ) ;
186+ if ( report . javascriptStack . stack !== undefined ) {
187+ assert ( Array . isArray ( report . javascriptStack . stack ) ) ;
188+ report . javascriptStack . stack . forEach ( ( frame ) => {
189+ assert . strictEqual ( typeof frame , 'string' ) ;
190+ } ) ;
191+ }
192+
193+ // Verify the format of the javascriptHeap section.
194+ const heap = report . javascriptHeap ;
195+ const jsHeapFields = [ 'totalMemory' , 'totalCommittedMemory' , 'usedMemory' ,
196+ 'availableMemory' , 'memoryLimit' , 'heapSpaces' ] ;
197+ checkForUnknownFields ( heap , jsHeapFields ) ;
198+ assert ( Number . isSafeInteger ( heap . totalMemory ) ) ;
199+ assert ( Number . isSafeInteger ( heap . totalCommittedMemory ) ) ;
200+ assert ( Number . isSafeInteger ( heap . usedMemory ) ) ;
201+ assert ( Number . isSafeInteger ( heap . availableMemory ) ) ;
202+ assert ( Number . isSafeInteger ( heap . memoryLimit ) ) ;
203+ assert ( typeof heap . heapSpaces === 'object' && heap . heapSpaces !== null ) ;
204+ const heapSpaceFields = [ 'memorySize' , 'committedMemory' , 'capacity' ,
205+ 'used' , 'available' ] ;
206+ Object . keys ( heap . heapSpaces ) . forEach ( ( spaceName ) => {
207+ const space = heap . heapSpaces [ spaceName ] ;
208+ checkForUnknownFields ( space , heapSpaceFields ) ;
209+ heapSpaceFields . forEach ( ( field ) => {
210+ assert ( Number . isSafeInteger ( space [ field ] ) ) ;
211+ } ) ;
207212 } ) ;
208- } ) ;
213+ }
209214
210215 // Verify the format of the resourceUsage section.
211216 const usage = report . resourceUsage ;
0 commit comments