@@ -27,6 +27,7 @@ var util = require('util');
2727
2828var StatusMessage = require ( './apiclasses.js' ) . StatusMessage ;
2929
30+ // Error message indices into the resolved variable table.
3031var BUFFER_FULL_MESSAGE_INDEX = 0 ;
3132var NATIVE_PROPERTY_MESSAGE_INDEX = 1 ;
3233var GETTER_MESSAGE_INDEX = 2 ;
@@ -48,15 +49,20 @@ MESSAGE_TABLE[ARG_LOCAL_LIMIT_MESSAGE_INDEX] =
4849 'top `config.capture.maxExpandFrames` stack frames.' ,
4950 true ) } ;
5051
51- // TODO: document this file
52-
53- // returns an object with three fields: stacksframes,
54- // variableTable and evaluated_expressions
52+ /**
53+ * Captures the stack and current execution state.
54+ *
55+ * @return an object with stackFrames, variableTable, and
56+ * evaluatedExpressions fields
57+ */
5558function capture ( execState , expressions , config ) {
56- return ( new StateResolver ( execState , expressions , config ) ) . capture ( ) ;
59+ return ( new StateResolver ( execState , expressions , config ) ) . capture_ ( ) ;
5760}
5861
62+
5963/**
64+ * Checks that the provided expressions will not have side effects and
65+ * then evaluates the expression in the current execution context.
6066 *
6167 * @return an object with error and mirror fields.
6268 */
@@ -87,6 +93,7 @@ function evaluate(expression, frame) {
8793 }
8894}
8995
96+
9097/**
9198 * @param {!Object } execState
9299 * @param {Array<string> } expressions
@@ -106,7 +113,13 @@ function StateResolver(execState, expressions, config) {
106113}
107114
108115
109- StateResolver . prototype . capture = function ( ) {
116+ /**
117+ * Captures the stack and current execution state.
118+ *
119+ * @return an object with stackFrames, variableTable, and
120+ * evaluatedExpressions fields
121+ */
122+ StateResolver . prototype . capture_ = function ( ) {
110123 // Gather the stack frames first
111124 var that = this ;
112125 var frames = that . resolveFrames_ ( ) ;
@@ -140,9 +153,6 @@ StateResolver.prototype.capture = function() {
140153 index ++ ;
141154 }
142155
143- // console.log('totalSize: ' + that.totalSize_ + ' index: ' + index + ' table: '+
144- // that.rawVariableTable_.length);
145-
146156 // If we filled up the buffer already, we need to trim the remainder
147157 if ( index < that . rawVariableTable_ . length ) {
148158 that . trimVariableTable_ ( index , frames ) ;
@@ -155,6 +165,15 @@ StateResolver.prototype.capture = function() {
155165 } ;
156166} ;
157167
168+ /**
169+ * Limits the size of the variable table to `fromIndex` elements. It marks
170+ * all variables with entries beyond `fromIndex` with a message indicating
171+ * that the table filled.
172+ *
173+ * @param {Number } fromIndex The desired size of the variable table.
174+ * @param {Object } frames Frames associated with the current execution
175+ * environment.
176+ */
158177StateResolver . prototype . trimVariableTable_ = function ( fromIndex , frames ) {
159178 this . resolvedVariableTable_ . splice ( fromIndex ) ; // remove the remaining entries
160179
@@ -194,7 +213,6 @@ StateResolver.prototype.resolveFrames_ = function() {
194213 return frames ;
195214} ;
196215
197-
198216StateResolver . prototype . shouldFrameBeResolved_ = function ( frame ) {
199217 // Only capture data from the frames for which we can link the data back
200218 // to the source files.
@@ -214,7 +232,6 @@ StateResolver.prototype.shouldFrameBeResolved_ = function(frame) {
214232 return true ;
215233} ;
216234
217-
218235StateResolver . prototype . resolveFullPath_ = function ( frame ) {
219236 var func = frame . func ( ) ;
220237 if ( ! func . resolved ( ) ) {
@@ -229,30 +246,25 @@ StateResolver.prototype.resolveFullPath_ = function(frame) {
229246 return script . name ( ) ;
230247} ;
231248
232-
233249StateResolver . prototype . resolveRelativePath_ = function ( frame ) {
234250 var fullPath = this . resolveFullPath_ ( frame ) ;
235251 return this . stripCurrentWorkingDirectory_ ( fullPath ) ;
236252} ;
237253
238-
239254StateResolver . prototype . stripCurrentWorkingDirectory_ = function ( path ) {
240255 // Strip 1 extra character to remove the slash.
241256 return path . substr ( this . config_ . workingDirectory . length + 1 ) ;
242257} ;
243258
244-
245259StateResolver . prototype . isPathInCurrentWorkingDirectory_ = function ( path ) {
246260 //return true;
247261 return path . indexOf ( this . config_ . workingDirectory ) === 0 ;
248262} ;
249263
250-
251264StateResolver . prototype . isPathInNodeModulesDirectory_ = function ( path ) {
252265 return path . indexOf ( 'node_modules' ) === 0 ;
253266} ;
254267
255-
256268StateResolver . prototype . resolveFrame_ = function ( frame , resolveVars ) {
257269 var args = resolveVars ? this . resolveArgumentList_ ( frame ) : [ {
258270 name : 'arguments_not_available' ,
@@ -270,15 +282,13 @@ StateResolver.prototype.resolveFrame_ = function(frame, resolveVars) {
270282 } ;
271283} ;
272284
273-
274285StateResolver . prototype . resolveFunctionName_ = function ( func ) {
275286 if ( ! func || ! func . isFunction ( ) ) {
276287 return '' ;
277288 }
278289 return func . name ( ) || func . inferredName ( ) || '(anonymous function)' ;
279290} ;
280291
281-
282292StateResolver . prototype . resolveLocation_ = function ( frame ) {
283293 return {
284294 path : this . resolveRelativePath_ ( frame ) ,
@@ -287,7 +297,6 @@ StateResolver.prototype.resolveLocation_ = function(frame) {
287297 } ;
288298} ;
289299
290-
291300StateResolver . prototype . resolveArgumentList_ = function ( frame ) {
292301 var args = [ ] ;
293302 for ( var i = 0 ; i < frame . argumentCount ( ) ; i ++ ) {
@@ -301,7 +310,6 @@ StateResolver.prototype.resolveArgumentList_ = function(frame) {
301310 return args ;
302311} ;
303312
304-
305313StateResolver . prototype . resolveLocalsList_ = function ( frame ,
306314 resolvedArguments ) {
307315 var locals = [ ] ;
@@ -321,7 +329,14 @@ StateResolver.prototype.resolveLocalsList_ = function(frame,
321329 return locals ;
322330} ;
323331
324-
332+ /**
333+ * Computes a text representation of the provided value based on its type.
334+ * If the value is a recursive data type, it will be represented as an index
335+ * into the variable table.
336+ *
337+ * @param {String } name The name of the variable.
338+ * @param {Object } value A v8 debugger representation of a variable value.
339+ */
325340StateResolver . prototype . resolveVariable_ = function ( name , value ) {
326341 var size = name . length ;
327342
@@ -367,13 +382,20 @@ StateResolver.prototype.getVariableIndex_ = function(value) {
367382 return idx ;
368383} ;
369384
370-
371385StateResolver . prototype . storeObjectToVariableTable_ = function ( obj ) {
372386 var idx = this . rawVariableTable_ . length ;
373387 this . rawVariableTable_ [ idx ] = obj ;
374388 return idx ;
375389} ;
376390
391+ /**
392+ * Responsible for recursively resolving the properties on a
393+ * provided object mirror. Due to a bug in early node versions,
394+ * we maintain two implementations using the fast approach
395+ * for supported node versions.
396+ *
397+ * See https://github.com/iojs/io.js/issues/1190.
398+ */
377399StateResolver . prototype . resolveMirror_ = function ( mirror ) {
378400 if ( semver . satisfies ( process . version , '<1.6' ) ) {
379401 return this . resolveMirrorSlow_ ( mirror ) ;
@@ -383,8 +405,6 @@ StateResolver.prototype.resolveMirror_ = function(mirror) {
383405} ;
384406
385407// A slower implementation of resolveMirror_ which is safe for all node versions
386- //
387- // See https://github.com/iojs/io.js/issues/1190.
388408StateResolver . prototype . resolveMirrorSlow_ = function ( mirror ) {
389409 // Instead, let's use Object.keys. This will only get the enumerable
390410 // properties. The other alternative would be Object.getOwnPropertyNames, but
@@ -415,12 +435,14 @@ StateResolver.prototype.resolveMirrorFast_ = function(mirror) {
415435 members : members
416436 } ;
417437} ;
438+
418439StateResolver . prototype . getMirrorProperties_ = function ( mirror ) {
419440 var numProperties = this . config_ . capture . maxProperties ;
420441 var namedProperties = mirror . properties ( 1 , numProperties ) ;
421442 var indexedProperties = mirror . properties ( 2 , numProperties ) ;
422443 return namedProperties . concat ( indexedProperties ) ;
423444} ;
445+
424446StateResolver . prototype . resolveMirrorProperty_ = function ( property ) {
425447 if ( property . isNative ( ) ) {
426448 return {
0 commit comments