@@ -22,6 +22,7 @@ module.exports = {
2222} ;
2323
2424var assert = require ( 'assert' ) ;
25+ var semver = require ( 'semver' ) ;
2526
2627var StatusMessage = require ( './apiclasses.js' ) . StatusMessage ;
2728
@@ -345,10 +346,18 @@ StateResolver.prototype.storeObjectToVariableTable_ = function(obj) {
345346 return idx ;
346347} ;
347348
348-
349349StateResolver . prototype . resolveMirror_ = function ( mirror ) {
350- // See the commented out version of this method below.
351- //
350+ if ( semver . satisfies ( process . version , '<1.6' ) ) {
351+ return this . resolveMirrorSlow_ ( mirror ) ;
352+ } else {
353+ return this . resolveMirrorFast_ ( mirror ) ;
354+ }
355+ } ;
356+
357+ // A slower implementation of resolveMirror_ which is safe for all node versions
358+ //
359+ // See https://github.com/iojs/io.js/issues/1190.
360+ StateResolver . prototype . resolveMirrorSlow_ = function ( mirror ) {
352361 // Instead, let's use Object.keys. This will only get the enumerable
353362 // properties. The other alternative would be Object.getOwnPropertyNames, but
354363 // I'm going with the former as that's what util.inspect does.
@@ -367,24 +376,23 @@ StateResolver.prototype.resolveMirror_ = function(mirror) {
367376 } ;
368377} ;
369378
370- // Ideally we would use Mirror.properties() method to acquire the properties
371- // However, because of a bug that exists in iojs (uptil 1.6.?) and node (still)
372- // we can end up with segfaults on objects with interceptors and accessors.
373- // See https://github.com/iojs/io.js/issues/1190.
379+ // A faster implementation of resolveMirror_ which segfaults in node <1.6
374380//
375- // StateResolver.prototype.resolveMirror_ = function(mirror) {
376- // var members = this.getMirrorProperties_(mirror).map(
377- // this.resolveMirrorProperty_.bind(this));
378- // return {
379- // value: mirror.toText(),
380- // members: members
381- // };
382- // };
383- // StateResolver.prototype.getMirrorProperties_ = function(mirror) {
384- // var namedProperties = mirror.properties(1, 100); // Limited to 100.
385- // var indexedProperties = mirror.properties(2, 100); // Limited to 100.
386- // return namedProperties.concat(indexedProperties);
387- // };
388- // StateResolver.prototype.resolveMirrorProperty_ = function(property) {
389- // return this.resolveVariable_(property.name(), property.value());
390- // };
381+ // See https://github.com/iojs/io.js/issues/1190.
382+ StateResolver . prototype . resolveMirrorFast_ = function ( mirror ) {
383+ var members = this . getMirrorProperties_ ( mirror ) . map (
384+ this . resolveMirrorProperty_ . bind ( this ) ) ;
385+ return {
386+ value : mirror . toText ( ) ,
387+ members : members
388+ } ;
389+ } ;
390+ StateResolver . prototype . getMirrorProperties_ = function ( mirror ) {
391+ var numProperties = this . config_ . capture . maxProperties || 1000 ;
392+ var namedProperties = mirror . properties ( 1 , numProperties ) ;
393+ var indexedProperties = mirror . properties ( 2 , numProperties ) ;
394+ return namedProperties . concat ( indexedProperties ) ;
395+ } ;
396+ StateResolver . prototype . resolveMirrorProperty_ = function ( property ) {
397+ return this . resolveVariable_ ( property . name ( ) , property . value ( ) ) ;
398+ } ;
0 commit comments