11/*1* KEEP THIS CODE AT THE TOP TO AVOID LINE NUMBER CHANGES */
22/*2*/ 'use strict' ;
33/*3*/ function foo ( n ) {
4- /*4*/ return n + 42 ;
4+ /*4*/ var A = new Array ( 3 ) ; return n + 42 + A [ 0 ] ;
55/*5*/ }
66/*6*/ function getterObject ( ) {
77/*7*/ var hasGetter = { _a : 5 , get a ( ) { return this . _a ; } , b : 'hello world' } ;
@@ -28,6 +28,8 @@ var breakpointInFoo = {
2828 location : { path : 'test-v8debugapi.js' , line : 4 }
2929} ;
3030
31+ var MAX_INT = 2147483647 ; // Max signed int32.
32+
3133var assert = require ( 'assert' ) ;
3234var v8debugapi = require ( '../lib/v8debugapi.js' ) ;
3335var logModule = require ( '@google/cloud-diagnostics-common' ) . logger ;
@@ -43,6 +45,67 @@ function stateIsClean(api) {
4345 return true ;
4446}
4547
48+ function validateVariable ( variable ) {
49+ if ( variable . name ) {
50+ assert . equal ( typeof variable . name , 'string' ) ;
51+ }
52+ if ( variable . value ) {
53+ assert . equal ( typeof variable . value , 'string' ) ;
54+ }
55+ if ( variable . type ) {
56+ assert . equal ( typeof variable . type , 'string' ) ;
57+ }
58+ if ( variable . members ) {
59+ variable . members . forEach ( validateVariable ) ;
60+ }
61+ if ( variable . varTableIndex ) {
62+ assert . ok ( Number . isInteger ( variable . varTableIndex ) &&
63+ variable . varTableIndex >= 0 &&
64+ variable . varTableIndex <= MAX_INT ) ;
65+ }
66+ }
67+
68+ function validateSourceLocation ( location ) {
69+ if ( location . path ) {
70+ assert . equal ( typeof location . path , 'string' ) ;
71+ }
72+ if ( location . line ) {
73+ assert . ok ( Number . isInteger ( location . line ) &&
74+ location . line >= 1 &&
75+ location . line <= MAX_INT ) ;
76+ }
77+ }
78+
79+ function validateStackFrame ( frame ) {
80+ if ( frame [ 'function' ] ) {
81+ assert . equal ( typeof frame [ 'function' ] , 'string' ) ;
82+ }
83+ if ( frame . location ) {
84+ validateSourceLocation ( frame . location ) ;
85+ }
86+ if ( frame . arguments ) {
87+ frame . arguments . forEach ( validateVariable ) ;
88+ }
89+ if ( frame . locals ) {
90+ frame . locals . forEach ( validateVariable ) ;
91+ }
92+ }
93+
94+ function validateBreakpoint ( breakpoint ) {
95+ if ( ! breakpoint ) {
96+ return ;
97+ }
98+ if ( breakpoint . variableTable ) {
99+ breakpoint . variableTable . forEach ( validateVariable ) ;
100+ }
101+ if ( breakpoint . evaluatedExpressions ) {
102+ breakpoint . evaluatedExpressions . forEach ( validateVariable ) ;
103+ }
104+ if ( breakpoint . stackFrames ) {
105+ breakpoint . stackFrames . forEach ( validateStackFrame ) ;
106+ }
107+ }
108+
46109describe ( 'v8debugapi' , function ( ) {
47110 config . workingDirectory = process . cwd ( ) + '/test' ;
48111 var logger = logModule . create ( config . logLevel ) ;
@@ -54,6 +117,15 @@ describe('v8debugapi', function() {
54117 assert ( ! err ) ;
55118 api = v8debugapi . create ( logger , config , fileStats ) ;
56119 assert . ok ( api , 'should be able to create the api' ) ;
120+
121+ // monkey-patch wait to add validation of the breakpoints.
122+ var origWait = api . wait ;
123+ api . wait = function ( bp , callback ) {
124+ origWait ( bp , function ( err ) {
125+ validateBreakpoint ( bp ) ;
126+ callback ( err ) ;
127+ } ) ;
128+ } ;
57129 done ( ) ;
58130 } ) ;
59131 } else {
0 commit comments