@@ -389,10 +389,15 @@ std::string JSFunction::Inspect(InspectOptions* options, Error& err) {
389
389
snprintf (tmp, sizeof (tmp), " \n context=0x%016" PRIx64, context.raw ());
390
390
res += tmp;
391
391
392
- std::string context_str = context.Inspect (err);
393
- if (err.Fail ()) return std::string ();
392
+ {
393
+ InspectOptions ctx_options;
394
+ ctx_options.detailed = true ;
395
+ ctx_options.indent_depth = options->indent_depth + 1 ;
396
+ std::string context_str = context.Inspect (&ctx_options, err);
397
+ if (err.Fail ()) return std::string ();
394
398
395
- if (!context_str.empty ()) res += " :" + context_str;
399
+ if (!context_str.empty ()) res += " :" + context_str;
400
+ }
396
401
397
402
if (options->print_source ) {
398
403
SharedFunctionInfo info = Info (err);
@@ -821,6 +826,12 @@ std::string HeapObject::Inspect(InspectOptions* options, Error& err) {
821
826
return pre + str.Inspect (options, err);
822
827
}
823
828
829
+ if (type >= v8 ()->types ()->kFirstContextType &&
830
+ type <= v8 ()->types ()->kLastContextType ) {
831
+ Context ctx (this );
832
+ return pre + ctx.Inspect (options, err);
833
+ }
834
+
824
835
if (type == v8 ()->types ()->kFixedArrayType ) {
825
836
FixedArray arr (this );
826
837
return pre + arr.Inspect (options, err);
@@ -1060,13 +1071,19 @@ HeapObject Context::GetScopeInfo(Error& err) {
1060
1071
return info.GetScopeInfo (err);
1061
1072
}
1062
1073
1063
- std::string Context::Inspect (Error& err) {
1074
+ std::string Context::Inspect (InspectOptions* options, Error& err) {
1064
1075
// Not enough postmortem information, return bare minimum
1065
1076
if (v8 ()->shared_info ()->kScopeInfoOffset == -1 &&
1066
1077
v8 ()->shared_info ()->kNameOrScopeInfoOffset == -1 )
1067
1078
return std::string ();
1068
1079
1069
- std::string res = " <Context: {\n " ;
1080
+ std::string res = " <Context" ;
1081
+
1082
+ if (!options->detailed ) {
1083
+ return res + " >" ;
1084
+ }
1085
+
1086
+ res += " : {\n " ;
1070
1087
1071
1088
Value previous = Previous (err);
1072
1089
if (err.Fail ()) return std::string ();
@@ -1083,12 +1100,10 @@ std::string Context::Inspect(Error& err) {
1083
1100
Smi local_count_smi = scope.ContextLocalCount (err);
1084
1101
if (err.Fail ()) return std::string ();
1085
1102
1086
- InspectOptions options;
1087
-
1088
1103
HeapObject heap_previous = HeapObject (previous);
1089
1104
if (heap_previous.Check ()) {
1090
1105
char tmp[128 ];
1091
- snprintf (tmp, sizeof (tmp), " (previous)=0x%016" PRIx64, previous.raw ());
1106
+ snprintf (tmp, sizeof (tmp), (options-> get_indent_spaces () + " (previous)=0x%016" PRIx64). c_str () , previous.raw ());
1092
1107
res += std::string (tmp) + " :<Context>," ;
1093
1108
}
1094
1109
@@ -1098,16 +1113,16 @@ std::string Context::Inspect(Error& err) {
1098
1113
JSFunction closure = Closure (err);
1099
1114
if (err.Fail ()) return std::string ();
1100
1115
char tmp[128 ];
1101
- snprintf (tmp, sizeof (tmp), " (closure)=0x%016" PRIx64 " {" ,
1116
+ snprintf (tmp, sizeof (tmp), (options-> get_indent_spaces () + " (closure)=0x%016" PRIx64 " {" ). c_str () ,
1102
1117
closure.raw ());
1103
1118
res += tmp;
1104
1119
1105
- InspectOptions options ;
1106
- res += closure.Inspect (&options , err) + " }" ;
1120
+ InspectOptions closure_options ;
1121
+ res += closure.Inspect (&closure_options , err) + " }" ;
1107
1122
if (err.Fail ()) return std::string ();
1108
1123
} else {
1109
1124
char tmp[128 ];
1110
- snprintf (tmp, sizeof (tmp), " (scope_info)=0x%016" PRIx64,
1125
+ snprintf (tmp, sizeof (tmp), (options-> get_indent_spaces () + " (scope_info)=0x%016" PRIx64). c_str () ,
1111
1126
scope.raw ());
1112
1127
1113
1128
res += std::string (tmp) + " :<ScopeInfo" ;
@@ -1131,17 +1146,18 @@ std::string Context::Inspect(Error& err) {
1131
1146
1132
1147
if (!res.empty ()) res += " ,\n " ;
1133
1148
1134
- res += " " + name.ToString (err) + " =" ;
1149
+ res += options-> get_indent_spaces () + name.ToString (err) + " =" ;
1135
1150
if (err.Fail ()) return std::string ();
1136
1151
1137
1152
Value value = ContextSlot (i, err);
1138
1153
if (err.Fail ()) return std::string ();
1139
1154
1140
- res += value.Inspect (&options, err);
1155
+ InspectOptions val_options;
1156
+ res += value.Inspect (&val_options, err);
1141
1157
if (err.Fail ()) return std::string ();
1142
1158
}
1143
1159
1144
- return res + " }>" ;
1160
+ return res + " }>" ;
1145
1161
}
1146
1162
1147
1163
0 commit comments